Skip to content

Commit

Permalink
fix: mark typescript rules, which extend eslint rule, as supported (#165
Browse files Browse the repository at this point in the history
)

closes #158

I harcoded the alias rules in the constant, before searching inside the
2 dependencies and comparing the result :)
  • Loading branch information
Sysix authored Oct 8, 2024
1 parent a19b2e9 commit 8ae1db7
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 40 deletions.
44 changes: 44 additions & 0 deletions scripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,50 @@ export const scopeMaps = {
typescript: '@typescript-eslint',
};

// Some typescript-eslint rules are re-implemented version of eslint rules.
// e.g. no-array-constructor, max-params, etc...
// Since oxlint supports these rules under eslint/* and it also supports TS,
// we should override these to make implementation status up-to-date.
export const typescriptRulesExtendEslintRules = [
'block-spacing',
'brace-style',
'class-methods-use-this',
'comma-dangle',
'comma-spacing',
'default-param-last',
'func-call-spacing',
'indent',
'init-declarations',
'key-spacing',
'keyword-spacing',
'lines-around-comment',
'lines-between-class-members',
'max-params',
'no-array-constructor',
'no-dupe-class-members',
'no-empty-function',
'no-extra-parens',
'no-extra-semi',
'no-invalid-this',
'no-loop-func',
'no-loss-of-precision',
'no-magic-numbers',
'no-redeclare',
'no-restricted-imports',
'no-shadow',
'no-unused-expressions',
'no-unused-vars',
'no-use-before-define',
'no-useless-constructor',
'object-curly-spacing',
'padding-line-between-statements',
'quotes',
'semi',
'space-before-blocks',
'space-before-function-paren',
'space-infix-ops',
];

export function convertScope(scope: string) {
return Reflect.has(scopeMaps, scope)
? scopeMaps[scope as 'eslint']
Expand Down
13 changes: 13 additions & 0 deletions scripts/traverse-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
prefixScope,
SPARSE_CLONE_DIRECTORY,
TARGET_DIRECTORY,
typescriptRulesExtendEslintRules,
} from './constants.js';

// Recursive function to read files in a directory, this currently assumes that the directory
Expand Down Expand Up @@ -114,6 +115,18 @@ async function processFile(
scope: scope,
category: keywordMatch[1],
});

