Skip to content

Commit

Permalink
fix: manual lint fixes (#11638)
Browse files Browse the repository at this point in the history
* fix: automatic lint fixes

* fix: coerce type

* fix: jest/no-jasmine-globals, no-inner-declarations, no-restricted-syntax

* fix: api extract

* fix: double not

* fix: api extract

* fix: added prettierrc

* fix: ts-ignore

* fix: adjust prettierrc

* fix: @typescript-eslint/ban-ts-comment

* fix: no-constant-condition

* fix: no-useless-catch

* fix: no-async-promise-executor

* fix: no-empty

* fix: jest/no-standalone-expect

* fix: no-prototype-builtins

* fix: prefer-const, jest/no-conditional-expect

* fix: no-useless-escape

* fix: @typescript-eslint/no-empty-function, no-case-declarations

* fix: consistent-return

* fix: added ignore where fix was overly onerous

* fix: add description to enquirer declaration

* fix: disable rule

* fix: refactor unusual infinite loop syntax

* fix: format

* fix: formatting

* fix: api

* fix: api
  • Loading branch information
sdstolworthy authored Dec 27, 2022
1 parent 7dc9179 commit 2294cf8
Show file tree
Hide file tree
Showing 136 changed files with 1,444 additions and 1,256 deletions.
53 changes: 30 additions & 23 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
env: {
es6: true,
node: true,
jest: true
jest: true,
},
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
Expand All @@ -24,17 +24,17 @@ module.exports = {
jsx: true, // Allows for the parsing of JSX
arrowFunctions: true,
modules: true,
module: true
}
module: true,
},
},
plugins: ['@typescript-eslint', 'spellcheck', 'import', 'jsdoc', 'prefer-arrow'],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx']
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {}
}
typescript: {},
},
},
rules: {
'@typescript-eslint/no-var-requires': 'off',
Expand All @@ -47,16 +47,16 @@ module.exports = {
{
selector: 'ForInStatement',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.'
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'LabeledStatement',
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.'
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.'
}
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],

quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }],
Expand All @@ -67,19 +67,26 @@ module.exports = {
skipWords: dictionary,
skipIfMatch: [
'http://[^s]*',
'^[-\\w]+/[-\\w\\.]+$' //For MIME Types
'^[-\\w]+/[-\\w\\.]+$', //For MIME Types
],
minLength: 4
}
]
minLength: 4,
},
],
},
overrides: [
{
files: ['cypress/*', 'packages/amplify-e2e-tests/src/cypress/uibuilder/uibuilder-spec.js'],
plugins: ['cypress'],
env: {
'cypress/globals': true,
},
},
{
// Add files to this list that shouldn't be spellchecked
files: ['.eslintrc.js'],
rules: {
'spellcheck/spell-checker': 'off'
}
'spellcheck/spell-checker': 'off',
},
},
{
// edit rules here to modify test linting
Expand All @@ -90,18 +97,18 @@ module.exports = {
'@typescript-eslint/unbound-method': 'off',
'jest/unbound-method': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'spellcheck/spell-checker': 'off'
}
'spellcheck/spell-checker': 'off',
},
},
{
// disable spell checker in tests
files: ['**/__tests__/**', '*.test.ts', 'packages/amplify-e2e-*/**', '**/test/**'],
plugins: ['jest'],
extends: ['plugin:jest/recommended'],
rules: {
'spellcheck/spell-checker': 'off'
}
}
'spellcheck/spell-checker': 'off',
},
},
],
// Files / paths / globs that shouldn't be linted at all
// (note that only .js, .jsx, .ts, and .tsx files are linted in the first place)
Expand Down Expand Up @@ -185,6 +192,6 @@ module.exports = {
// Ignore CHANGELOG.md files
'/packages/*/CHANGELOG.md',
// Ignore autogenerated API files
'/packages/*/API.md'
]
'/packages/*/API.md',
],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^26.1.1",
"eslint-plugin-jsdoc": "^37.9.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-app/src/xcodeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ async function addAmplifyFiles() {
}
const rootDir = path.resolve(projectDir, '..', '..');
const project = xcode.project(projectDir);
return new Promise((resolve, reject) => {
await new Promise((resolve, reject) => {
project.parse(error => {
if (error) {
reject(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('WebsocketSubscriptionServer', () => {
});

describe('Connect', () => {
it('should close connection when the protocol is not graphql-ws', done => {
it('should close connection when the protocol is not graphql-ws', (done) => {
const client = new WS(`ws://localhost:${serverPort}${REALTIME_SUBSCRIPTION_PATH}`, 'something');
client.addEventListener('close', event => {
expect(event.code).toEqual(1002);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class AppSyncUnitResolver extends AppSyncBaseResolver {
}
}
if (requestPayload && requestPayload.version !== '2018-05-29' && result === null) {
return;
return undefined;
}

const { result: responseTemplateResult, errors: responseTemplateErrors } = responseMappingTemplate.render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import * as net from 'net';

import { GraphQLDate, GraphQLTime, GraphQLDateTime } from 'graphql-iso-date';

const EMAIL_ADDRESS_REGEX =
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;

// Some of the custom scalars in this file are inspired by the graphql-scalars npm module.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const getSubscriberForMutation = (schema: GraphQLSchema, subscriptions: GraphQLF
return subscriptionName;
}
}
return undefined;
})
.filter(Boolean);
};
1 change: 1 addition & 0 deletions packages/amplify-appsync-simulator/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function generateResolvers(
} catch (e) {
context.appsyncErrors.push(e);
}
return undefined;
},
...(typeName === 'Subscription'
? {
Expand Down
18 changes: 10 additions & 8 deletions packages/amplify-appsync-simulator/src/server/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ const STATIC_ROOT = join(__dirname, '..', '..', 'public');
export class OperationServer {
private _app: express.Application;

constructor(
private config: AppSyncSimulatorServerConfig,
private simulatorContext: AmplifyAppSyncSimulator
) {
constructor(private config: AppSyncSimulatorServerConfig, private simulatorContext: AmplifyAppSyncSimulator) {
this._app = express();
this._app.use(express.json({ limit: MAX_BODY_SIZE }));
this._app.use(cors());
/* eslint-disable @typescript-eslint/no-misused-promises */
this._app.post('/graphql', this.handleRequest);
/* eslint-enable */
this._app.get('/api-config', this.handleAPIInfoRequest);
this._app.use('/', express.static(STATIC_ROOT));
}
Expand Down Expand Up @@ -75,17 +74,20 @@ export class OperationServer {
};
switch (getOperationType(doc, operationName)) {
case 'query':
case 'mutation':
case 'mutation': {
const gqlResult = await runQueryOrMutation(this.simulatorContext.schema, doc, variables, operationName, context);
return response.send(gqlResult);

case 'subscription':
}
case 'subscription': {
const subscriptionResult = await runSubscription(this.simulatorContext.schema, doc, variables, operationName, context);
if ((subscriptionResult as ExecutionResult).errors) {
return response.send(subscriptionResult);
}
throw new Error(`Subscription request is only supported in realtime url. Send requests to ${REALTIME_SUBSCRIPTION_PATH} path instead`);
throw new Error(
`Subscription request is only supported in realtime url. Send requests to ${REALTIME_SUBSCRIPTION_PATH} path instead`,
);
break;
}

default:
throw new Error(`unknown operation`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export type WebsocketSubscriptionServerOptions = {
};

const DEFAULT_OPTIONS: Partial<WebsocketSubscriptionServerOptions> = {
onConnectHandler: async () => {},
onConnectHandler: async () => {
// empty
},
keepAlive: KEEP_ALIVE_TIMEOUT,
connectionTimeoutDuration: CONNECTION_TIMEOUT_DURATION,
};
Expand All @@ -75,11 +77,13 @@ export class WebsocketSubscriptionServer {
if (!this.webSocketServer) {
throw new Error('No server is attached');
}
/* eslint-disable @typescript-eslint/no-misused-promises */
this.webSocketServer.on('connection', this.onSocketConnection);
}

stop() {
this.webSocketServer?.off('connection', this.onSocketConnection);
/* eslint-enable */
this.connections?.forEach(connection => {
this.onClose(connection);
});
Expand Down Expand Up @@ -186,6 +190,7 @@ export class WebsocketSubscriptionServer {
} catch (e) {
this.sendError(connectionContext, '', { errors: [{ message: e.message }] });
}
return undefined;
};

private sendMessage = (connectionContext: ConnectionContext, subscriptionId: string, type: MESSAGE_TYPES, data: any): void => {
Expand Down Expand Up @@ -261,8 +266,10 @@ export class WebsocketSubscriptionServer {

private attachAsyncIterator = async (connectionContext: ConnectionContext, sub: WebsocketSubscription): Promise<void> => {
const { asyncIterator, id } = sub;
while (true) {
const { value, done } = await asyncIterator.next();
let done = false;
while (!done) {
const { value, done: doneResult } = await asyncIterator.next();
done = doneResult;
if (done) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function generateFilterExpression(filter: any, prefix = null, parent = nu

switch (name) {
case 'or':
case 'and':
case 'and': {
const JOINER = name === 'or' ? 'OR' : 'AND';
if (Array.isArray(value)) {
subExpr = scopeExpression(
Expand All @@ -47,11 +47,13 @@ export function generateFilterExpression(filter: any, prefix = null, parent = nu
subExpr = generateFilterExpression(value, [prefix, name].filter(val => val !== null).join('_'));
}
break;
case 'not':
}
case 'not': {
subExpr = scopeExpression(generateFilterExpression(value, [prefix, name].filter(val => val !== null).join('_')));
subExpr.expressions.unshift('NOT');
break;
case 'between':
}
case 'between': {
const expr1 = createExpressionValueName(parent, 'between_1', prefix);
const expr2 = createExpressionValueName(parent, 'between_2', prefix);
const exprName = createExpressionName(parent);
Expand All @@ -66,45 +68,50 @@ export function generateFilterExpression(filter: any, prefix = null, parent = nu
expressionValues: exprValues,
};
break;
}
case 'ne':
case 'eq':
case 'gt':
case 'ge':
case 'lt':
case 'le':
case 'le': {
const operator = OPERATOR_MAP[name];
subExpr = {
expressions: [`${fieldName} ${operator} ${filedValueName}`],
expressionNames: createExpressionName(parent),
expressionValues: createExpressionValue(parent, name, value, prefix),
};
break;
case 'attributeExists':
}
case 'attributeExists': {
const existsName = value === true ? 'attribute_exists' : 'attribute_not_exists';
subExpr = {
expressions: [`${existsName}(${fieldName})`],
expressionNames: createExpressionName(parent),
expressionValues: createExpressionValue(parent, name, value, prefix),
};
break;
}
case 'contains':
case 'notContains':
case 'beginsWith':
case 'beginsWith': {
const functionName = FUNCTION_MAP[name];
subExpr = {
expressions: [`${functionName}(${fieldName}, ${filedValueName})`],
expressionNames: createExpressionName(parent),
expressionValues: createExpressionValue(parent, name, value, prefix),
};
break;
case 'in':
const operatorName = OPERATOR_MAP[name];
subExpr = {
expressions: [`${operatorName}(${filedValueName}, ${fieldName})`],
expressionNames: createExpressionName(parent),
expressionValues: createExpressionValue(parent, name, value, prefix),
};
break;
}
case 'in': {
const operatorName = OPERATOR_MAP[name];
subExpr = {
expressions: [`${operatorName}(${filedValueName}, ${fieldName})`],
expressionNames: createExpressionName(parent),
expressionValues: createExpressionValue(parent, name, value, prefix),
};
break;
}
default:
subExpr = scopeExpression(generateFilterExpression(value, prefix, name));
}
Expand Down
Loading

0 comments on commit 2294cf8

Please sign in to comment.