diff --git a/.prettierignore b/.prettierignore index 50a789d61de..755a2771d25 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,7 +3,6 @@ **/coverage **/shared-fixtures **/tests/integration/fixtures/**/* -**/lib/configs/recommended.json **/.vscode **/.nyc_output packages/eslint-plugin-tslint/tests/test-tslint-rules-directory/alwaysFailRule.js diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 22afc3659ac..24ada799b9a 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -161,7 +161,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e | [`@typescript-eslint/restrict-plus-operands`](./docs/rules/restrict-plus-operands.md) | When adding two variables, operands must both be of type number or of type string. (`restrict-plus-operands` from TSLint) | | | :thought_balloon: | | [`@typescript-eslint/semi`](./docs/rules/semi.md) | Require or disallow semicolons instead of ASI | | :wrench: | | | [`@typescript-eslint/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) | Require consistent spacing around type annotations (`typedef-whitespace` from TSLint) | :heavy_check_mark: | :wrench: | | -| [`@typescript-eslint/unbound-method`](./docs/rules/unbound-method.md) | Enforces unbound methods are called with their expected scope. (`no-unbound-method` from TSLint) | :heavy_check_mark: | | :thought_balloon: | +| [`@typescript-eslint/unbound-method`](./docs/rules/unbound-method.md) | Enforces unbound methods are called with their expected scope. (`no-unbound-method` from TSLint) | | | :thought_balloon: | | [`@typescript-eslint/prefer-regexp-exec`](./docs/rules/prefer-regexp-exec.md) | Enforce to use `RegExp#exec` over `String#match` | | | :thought_balloon: | | [`@typescript-eslint/unified-signatures`](./docs/rules/unified-signatures.md) | Warns for any two overloads that could be unified into one. (`unified-signatures` from TSLint) | | | | diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 383c08dd392..3409c5984c6 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -29,10 +29,11 @@ "clean": "rimraf dist/", "docs": "eslint-docs", "docs:check": "eslint-docs check", + "test": "jest --coverage", + "generate:configs": "ts-node --files tools/generate-configs.ts", "format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore", "prebuild": "npm run clean", "recommended:update": "ts-node tools/update-recommended.ts", - "test": "jest --coverage", "typecheck": "tsc --noEmit" }, "dependencies": { @@ -41,7 +42,6 @@ "eslint-utils": "^1.3.1", "functional-red-black-tree": "^1.0.1", "regexpp": "^2.0.1", - "requireindex": "^1.2.0", "tsutils": "^3.7.0" }, "devDependencies": { diff --git a/packages/eslint-plugin/src/configs/all.json b/packages/eslint-plugin/src/configs/all.json new file mode 100644 index 00000000000..fa36e3d876c --- /dev/null +++ b/packages/eslint-plugin/src/configs/all.json @@ -0,0 +1,64 @@ +{ + "extends": "./configs/base.json", + "rules": { + "@typescript-eslint/adjacent-overload-signatures": "error", + "@typescript-eslint/array-type": "error", + "@typescript-eslint/await-thenable": "error", + "@typescript-eslint/ban-ts-ignore": "error", + "@typescript-eslint/ban-types": "error", + "camelcase": "off", + "@typescript-eslint/camelcase": "error", + "@typescript-eslint/class-name-casing": "error", + "@typescript-eslint/explicit-function-return-type": "error", + "@typescript-eslint/explicit-member-accessibility": "error", + "@typescript-eslint/func-call-spacing": "error", + "@typescript-eslint/generic-type-naming": "error", + "indent": "off", + "@typescript-eslint/indent": "error", + "@typescript-eslint/interface-name-prefix": "error", + "@typescript-eslint/member-delimiter-style": "error", + "@typescript-eslint/member-naming": "error", + "@typescript-eslint/member-ordering": "error", + "@typescript-eslint/no-angle-bracket-type-assertion": "error", + "no-array-constructor": "off", + "@typescript-eslint/no-array-constructor": "error", + "@typescript-eslint/no-empty-interface": "error", + "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/no-extra-parens": "error", + "@typescript-eslint/no-extraneous-class": "error", + "@typescript-eslint/no-for-in-array": "error", + "@typescript-eslint/no-inferrable-types": "error", + "@typescript-eslint/no-magic-numbers": "error", + "@typescript-eslint/no-misused-new": "error", + "@typescript-eslint/no-namespace": "error", + "@typescript-eslint/no-non-null-assertion": "error", + "@typescript-eslint/no-object-literal-type-assertion": "error", + "@typescript-eslint/no-parameter-properties": "error", + "@typescript-eslint/no-require-imports": "error", + "@typescript-eslint/no-this-alias": "error", + "@typescript-eslint/no-triple-slash-reference": "error", + "@typescript-eslint/no-type-alias": "error", + "@typescript-eslint/no-unnecessary-qualifier": "error", + "@typescript-eslint/no-unnecessary-type-assertion": "error", + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": "error", + "@typescript-eslint/no-use-before-define": "error", + "no-useless-constructor": "off", + "@typescript-eslint/no-useless-constructor": "error", + "@typescript-eslint/no-var-requires": "error", + "@typescript-eslint/prefer-for-of": "error", + "@typescript-eslint/prefer-function-type": "error", + "@typescript-eslint/prefer-includes": "error", + "@typescript-eslint/prefer-interface": "error", + "@typescript-eslint/prefer-namespace-keyword": "error", + "@typescript-eslint/prefer-regexp-exec": "error", + "@typescript-eslint/prefer-string-starts-ends-with": "error", + "@typescript-eslint/promise-function-async": "error", + "@typescript-eslint/require-array-sort-compare": "error", + "@typescript-eslint/restrict-plus-operands": "error", + "@typescript-eslint/semi": "error", + "@typescript-eslint/type-annotation-spacing": "error", + "@typescript-eslint/unbound-method": "error", + "@typescript-eslint/unified-signatures": "error" + } +} diff --git a/packages/eslint-plugin/src/configs/base.json b/packages/eslint-plugin/src/configs/base.json new file mode 100644 index 00000000000..9b6931ad616 --- /dev/null +++ b/packages/eslint-plugin/src/configs/base.json @@ -0,0 +1,7 @@ +{ + "parser": "@typescript-eslint/parser", + "parserOptions": { + "sourceType": "module" + }, + "plugins": ["@typescript-eslint"] +} diff --git a/packages/eslint-plugin/src/configs/recommended.json b/packages/eslint-plugin/src/configs/recommended.json index e107a645724..12edb521fe8 100644 --- a/packages/eslint-plugin/src/configs/recommended.json +++ b/packages/eslint-plugin/src/configs/recommended.json @@ -1,9 +1,5 @@ { - "parser": "@typescript-eslint/parser", - "parserOptions": { - "sourceType": "module" - }, - "plugins": ["@typescript-eslint"], + "extends": "./configs/base.json", "rules": { "@typescript-eslint/adjacent-overload-signatures": "error", "@typescript-eslint/array-type": "error", diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts index e62e97495d5..0fb5516ba72 100644 --- a/packages/eslint-plugin/src/index.ts +++ b/packages/eslint-plugin/src/index.ts @@ -1,23 +1,15 @@ -import requireIndex from 'requireindex'; -import path from 'path'; +import rules from './rules'; +import all from './configs/all.json'; +import base from './configs/base.json'; import recommended from './configs/recommended.json'; import eslintRecommended from './configs/eslint-recommended'; -const rules = requireIndex(path.join(__dirname, 'rules')); -// eslint expects the rule to be on rules[name], not rules[name].default -const rulesWithoutDefault = Object.keys(rules).reduce>( - (acc, ruleName) => { - acc[ruleName] = rules[ruleName].default; - return acc; - }, - {}, -); - -// import all rules in lib/rules export = { - rules: rulesWithoutDefault, + rules, configs: { + all, + base, recommended, 'eslint-recommended': eslintRecommended, }, diff --git a/packages/eslint-plugin/src/rules/ban-ts-ignore.ts b/packages/eslint-plugin/src/rules/ban-ts-ignore.ts index bf83a29cf4e..661031a03f7 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-ignore.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-ignore.ts @@ -8,7 +8,7 @@ export default util.createRule({ description: 'Bans “// @ts-ignore” comments from being used.', tslintRuleName: 'ban-ts-ignore', category: 'Best Practices', - recommended: 'error', + recommended: false, }, schema: [], messages: { diff --git a/packages/eslint-plugin/src/rules/index.ts b/packages/eslint-plugin/src/rules/index.ts new file mode 100644 index 00000000000..d62f58d6af3 --- /dev/null +++ b/packages/eslint-plugin/src/rules/index.ts @@ -0,0 +1,111 @@ +import adjacentOverloadSignatures from './adjacent-overload-signatures'; +import arrayType from './array-type'; +import awaitThenable from './await-thenable'; +import banTsIgnore from './ban-ts-ignore'; +import banTypes from './ban-types'; +import camelcase from './camelcase'; +import classNameCasing from './class-name-casing'; +import explicitFunctionReturnType from './explicit-function-return-type'; +import explicitMemberAccessibility from './explicit-member-accessibility'; +import funcCallSpacing from './func-call-spacing'; +import genericTypeNaming from './generic-type-naming'; +import indent from './indent'; +import interfaceNamePrefix from './interface-name-prefix'; +import memberDelimiterStyle from './member-delimiter-style'; +import memberNaming from './member-naming'; +import memberOrdering from './member-ordering'; +import noAngleBracketTypeAssertion from './no-angle-bracket-type-assertion'; +import noArrayConstructor from './no-array-constructor'; +import noEmptyInterface from './no-empty-interface'; +import noExplicitAny from './no-explicit-any'; +import noExtraParens from './no-extra-parens'; +import noExtraneousClass from './no-extraneous-class'; +import noForInArray from './no-for-in-array'; +import noInferrableTypes from './no-inferrable-types'; +import noMagicNumbers from './no-magic-numbers'; +import noMisusedNew from './no-misused-new'; +import noNamespace from './no-namespace'; +import noNonNullAssertion from './no-non-null-assertion'; +import noObjectLiteralTypeAssertion from './no-object-literal-type-assertion'; +import noParameterProperties from './no-parameter-properties'; +import noRequireImports from './no-require-imports'; +import noThisAlias from './no-this-alias'; +import noTripleSlashReference from './no-triple-slash-reference'; +import noTypeAlias from './no-type-alias'; +import noUnnecessaryQualifier from './no-unnecessary-qualifier'; +import noUnnecessaryTypeAssertion from './no-unnecessary-type-assertion'; +import noUnusedVars from './no-unused-vars'; +import noUseBeforeDefine from './no-use-before-define'; +import noUselessConstructor from './no-useless-constructor'; +import noVarRequires from './no-var-requires'; +import preferForOf from './prefer-for-of'; +import preferFunctionType from './prefer-function-type'; +import preferIncludes from './prefer-includes'; +import preferInterface from './prefer-interface'; +import preferNamespaceKeyword from './prefer-namespace-keyword'; +import preferRegexpExec from './prefer-regexp-exec'; +import preferStringStartsEndsWith from './prefer-string-starts-ends-with'; +import promiseFunctionAsync from './promise-function-async'; +import requireArraySortCompare from './require-array-sort-compare'; +import restrictPlusOperands from './restrict-plus-operands'; +import semi from './semi'; +import typeAnnotationSpacing from './type-annotation-spacing'; +import unboundMethod from './unbound-method'; +import unifiedSignatures from './unified-signatures'; + +export default { + 'adjacent-overload-signatures': adjacentOverloadSignatures, + 'array-type': arrayType, + 'await-thenable': awaitThenable, + 'ban-ts-ignore': banTsIgnore, + 'ban-types': banTypes, + camelcase: camelcase, + 'class-name-casing': classNameCasing, + 'explicit-function-return-type': explicitFunctionReturnType, + 'explicit-member-accessibility': explicitMemberAccessibility, + 'func-call-spacing': funcCallSpacing, + 'generic-type-naming': genericTypeNaming, + indent: indent, + 'interface-name-prefix': interfaceNamePrefix, + 'member-delimiter-style': memberDelimiterStyle, + 'member-naming': memberNaming, + 'member-ordering': memberOrdering, + 'no-angle-bracket-type-assertion': noAngleBracketTypeAssertion, + 'no-array-constructor': noArrayConstructor, + 'no-empty-interface': noEmptyInterface, + 'no-explicit-any': noExplicitAny, + 'no-extra-parens': noExtraParens, + 'no-extraneous-class': noExtraneousClass, + 'no-for-in-array': noForInArray, + 'no-inferrable-types': noInferrableTypes, + 'no-magic-numbers': noMagicNumbers, + 'no-misused-new': noMisusedNew, + 'no-namespace': noNamespace, + 'no-non-null-assertion': noNonNullAssertion, + 'no-object-literal-type-assertion': noObjectLiteralTypeAssertion, + 'no-parameter-properties': noParameterProperties, + 'no-require-imports': noRequireImports, + 'no-this-alias': noThisAlias, + 'no-triple-slash-reference': noTripleSlashReference, + 'no-type-alias': noTypeAlias, + 'no-unnecessary-qualifier': noUnnecessaryQualifier, + 'no-unnecessary-type-assertion': noUnnecessaryTypeAssertion, + 'no-unused-vars': noUnusedVars, + 'no-use-before-define': noUseBeforeDefine, + 'no-useless-constructor': noUselessConstructor, + 'no-var-requires': noVarRequires, + 'prefer-for-of': preferForOf, + 'prefer-function-type': preferFunctionType, + 'prefer-includes': preferIncludes, + 'prefer-interface': preferInterface, + 'prefer-namespace-keyword': preferNamespaceKeyword, + 'prefer-regexp-exec': preferRegexpExec, + 'prefer-string-starts-ends-with': preferStringStartsEndsWith, + 'promise-function-async': promiseFunctionAsync, + 'require-array-sort-compare': requireArraySortCompare, + 'restrict-plus-operands': restrictPlusOperands, + semi: semi, + 'type-annotation-spacing': typeAnnotationSpacing, + 'unbound-method': unboundMethod, + 'unified-signatures': unifiedSignatures, +}; diff --git a/packages/eslint-plugin/src/rules/no-require-imports.ts b/packages/eslint-plugin/src/rules/no-require-imports.ts index 69b4887c925..8bed451ccb7 100644 --- a/packages/eslint-plugin/src/rules/no-require-imports.ts +++ b/packages/eslint-plugin/src/rules/no-require-imports.ts @@ -9,7 +9,7 @@ export default util.createRule({ description: 'Disallows invocation of `require()`.', tslintName: 'no-require-imports', category: 'Best Practices', - recommended: 'error', + recommended: false, }, schema: [], messages: { diff --git a/packages/eslint-plugin/src/rules/promise-function-async.ts b/packages/eslint-plugin/src/rules/promise-function-async.ts index 0eb96e99143..ef041758630 100644 --- a/packages/eslint-plugin/src/rules/promise-function-async.ts +++ b/packages/eslint-plugin/src/rules/promise-function-async.ts @@ -21,7 +21,7 @@ export default util.createRule({ 'Requires any function or method that returns a Promise to be marked async.', tslintName: 'promise-function-async', category: 'Best Practices', - recommended: 'error', + recommended: false, }, messages: { missingAsync: 'Functions that return promises must be async.', diff --git a/packages/eslint-plugin/src/rules/unbound-method.ts b/packages/eslint-plugin/src/rules/unbound-method.ts index cd273a65456..cb9e388370e 100644 --- a/packages/eslint-plugin/src/rules/unbound-method.ts +++ b/packages/eslint-plugin/src/rules/unbound-method.ts @@ -26,7 +26,7 @@ export default util.createRule({ description: 'Enforces unbound methods are called with their expected scope.', tslintName: 'no-unbound-method', - recommended: 'error', + recommended: false, }, messages: { unbound: diff --git a/packages/eslint-plugin/tests/configs/all.test.ts b/packages/eslint-plugin/tests/configs/all.test.ts new file mode 100644 index 00000000000..425e3a1426a --- /dev/null +++ b/packages/eslint-plugin/tests/configs/all.test.ts @@ -0,0 +1,46 @@ +import rules from '../../src/rules'; +import allConfig from '../../src/configs/all.json'; +import { TSESLint } from '@typescript-eslint/experimental-utils'; + +interface IndexRules { + [name: string]: TSESLint.RuleModule; +} +interface JsonRules { + [name: string]: string; +} + +describe('all.json config', () => { + const RULE_NAME_PREFIX = '@typescript-eslint/'; + + const typedRules: IndexRules = rules; + const notDeprecatedRuleNames = Object.keys(typedRules).reduce( + (collection, name) => { + if (!typedRules[name].meta.deprecated) { + collection.push(`${RULE_NAME_PREFIX}${name}`); + } + return collection; + }, + [], + ); + + // with end of Node.js 6 support, we can use Object.entries(allConfig.rules) here + const configRules: JsonRules = allConfig.rules; + const typescriptEslintConfigRules = Object.keys(configRules).filter(name => + name.startsWith(RULE_NAME_PREFIX), + ); + const typescriptEslintConfigRuleValues = typescriptEslintConfigRules.map( + name => configRules[name], + ); + + it('contains all @typescript-eslint/eslint-plugin rule modules, except the deprecated ones', () => { + expect(notDeprecatedRuleNames).toEqual( + expect.arrayContaining(typescriptEslintConfigRules), + ); + }); + + it('has all containing @typescript-eslint/eslint-plugin rules enabled with "error"', () => { + expect(['error']).toEqual( + expect.arrayContaining(typescriptEslintConfigRuleValues), + ); + }); +}); diff --git a/packages/eslint-plugin/tests/index.test.ts b/packages/eslint-plugin/tests/index.test.ts new file mode 100644 index 00000000000..3cac8304e9c --- /dev/null +++ b/packages/eslint-plugin/tests/index.test.ts @@ -0,0 +1,24 @@ +import fs from 'fs'; +import path from 'path'; + +import eslintPlugin from '../src'; +import rules from '../src/rules'; + +describe('eslint-plugin ("./src/index.ts")', () => { + const ruleKeys = Object.keys(rules); + const eslintPluginRuleKeys = Object.keys(eslintPlugin.rules); + + const configs = fs + .readdirSync('./src/configs') + .filter(file => ['.json', '.ts'].includes(path.extname(file).toLowerCase())) + .map(file => path.basename(file, path.extname(file))); + const eslintPluginConfigKeys = Object.keys(eslintPlugin.configs); + + it('exports all available rules', () => { + expect(ruleKeys).toEqual(expect.arrayContaining(eslintPluginRuleKeys)); + }); + + it('exports all available configs', () => { + expect(configs).toEqual(expect.arrayContaining(eslintPluginConfigKeys)); + }); +}); diff --git a/packages/eslint-plugin/tests/rules/index.test.ts b/packages/eslint-plugin/tests/rules/index.test.ts new file mode 100644 index 00000000000..c9160c0522f --- /dev/null +++ b/packages/eslint-plugin/tests/rules/index.test.ts @@ -0,0 +1,14 @@ +import fs from 'fs'; + +import rules from '../../src/rules'; + +describe('./src/rules/index.ts', () => { + const ruleNames = Object.keys(rules).map(name => `${name}.ts`); + const files = fs + .readdirSync('./src/rules') + .filter(file => file !== 'index.ts' && file.endsWith('.ts')); + + it('imports all available rule modules', () => { + expect(ruleNames).toEqual(expect.arrayContaining(files)); + }); +}); diff --git a/packages/eslint-plugin/tools/generate-configs.ts b/packages/eslint-plugin/tools/generate-configs.ts new file mode 100644 index 00000000000..4c29753a048 --- /dev/null +++ b/packages/eslint-plugin/tools/generate-configs.ts @@ -0,0 +1,109 @@ +/* eslint-disable no-console */ + +import { Linter } from 'eslint'; +import fs from 'fs'; +import path from 'path'; +import { TSESLint } from '@typescript-eslint/experimental-utils'; +import rules from '../src/rules'; + +interface LinterConfigRules { + [name: string]: Linter.RuleLevel | Linter.RuleLevelAndOptions; +} + +interface LinterConfig extends Linter.Config { + extends?: string | string[]; + plugins?: string[]; +} + +const RULE_NAME_PREFIX = '@typescript-eslint/'; +const MAX_RULE_NAME_LENGTH = 32 + RULE_NAME_PREFIX.length; +const DEFAULT_RULE_SETTING = 'warn'; +const BASE_RULES_TO_BE_OVERRIDDEN = new Set([ + 'camelcase', + 'indent', + 'no-array-constructor', + 'no-unused-vars', + 'no-useless-constructor', +]); + +const ruleEntries = Object.entries(rules); + +/** + * Helper function reduces records to key - value pairs. + * @param config + * @param entry + */ +const reducer = ( + config: LinterConfigRules, + entry: [string, TSESLint.RuleModule], + settings: { + errorLevel?: 'error' | 'warn'; + filterDeprecated: boolean; + }, +) => { + const key = entry[0]; + const value = entry[1]; + + if (settings.filterDeprecated && value.meta.deprecated) { + return config; + } + + const ruleName = `${RULE_NAME_PREFIX}${key}`; + const recommendation = value.meta.docs.recommended; + const usedSetting = settings.errorLevel + ? settings.errorLevel + : !recommendation + ? DEFAULT_RULE_SETTING + : recommendation; + + if (BASE_RULES_TO_BE_OVERRIDDEN.has(key)) { + console.log(key.padEnd(MAX_RULE_NAME_LENGTH), '=', 'off'); + config[key] = 'off'; + } + console.log(ruleName.padEnd(MAX_RULE_NAME_LENGTH), '=', usedSetting); + config[ruleName] = usedSetting; + + return config; +}; + +/** + * Helper function writes configuration. + */ +function writeConfig(config: LinterConfig, filePath: string): void { + fs.writeFileSync(filePath, `${JSON.stringify(config, null, 2)}\n`); +} + +const baseConfig: LinterConfig = { + parser: '@typescript-eslint/parser', + parserOptions: { + sourceType: 'module', + }, + plugins: ['@typescript-eslint'], +}; +writeConfig(baseConfig, path.resolve(__dirname, '../src/configs/base.json')); + +console.log('------------------------- all.json -------------------------'); +const allConfig: LinterConfig = { + extends: './configs/base.json', + rules: ruleEntries.reduce( + (config, entry) => + reducer(config, entry, { errorLevel: 'error', filterDeprecated: true }), + {}, + ), +}; +writeConfig(allConfig, path.resolve(__dirname, '../src/configs/all.json')); + +console.log('--------------------- recommended.json ---------------------'); +const recommendedConfig: LinterConfig = { + extends: './configs/base.json', + rules: ruleEntries + .filter(entry => !!entry[1].meta.docs.recommended) + .reduce( + (config, entry) => reducer(config, entry, { filterDeprecated: true }), + {}, + ), +}; +writeConfig( + recommendedConfig, + path.resolve(__dirname, '../src/configs/recommended.json'), +); diff --git a/packages/eslint-plugin/tools/update-recommended.ts b/packages/eslint-plugin/tools/update-recommended.ts deleted file mode 100644 index 39861d35ee7..00000000000 --- a/packages/eslint-plugin/tools/update-recommended.ts +++ /dev/null @@ -1,68 +0,0 @@ -/* eslint-disable no-console */ - -import path from 'path'; -import fs from 'fs'; -import requireIndex from 'requireindex'; - -const bannedRecommendedRules = new Set([ - 'camelcase', - 'indent', - 'no-array-constructor', - 'no-unused-vars', -]); -const MAX_RULE_NAME_LENGTH = 32 + 'typescript/'.length; - -function padEnd(str: string, length: number): string { - while (str.length < length) { - str += ' '; - } - return str; -} - -/** - * Generate recommended configuration - */ -function generate(): void { - // replace this with Object.entries when node > 8 - const allRules = requireIndex(path.resolve(__dirname, '../dist/lib/rules')); - - const rules = Object.keys(allRules) - .filter(key => !!allRules[key].meta.docs.recommended) - .reduce>((config, key) => { - // having this here is just for output niceness (the keys will be ordered) - if (bannedRecommendedRules.has(key)) { - console.log(padEnd(key, MAX_RULE_NAME_LENGTH), '= off'); - config[key] = 'off'; - } - - const ruleName = `@typescript-eslint/${key}`; - const setting = allRules[key].meta.docs.recommended; - - if (!['error', 'warn'].includes(setting)) { - console.log(`ERR! Invalid level for rule ${key}: "${setting}"`); - // Don't want to throw an error since ^ explains what happened. - // eslint-disable-next-line no-process-exit - process.exit(1); - } - - console.log(padEnd(ruleName, MAX_RULE_NAME_LENGTH), '=', setting); - config[ruleName] = setting; - - return config; - }, {}); - - const filePath = path.resolve(__dirname, '../src/configs/recommended.json'); - - const recommendedConfig = { - parser: '@typescript-eslint/parser', - parserOptions: { - sourceType: 'module', - }, - plugins: ['@typescript-eslint'], - rules, - }; - - fs.writeFileSync(filePath, `${JSON.stringify(recommendedConfig, null, 4)}\n`); -} - -generate(); diff --git a/packages/eslint-plugin/typings/requireindex.d.ts b/packages/eslint-plugin/typings/requireindex.d.ts deleted file mode 100644 index 03807931eed..00000000000 --- a/packages/eslint-plugin/typings/requireindex.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -declare module 'requireindex' { - type RequireIndex = ( - path: string, - basenames?: string[], - ) => Record; - - const fn: RequireIndex; - export = fn; -} diff --git a/yarn.lock b/yarn.lock index b296e145ad2..6541649af58 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6308,11 +6308,6 @@ require-main-filename@^2.0.0: resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== -requireindex@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/requireindex/-/requireindex-1.2.0.tgz#3463cdb22ee151902635aa6c9535d4de9c2ef1ef" - integrity sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww== - resolve-cwd@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"