diff --git a/scripts/rules-generator.ts b/scripts/rules-generator.ts index d7db683..7a6d47b 100644 --- a/scripts/rules-generator.ts +++ b/scripts/rules-generator.ts @@ -71,7 +71,7 @@ export class RulesGenerator { return ` '${rule.replace(/_/g, '-')}': "off"`; }) .join(',\n'); - code += '\n}\n\n'; + code += '\n} as const\n\n'; } code += 'export {\n'; diff --git a/src/index.ts b/src/index.ts index 6cba651..ac50668 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,16 @@ import * as ruleMapsByScope from './rules-by-scope.js'; import * as ruleMapsByCategory from './rules-by-category.js'; import { createFlatRulesConfig } from './utils.js'; -const allRules: Record = Object.assign( +type UnionToIntersection = (U extends any ? (x: U) => void : never) extends ( + x: infer I +) => void + ? I + : never; + +type RulesGroups = keyof typeof ruleMapsByScope; +type AllRules = (typeof ruleMapsByScope)[RulesGroups]; + +const allRules: UnionToIntersection = Object.assign( {}, ...Object.values(ruleMapsByScope) ); diff --git a/src/rules-by-category.ts b/src/rules-by-category.ts index cc5b88f..33d7f58 100644 --- a/src/rules-by-category.ts +++ b/src/rules-by-category.ts @@ -33,7 +33,7 @@ const pedanticRules = { 'unicorn/no-unreadable-iife': 'off', 'unicorn/prefer-dom-node-remove': 'off', 'unicorn/prefer-event-target': 'off', -}; +} as const; const nurseryRules = { 'constructor-super': 'off', @@ -47,7 +47,7 @@ const nurseryRules = { 'react/require-render-return': 'off', 'react/rules-of-hooks': 'off', 'tree-shaking/no-side-effects-in-initialization': 'off', -}; +} as const; const restrictionRules = { 'default-case': 'off', @@ -82,7 +82,7 @@ const restrictionRules = { 'unicorn/no-anonymous-default-export': 'off', 'unicorn/no-array-reduce': 'off', 'unicorn/no-magic-array-flat-depth': 'off', -}; +} as const; const styleRules = { 'default-case-last': 'off', @@ -132,10 +132,11 @@ const styleRules = { 'unicorn/no-unreadable-array-destructuring': 'off', 'unicorn/prefer-reflect-apply': 'off', 'vitest/prefer-each': 'off', -}; +} as const; const conditionalFixRules = { eqeqeq: 'off', + 'no-else-return': 'off', 'prefer-numeric-literals': 'off', 'sort-imports': 'off', 'use-isnan': 'off', @@ -163,15 +164,15 @@ const conditionalFixRules = { 'unicorn/prefer-query-selector': 'off', 'unicorn/prefer-spread': 'off', 'unicorn/require-array-join-separator': 'off', -}; +} as const; const dangerousFixRules = { 'for-direction': 'off', -}; +} as const; const conditionalFixSuggestionRules = { 'func-names': 'off', -}; +} as const; const pendingRules = { 'no-array-constructor': 'off', @@ -225,7 +226,7 @@ const pendingRules = { 'unicorn/prefer-number-properties': 'off', 'unicorn/prefer-structured-clone': 'off', 'vitest/require-local-test-context-for-concurrent-snapshots': 'off', -}; +} as const; const correctnessRules = { 'no-async-promise-executor': 'off', @@ -351,7 +352,7 @@ const correctnessRules = { 'unicorn/no-invalid-remove-event-listener': 'off', 'unicorn/no-thenable': 'off', 'vitest/no-conditional-tests': 'off', -}; +} as const; const perfRules = { 'no-await-in-loop': 'off', @@ -359,11 +360,11 @@ const perfRules = { 'react-perf/jsx-no-new-array-as-prop': 'off', 'react-perf/jsx-no-new-function-as-prop': 'off', 'react-perf/jsx-no-new-object-as-prop': 'off', -}; +} as const; const conditionalSuggestionFixRules = { 'no-compare-neg-zero': 'off', -}; +} as const; const fixRules = { 'no-debugger': 'off', @@ -439,16 +440,16 @@ const fixRules = { 'vitest/prefer-to-be-falsy': 'off', 'vitest/prefer-to-be-object': 'off', 'vitest/prefer-to-be-truthy': 'off', -}; +} as const; const suggestionRules = { 'no-empty': 'off', -}; +} as const; const fixDangerousRules = { 'no-eq-null': 'off', 'no-unexpected-multiline': 'off', -}; +} as const; const suspiciousRules = { 'no-extend-native': 'off', @@ -463,16 +464,17 @@ const suspiciousRules = { 'react/react-in-jsx-scope': 'off', '@typescript-eslint/no-extraneous-class': 'off', '@typescript-eslint/no-unnecessary-type-constraint': 'off', -}; +} as const; + +const conditionalSuggestionRules = { + 'no-throw-literal': 'off', + 'jsx-a11y/anchor-has-content': 'off', +} as const; const dangerousSuggestionRules = { 'no-unused-vars': 'off', '@typescript-eslint/no-unused-vars': 'off', -}; - -const conditionalSuggestionRules = { - 'jsx-a11y/anchor-has-content': 'off', -}; +} as const; export { pedanticRules, @@ -490,6 +492,6 @@ export { suggestionRules, fixDangerousRules, suspiciousRules, - dangerousSuggestionRules, conditionalSuggestionRules, + dangerousSuggestionRules, }; diff --git a/src/rules-by-scope.ts b/src/rules-by-scope.ts index 6552e35..77fb8db 100644 --- a/src/rules-by-scope.ts +++ b/src/rules-by-scope.ts @@ -38,6 +38,7 @@ const eslintRules = { 'no-dupe-else-if': 'off', 'no-dupe-keys': 'off', 'no-duplicate-case': 'off', + 'no-else-return': 'off', 'no-empty': 'off', 'no-empty-character-class': 'off', 'no-empty-function': 'off', @@ -82,6 +83,7 @@ const eslintRules = { 'no-template-curly-in-string': 'off', 'no-ternary': 'off', 'no-this-before-super': 'off', + 'no-throw-literal': 'off', 'no-undef': 'off', 'no-undefined': 'off', 'no-unexpected-multiline': 'off', @@ -112,7 +114,7 @@ const eslintRules = { 'unicode-bom': 'off', 'use-isnan': 'off', 'valid-typeof': 'off', -}; +} as const; const typescriptRules = { '@typescript-eslint/default-param-last': 'off', @@ -161,7 +163,7 @@ const typescriptRules = { '@typescript-eslint/prefer-namespace-keyword': 'off', '@typescript-eslint/prefer-ts-expect-error': 'off', '@typescript-eslint/triple-slash-reference': 'off', -}; +} as const; const importRules = { 'import/default': 'off', @@ -180,7 +182,7 @@ const importRules = { 'import/no-self-import': 'off', 'import/no-unused-modules': 'off', 'import/no-webpack-loader-syntax': 'off', -}; +} as const; const jestRules = { 'jest/consistent-test-it': 'off', @@ -231,7 +233,7 @@ const jestRules = { 'jest/valid-describe-callback': 'off', 'jest/valid-expect': 'off', 'jest/valid-title': 'off', -}; +} as const; const jsdocRules = { 'jsdoc/check-access': 'off', @@ -252,7 +254,7 @@ const jsdocRules = { 'jsdoc/require-returns-description': 'off', 'jsdoc/require-returns-type': 'off', 'jsdoc/require-yields': 'off', -}; +} as const; const jsxA11yRules = { 'jsx-a11y/alt-text': 'off', @@ -282,7 +284,7 @@ const jsxA11yRules = { 'jsx-a11y/role-supports-aria-props': 'off', 'jsx-a11y/scope': 'off', 'jsx-a11y/tabindex-no-positive': 'off', -}; +} as const; const nextjsRules = { 'nextjs/google-font-display': 'off', @@ -305,11 +307,11 @@ const nextjsRules = { 'nextjs/no-title-in-document-head': 'off', 'nextjs/no-typos': 'off', 'nextjs/no-unwanted-polyfillio': 'off', -}; +} as const; const nodeRules = { 'node/no-exports-assign': 'off', -}; +} as const; const promiseRules = { 'promise/avoid-new': 'off', @@ -321,7 +323,7 @@ const promiseRules = { 'promise/prefer-await-to-then': 'off', 'promise/spec-only': 'off', 'promise/valid-params': 'off', -}; +} as const; const reactRules = { 'react/button-has-type': 'off', @@ -352,22 +354,22 @@ const reactRules = { 'react/rules-of-hooks': 'off', 'react/self-closing-comp': 'off', 'react/void-dom-elements-no-children': 'off', -}; +} as const; const reactPerfRules = { 'react-perf/jsx-no-jsx-as-prop': 'off', 'react-perf/jsx-no-new-array-as-prop': 'off', 'react-perf/jsx-no-new-function-as-prop': 'off', 'react-perf/jsx-no-new-object-as-prop': 'off', -}; +} as const; const securityRules = { 'security/api-keys': 'off', -}; +} as const; const treeShakingRules = { 'tree-shaking/no-side-effects-in-initialization': 'off', -}; +} as const; const unicornRules = { 'unicorn/catch-error-name': 'off', @@ -456,7 +458,7 @@ const unicornRules = { 'unicorn/switch-case-braces': 'off', 'unicorn/text-encoding-identifier-case': 'off', 'unicorn/throw-new-error': 'off', -}; +} as const; const vitestRules = { 'vitest/no-conditional-tests': 'off', @@ -466,7 +468,7 @@ const vitestRules = { 'vitest/prefer-to-be-object': 'off', 'vitest/prefer-to-be-truthy': 'off', 'vitest/require-local-test-context-for-concurrent-snapshots': 'off', -}; +} as const; export { eslintRules,