Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: manual lint fixes #11638

Merged
merged 32 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c8f78e8
fix: automatic lint fixes
sdstolworthy Dec 20, 2022
d8b4321
fix: coerce type
sdstolworthy Dec 20, 2022
4b95cac
fix: jest/no-jasmine-globals, no-inner-declarations, no-restricted-sy…
sdstolworthy Dec 20, 2022
8c9a7d5
fix: api extract
sdstolworthy Dec 20, 2022
b5d3d73
fix: double not
sdstolworthy Dec 20, 2022
b0986d1
fix: api extract
sdstolworthy Dec 21, 2022
bd41724
Merge branch 'automatic-lint-fixes' into manual-lint-fixes
sdstolworthy Dec 21, 2022
2e5c745
fix: added prettierrc
sdstolworthy Dec 21, 2022
06a91cf
Merge branch 'automatic-lint-fixes' into manual-lint-fixes
sdstolworthy Dec 21, 2022
c66cd17
fix: ts-ignore
sdstolworthy Dec 21, 2022
d59eafb
fix: adjust prettierrc
sdstolworthy Dec 21, 2022
87e2b19
Merge branch 'automatic-lint-fixes' into manual-lint-fixes
sdstolworthy Dec 21, 2022
a79f14c
fix: @typescript-eslint/ban-ts-comment
sdstolworthy Dec 21, 2022
f7e49d9
fix: no-constant-condition
sdstolworthy Dec 21, 2022
481c422
fix: no-useless-catch
sdstolworthy Dec 21, 2022
74f1c9a
fix: no-async-promise-executor
sdstolworthy Dec 21, 2022
1439ec6
fix: no-empty
sdstolworthy Dec 21, 2022
66017a8
fix: jest/no-standalone-expect
sdstolworthy Dec 21, 2022
8e836c8
fix: no-prototype-builtins
sdstolworthy Dec 21, 2022
20e803d
fix: prefer-const, jest/no-conditional-expect
sdstolworthy Dec 21, 2022
57ae614
fix: no-useless-escape
sdstolworthy Dec 21, 2022
207849b
Merge branch 'dev' of github.com:aws-amplify/amplify-cli into manual-…
sdstolworthy Dec 21, 2022
31c54a9
fix: @typescript-eslint/no-empty-function, no-case-declarations
sdstolworthy Dec 21, 2022
723e541
fix: consistent-return
sdstolworthy Dec 21, 2022
9e1097c
fix: added ignore where fix was overly onerous
sdstolworthy Dec 21, 2022
69f7210
fix: add description to enquirer declaration
sdstolworthy Dec 21, 2022
5b41cc4
fix: disable rule
sdstolworthy Dec 21, 2022
40fe876
fix: refactor unusual infinite loop syntax
sdstolworthy Dec 21, 2022
8b6d45a
fix: format
sdstolworthy Dec 21, 2022
2bdfb7e
fix: formatting
sdstolworthy Dec 21, 2022
655e131
fix: api
sdstolworthy Dec 22, 2022
b272738
fix: api
sdstolworthy Dec 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
jhockett marked this conversation as resolved.
Show resolved Hide resolved
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