From 75a9d51c4918325d9f3b9694e058b9dc3c8bc68d Mon Sep 17 00:00:00 2001 From: Matthew Holder Date: Fri, 28 May 2021 19:44:37 -0500 Subject: [PATCH] fix: subject fixed failure to propgate extension rules present in standard --- package.json | 8 ++++---- src/index.test.ts | 28 +++++++++++++++++++++++++++- src/index.ts | 44 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 65 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 14ed35912..5d0db771a 100644 --- a/package.json +++ b/package.json @@ -55,16 +55,16 @@ "TypeScript" ], "dependencies": { - "@typescript-eslint/parser": "^4.0.0", + "@typescript-eslint/parser": "^4.15.0", "eslint-config-standard": "^16.0.0" }, "peerDependencies": { + "@typescript-eslint/eslint-plugin": ">=4.15.0", "eslint": ">=7.12.1", "eslint-plugin-import": ">=2.22.1", "eslint-plugin-node": ">=11.1.0", "eslint-plugin-promise": ">=4.2.1", - "typescript": ">=3.9", - "@typescript-eslint/eslint-plugin": ">=4.0.1" + "typescript": ">=3.9" }, "devDependencies": { "@commitlint/cli": "12.1.4", @@ -72,7 +72,7 @@ "@commitlint/travis-cli": "12.1.4", "@types/eslint": "7.2.12", "@types/node": "14.17.1", - "@typescript-eslint/eslint-plugin": "4.0.1", + "@typescript-eslint/eslint-plugin": "4.15.0", "ava": "3.15.0", "editorconfig-checker": "3.3.0", "eslint": "7.27.0", diff --git a/src/index.test.ts b/src/index.test.ts index 6d41b8b8d..7bf5c67f1 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -35,6 +35,7 @@ test('export', (t): void => { rules: { 'brace-style': 'off', camelcase: 'off', + 'comma-dangle': 'off', 'comma-spacing': 'off', 'default-param-last': 'off', 'dot-notation': 'off', @@ -44,6 +45,9 @@ test('export', (t): void => { 'lines-between-class-members': 'off', 'no-array-constructor': 'off', 'no-dupe-class-members': 'off', + 'no-extra-parens': 'off', + 'no-implied-eval': 'off', + 'no-loss-of-precision': 'off', 'no-redeclare': 'off', 'no-throw-literal': 'off', 'no-undef': 'off', @@ -52,12 +56,24 @@ test('export', (t): void => { 'no-unused-expressions': 'off', 'no-useless-constructor': 'off', 'no-void': ['error', { allowAsStatement: true }], + 'object-curly-spacing': 'off', quotes: 'off', semi: 'off', 'space-before-function-paren': 'off', + 'space-infix-ops': 'off', '@typescript-eslint/adjacent-overload-signatures': 'error', '@typescript-eslint/array-type': ['error', { default: 'array-simple' }], '@typescript-eslint/brace-style': ['error', '1tbs', { allowSingleLine: true }], + '@typescript-eslint/comma-dangle': [ + 'error', + { + arrays: 'never', + exports: 'never', + functions: 'never', + imports: 'never', + objects: 'never' + } + ], '@typescript-eslint/comma-spacing': ['error', { before: false, after: true }], '@typescript-eslint/consistent-type-assertions': [ 'error', @@ -114,11 +130,16 @@ test('export', (t): void => { '@typescript-eslint/no-dynamic-delete': 'error', '@typescript-eslint/no-empty-interface': ['error', { allowSingleExtends: true }], '@typescript-eslint/no-extra-non-null-assertion': 'error', + '@typescript-eslint/no-extra-parens': [ + 'error', + 'functions' + ], '@typescript-eslint/no-extraneous-class': ['error', { allowWithDecorator: true }], '@typescript-eslint/no-floating-promises': 'error', '@typescript-eslint/no-for-in-array': 'error', '@typescript-eslint/no-implied-eval': 'error', '@typescript-eslint/no-invalid-void-type': 'error', + '@typescript-eslint/no-loss-of-precision': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-misused-promises': 'error', '@typescript-eslint/no-namespace': 'error', @@ -134,6 +155,10 @@ test('export', (t): void => { '@typescript-eslint/no-unused-expressions': ['error', { allowShortCircuit: true, allowTaggedTemplates: true, allowTernary: true }], '@typescript-eslint/no-useless-constructor': 'error', '@typescript-eslint/no-var-requires': 'error', + '@typescript-eslint/object-curly-spacing': [ + 'error', + 'always' + ], '@typescript-eslint/prefer-function-type': 'error', '@typescript-eslint/prefer-includes': 'error', '@typescript-eslint/prefer-nullish-coalescing': ['error', { ignoreConditionalTests: false, ignoreMixedLogicalExpressions: false }], @@ -149,6 +174,7 @@ test('export', (t): void => { '@typescript-eslint/return-await': ['error', 'always'], '@typescript-eslint/semi': ['error', 'never'], '@typescript-eslint/space-before-function-paren': ['error', 'always'], + '@typescript-eslint/space-infix-ops': 'error', '@typescript-eslint/strict-boolean-expressions': ['error', { allowString: false, allowNumber: false, @@ -192,7 +218,7 @@ test('Own peerDependencies include those of eslint-config-standard', async (t) = const name = _name as keyof typeof standardPkg.peerDependencies const ourDep = ourPeerDeps[name] const ourRange = ourDep.split('>=')[1] - const standardRange = standardDep.split('^')[1] + const standardRange = standardDep.split('^')[1].split('||')[0].trim() t.is(ourRange, standardRange) }) }) diff --git a/src/index.ts b/src/index.ts index 6dc410977..0076ab158 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,36 +2,61 @@ import configStandard from './eslint-config-standard' import { Linter } from 'eslint' const equivalents = [ + 'brace-style', + 'comma-dangle', 'comma-spacing', + 'default-param-last', 'dot-notation', - 'brace-style', 'func-call-spacing', 'indent', + 'init-declarations', 'keyword-spacing', 'lines-between-class-members', 'no-array-constructor', 'no-dupe-class-members', + 'no-duplicate-imports', + 'no-empty-function', + 'no-extra-parens', + 'no-extra-semi', + 'no-implied-eval', + 'no-invalid-this', + 'no-loop-func', + 'no-loss-of-precision', + 'no-magic-numbers', 'no-redeclare', + 'no-shadow', 'no-throw-literal', - 'no-unused-vars', 'no-unused-expressions', + 'no-unused-vars', + 'no-use-before-define', 'no-useless-constructor', + 'object-curly-spacing', 'quotes', + 'require-await', 'semi', - 'space-before-function-paren' + 'space-before-function-paren', + 'space-infix-ops' ] as const -const ruleFromStandard = (name: string): Linter.RuleEntry => { - if (configStandard.rules === undefined) throw new Error() - const rule = configStandard.rules[name] - if (rule === undefined) throw new Error() +const rawRuleFromStandard = (name: string): undefined|Linter.RuleEntry => { + if (configStandard.rules === undefined) return undefined + return configStandard.rules[name] +} + +const ruleFromStandard = (name: string): undefined|Linter.RuleEntry => { + const rule = rawRuleFromStandard(name) + if (rule === undefined) return undefined if (typeof rule !== 'object') return rule return JSON.parse(JSON.stringify(rule)) } +const disableEquivalentsRule = (name: string): undefined|'off' => { + return rawRuleFromStandard(name) !== undefined ? 'off' : undefined +} + function fromEntries (iterable: Array<[string, T]>): { [key: string]: T } { return [...iterable].reduce<{ [key: string]: T }>((obj, [key, val]) => { - obj[key] = val + if (val !== undefined) obj[key] = val return obj }, {}) } @@ -48,7 +73,7 @@ const config: Linter.Config = { 'no-undef': 'off', // Rules replaced by @typescript-eslint versions: - ...fromEntries(equivalents.map((name) => [name, 'off'])), + ...fromEntries(equivalents.map((name) => [name, disableEquivalentsRule(name)])), camelcase: 'off', 'default-param-last': 'off', 'no-use-before-define': 'off', @@ -102,7 +127,6 @@ const config: Linter.Config = { '@typescript-eslint/no-extraneous-class': ['error', { allowWithDecorator: true }], '@typescript-eslint/no-floating-promises': 'error', '@typescript-eslint/no-for-in-array': 'error', - '@typescript-eslint/no-implied-eval': 'error', '@typescript-eslint/no-invalid-void-type': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-misused-promises': 'error',