if (scope === 'eslint') {
let ruleName = effectiveRuleName.replace(/^.*\//, '');

if (typescriptRulesExtendEslintRules.includes(ruleName)) {
successResultArray.push({
value: `@typescript-eslint/${ruleName}`,
scope: 'typescript',
category: keywordMatch[1],
});
}
}
} else {
failureResultArray.push({
value: effectiveRuleName,
Expand Down
10 changes: 10 additions & 0 deletions src/rules-by-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const pedanticRules = {
'no-inner-declarations': 'off',
'no-prototype-builtins': 'off',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'off',
'no-self-compare': 'off',
radix: 'off',
'require-await': 'off',
Expand Down Expand Up @@ -54,6 +55,7 @@ const restrictionRules = {
'no-bitwise': 'off',
'no-console': 'off',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'off',
'no-eval': 'off',
'no-restricted-globals': 'off',
'no-undefined': 'off',
Expand Down Expand Up @@ -85,8 +87,10 @@ const restrictionRules = {
const styleRules = {
'default-case-last': 'off',
'default-param-last': 'off',
'@typescript-eslint/default-param-last': 'off',
'guard-for-in': 'off',
'max-params': 'off',
'@typescript-eslint/max-params': 'off',
'no-continue': 'off',
'no-label-var': 'off',
'no-multi-str': 'off',
Expand Down Expand Up @@ -171,11 +175,13 @@ const conditionalFixSuggestionRules = {

const pendingRules = {
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'off',
'no-empty-static-block': 'off',
'no-extra-boolean-cast': 'off',
'no-fallthrough': 'off',
'no-iterator': 'off',
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': 'off',
'no-new-wrappers': 'off',
'no-nonoctal-decimal-escape': 'off',
'no-plusplus': 'off',
Expand Down Expand Up @@ -232,6 +238,7 @@ const correctnessRules = {
'no-control-regex': 'off',
'no-delete-var': 'off',
'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members': 'off',
'no-dupe-else-if': 'off',
'no-dupe-keys': 'off',
'no-duplicate-case': 'off',
Expand All @@ -244,6 +251,7 @@ const correctnessRules = {
'no-invalid-regexp': 'off',
'no-irregular-whitespace': 'off',
'no-loss-of-precision': 'off',
'@typescript-eslint/no-loss-of-precision': 'off',
'no-new-native-nonconstructor': 'off',
'no-obj-calls': 'off',
'no-self-assign': 'off',
Expand Down Expand Up @@ -363,6 +371,7 @@ const fixRules = {
'no-unsafe-negation': 'off',
'no-unused-labels': 'off',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'off',
'no-useless-escape': 'off',
'no-var': 'off',
'unicode-bom': 'off',
Expand Down Expand Up @@ -458,6 +467,7 @@ const suspiciousRules = {

const dangerousSuggestionRules = {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',
};

const conditionalSuggestionRules = {
Expand Down
90 changes: 50 additions & 40 deletions src/rules-by-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,55 @@ const eslintRules = {
'valid-typeof': 'off',
};

const typescriptRules = {
'@typescript-eslint/default-param-last': 'off',
'@typescript-eslint/max-params': 'off',
'@typescript-eslint/no-array-constructor': 'off',
'@typescript-eslint/no-dupe-class-members': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-loss-of-precision': 'off',
'@typescript-eslint/no-magic-numbers': 'off',
'@typescript-eslint/no-redeclare': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-useless-constructor': 'off',
'@typescript-eslint/adjacent-overload-signatures': 'off',
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-tslint-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-confusing-non-null-assertion': 'off',
'@typescript-eslint/no-duplicate-enum-values': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-extra-non-null-assertion': 'off',
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/no-import-type-side-effects': 'off',
'@typescript-eslint/no-misused-new': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-unnecessary-type-constraint': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/no-useless-empty-export': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-wrapper-object-types': 'off',
'@typescript-eslint/prefer-as-const': 'off',
'@typescript-eslint/prefer-enum-initializers': 'off',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-function-type': 'off',
'@typescript-eslint/prefer-literal-enum-member': 'off',
'@typescript-eslint/prefer-namespace-keyword': 'off',
'@typescript-eslint/prefer-ts-expect-error': 'off',
'@typescript-eslint/triple-slash-reference': 'off',
};

const importRules = {
'import/default': 'off',
'import/export': 'off',
Expand Down Expand Up @@ -320,45 +369,6 @@ const treeShakingRules = {
'tree-shaking/no-side-effects-in-initialization': 'off',
};

const typescriptRules = {
'@typescript-eslint/adjacent-overload-signatures': 'off',
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-tslint-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-confusing-non-null-assertion': 'off',
'@typescript-eslint/no-duplicate-enum-values': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-extra-non-null-assertion': 'off',
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/no-import-type-side-effects': 'off',
'@typescript-eslint/no-misused-new': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-unnecessary-type-constraint': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/no-useless-empty-export': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-wrapper-object-types': 'off',
'@typescript-eslint/prefer-as-const': 'off',
'@typescript-eslint/prefer-enum-initializers': 'off',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-function-type': 'off',
'@typescript-eslint/prefer-literal-enum-member': 'off',
'@typescript-eslint/prefer-namespace-keyword': 'off',
'@typescript-eslint/prefer-ts-expect-error': 'off',
'@typescript-eslint/triple-slash-reference': 'off',
};

const unicornRules = {
'unicorn/catch-error-name': 'off',
'unicorn/consistent-function-scoping': 'off',
Expand Down Expand Up @@ -460,6 +470,7 @@ const vitestRules = {

export {
eslintRules,
typescriptRules,
importRules,
jestRules,
jsdocRules,
Expand All @@ -471,7 +482,6 @@ export {
reactPerfRules,
securityRules,
treeShakingRules,
typescriptRules,
unicornRules,
vitestRules,
};

0 comments on commit 8ae1db7

Please sign in to comment.