From c179c7cf4c2abd58e73ecfc1650626a2f9c61cf2 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 21 Jun 2020 16:18:57 +1200 Subject: [PATCH] chore: backport non-breaking changes from next (#607) * chore: enable eslint core rules enabled by v3 of `@typescript-eslint` * chore: target `es2015` in `tsconfig.json` This is required for using private identifiers, which are used by `@typescript-eslint` v3. We don't use `tsc` to actually build any code, so this change only affects the typechecking side of the compiler. * chore(valid-title): adjust default for `disallowedWords` option `@typescript-eslint` v3 changed the structure of their types, meaning that we need to type the options for `valid-title`. This in turn means we have to provide a direct default value for the `disallowedWords` option, in turn meaning we have to adjust our test to ensure proper coverage instead of relying on the `default` property. * chore(prefer-expect-assertions): adjust how report object is built `@typescript-eslint` v3 changed the structure of their types, meaning that the `suggest` property in `TSESLint.ReportDescriptor` is now marked as being `readonly`, so we can't assign to it. The easiest way around this is to just refactor our code to be slightly different, given it doesn't impact behaviour, performance, or clarity. * chore: apply prettier to `renovate.json` * chore: explicitly set `prettier` options --- .eslintrc.js | 6 ++++++ package.json | 2 ++ renovate.json | 4 +--- src/rules/__tests__/valid-title.test.ts | 4 ++++ src/rules/no-deprecated-functions.ts | 1 + src/rules/prefer-expect-assertions.ts | 18 ++++++++++-------- src/rules/valid-title.ts | 15 ++++++++++++--- tsconfig.json | 2 +- 8 files changed, 37 insertions(+), 15 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 1d51c96d1..131c10156 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -72,6 +72,12 @@ module.exports = { { blankLine: 'always', prev: 'directive', next: '*' }, { blankLine: 'any', prev: 'directive', next: 'directive' }, ], + + // todo: pulled from v3 of @typescript-eslint's eslint-recommended config + 'prefer-spread': 'error', + 'prefer-rest-params': 'error', + 'prefer-const': 'error', + 'no-var': 'error', }, overrides: [ { diff --git a/package.json b/package.json index 31f62cd02..dffe72bee 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,8 @@ ] }, "prettier": { + "arrowParens": "avoid", + "endOfLine": "auto", "proseWrap": "always", "singleQuote": true, "trailingComma": "all" diff --git a/renovate.json b/renovate.json index f6d03fb49..c70b3ff09 100644 --- a/renovate.json +++ b/renovate.json @@ -1,7 +1,5 @@ { - "extends": [ - "config:base" - ], + "extends": ["config:base"], "lockFileMaintenance": { "enabled": true }, "rangeStrategy": "replace", "ignorePresets": ["group:semantic-releaseMonorepo"] diff --git a/src/rules/__tests__/valid-title.test.ts b/src/rules/__tests__/valid-title.test.ts index 73f44ea0a..714dc805b 100644 --- a/src/rules/__tests__/valid-title.test.ts +++ b/src/rules/__tests__/valid-title.test.ts @@ -19,6 +19,10 @@ ruleTester.run('disallowedWords option', rule, { { ignoreTypeOfDescribeName: false, disallowedWords: ['correct'] }, ], }, + { + code: 'it("correctly sets the value", () => {});', + options: [{ disallowedWords: undefined }], + }, ], invalid: [ { diff --git a/src/rules/no-deprecated-functions.ts b/src/rules/no-deprecated-functions.ts index cdbf42d11..6bf19a682 100644 --- a/src/rules/no-deprecated-functions.ts +++ b/src/rules/no-deprecated-functions.ts @@ -124,6 +124,7 @@ export default createRule({ }, node, fix(fixer) { + // eslint-disable-next-line prefer-const let [name, func] = replacement.split('.'); if (callee.property.type === AST_NODE_TYPES.Literal) { diff --git a/src/rules/prefer-expect-assertions.ts b/src/rules/prefer-expect-assertions.ts index a510fb78b..6cc707da9 100644 --- a/src/rules/prefer-expect-assertions.ts +++ b/src/rules/prefer-expect-assertions.ts @@ -150,19 +150,21 @@ export default createRule<[], MessageIds>({ } if (!hasOnlyOneArgument(testFuncFirstLine)) { - const report: TSESLint.ReportDescriptor = { - messageId: 'assertionsRequiresOneArgument', - loc: testFuncFirstLine.callee.property.loc, - }; + let { loc } = testFuncFirstLine.callee.property; + const suggest: TSESLint.ReportSuggestionArray = []; if (testFuncFirstLine.arguments.length) { - report.loc = testFuncFirstLine.arguments[1].loc; - report.suggest = [ + loc = testFuncFirstLine.arguments[1].loc; + suggest.push( suggestRemovingExtraArguments(testFuncFirstLine.arguments, 1), - ]; + ); } - context.report(report); + context.report({ + messageId: 'assertionsRequiresOneArgument', + suggest, + loc, + }); return; } diff --git a/src/rules/valid-title.ts b/src/rules/valid-title.ts index bec7f888c..e05f5aedf 100644 --- a/src/rules/valid-title.ts +++ b/src/rules/valid-title.ts @@ -37,7 +37,17 @@ const quoteStringValue = (node: StringNode): string => ? `\`${node.quasis[0].value.raw}\`` : node.raw; -export default createRule({ +type MessageIds = + | 'titleMustBeString' + | 'emptyTitle' + | 'duplicatePrefix' + | 'accidentalSpace' + | 'disallowedWord'; + +export default createRule< + [{ ignoreTypeOfDescribeName?: boolean; disallowedWords?: string[] }], + MessageIds +>({ name: __filename, meta: { docs: { @@ -64,7 +74,6 @@ export default createRule({ disallowedWords: { type: 'array', items: { type: 'string' }, - default: [], }, }, additionalProperties: false, @@ -73,7 +82,7 @@ export default createRule({ fixable: 'code', }, defaultOptions: [{ ignoreTypeOfDescribeName: false, disallowedWords: [] }], - create(context, [{ ignoreTypeOfDescribeName, disallowedWords }]) { + create(context, [{ ignoreTypeOfDescribeName, disallowedWords = [] }]) { const disallowedWordsRegexp = new RegExp( `\\b(${disallowedWords.join('|')})\\b`, 'iu', diff --git a/tsconfig.json b/tsconfig.json index 4deba7ffb..fb22ad4db 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "es2015", "module": "commonjs", "moduleResolution": "node", "noEmit": true,