Skip to content

Commit

Permalink
feat(build): improve ts tdefinitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Oct 12, 2024
1 parent ec4e63a commit dd6ecee
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 38 deletions.
2 changes: 1 addition & 1 deletion scripts/rules-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = Object.assign(
type UnionToIntersection<U> = (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<AllRules> = Object.assign(
{},
...Object.values(ruleMapsByScope)
);
Expand Down
44 changes: 23 additions & 21 deletions src/rules-by-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -351,19 +352,19 @@ 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',
'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 conditionalSuggestionFixRules = {
'no-compare-neg-zero': 'off',
};
} as const;

const fixRules = {
'no-debugger': 'off',
Expand Down Expand Up @@ -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',
Expand All @@ -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,
Expand All @@ -490,6 +492,6 @@ export {
suggestionRules,
fixDangerousRules,
suspiciousRules,
dangerousSuggestionRules,
conditionalSuggestionRules,
dangerousSuggestionRules,
};
32 changes: 17 additions & 15 deletions src/rules-by-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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,
Expand Down

0 comments on commit dd6ecee

Please sign in to comment.