diff --git a/scripts/traverse-rules.test.ts b/scripts/traverse-rules.test.ts index cb35f1c..850108c 100644 --- a/scripts/traverse-rules.test.ts +++ b/scripts/traverse-rules.test.ts @@ -106,20 +106,18 @@ suite('readFilesRecursively', () => { value: 'oxc/rulename-which-will-be-skipped', }, ]); - expect(failureResultArray).toEqual([ - { - category: 'unknown', - error: 'No match block for `declare_oxc_lint`', - scope: 'eslint', - value: 'rulename-with-mod', - }, - { - category: 'unknown', - error: 'No match block for `declare_oxc_lint`', - scope: 'typescript', - value: '@typescript-eslint/rulename-without-mod', - }, - ]); + expect(failureResultArray).toContainEqual({ + category: 'unknown', + error: 'No match block for `declare_oxc_lint`', + scope: 'eslint', + value: 'rulename-with-mod', + }); + expect(failureResultArray).toContainEqual({ + category: 'unknown', + error: 'No match block for `declare_oxc_lint`', + scope: 'typescript', + value: '@typescript-eslint/rulename-without-mod', + }); }); test('readFilesRecursively returns parsed rules correctly', async () => { @@ -161,24 +159,21 @@ suite('readFilesRecursively', () => { // Call the function await readFilesRecursively('.', successResultArray, [], []); - - expect(successResultArray).toEqual([ - { - category: 'style', - scope: 'eslint', - value: 'rulename-with-mod', - }, - { - category: 'correctness', - scope: 'typescript', - value: '@typescript-eslint/rulename-without-mod', - }, - { - category: 'correctness', - scope: 'unicorn', - value: 'unicorn/rule-with-fixability', - }, - ]); + expect(successResultArray).toContainEqual({ + category: 'style', + scope: 'eslint', + value: 'rulename-with-mod', + }); + expect(successResultArray).toContainEqual({ + category: 'correctness', + scope: 'typescript', + value: '@typescript-eslint/rulename-without-mod', + }); + expect(successResultArray).toContainEqual({ + category: 'correctness', + scope: 'unicorn', + value: 'unicorn/rule-with-fixability', + }); expect(skippedResultArray).toEqual([]); expect(failureResultArray).toEqual([]); diff --git a/scripts/traverse-rules.ts b/scripts/traverse-rules.ts index 9e2f633..d9ee7cb 100644 --- a/scripts/traverse-rules.ts +++ b/scripts/traverse-rules.ts @@ -27,25 +27,30 @@ export async function readFilesRecursively( (entry) => entry.isFile() && entry.name === 'mod.rs' ); - for (const entry of entries) { - const entryPath = path.join(directory, entry.name); - if (entry.isDirectory()) { - await readFilesRecursively( - entryPath, - successResultArray, - skippedResultArray, - failureResultArray - ); // Recursive call for directories - } else if (entry.isFile() && (!containsModRs || entry.name === 'mod.rs')) { - await processFile( - entryPath, - directory, - successResultArray, - skippedResultArray, - failureResultArray - ); // Process each file - } - } + await Promise.all( + entries.map(async (entry) => { + const entryPath = path.join(directory, entry.name); + if (entry.isDirectory()) { + await readFilesRecursively( + entryPath, + successResultArray, + skippedResultArray, + failureResultArray + ); // Recursive call for directories + } else if ( + entry.isFile() && + (!containsModRs || entry.name === 'mod.rs') + ) { + await processFile( + entryPath, + directory, + successResultArray, + skippedResultArray, + failureResultArray + ); // Process each file + } + }) + ); } export interface Rule { @@ -209,6 +214,16 @@ export async function traverseRules(): Promise<{ failureResultArray ); + successResultArray.sort((aRule, bRule) => { + const scopeCompare = aRule.scope.localeCompare(bRule.scope); + + if (scopeCompare !== 0) { + return scopeCompare; + } + + return aRule.value.localeCompare(bRule.value); + }); + console.log( `>> Parsed ${successResultArray.length} rules, skipped ${skippedResultArray.length} and encountered ${failureResultArray.length} failures\n` ); diff --git a/src/generated/configs-by-scope.ts b/src/generated/configs-by-scope.ts index 0f084b4..5e51f64 100644 --- a/src/generated/configs-by-scope.ts +++ b/src/generated/configs-by-scope.ts @@ -7,11 +7,6 @@ const eslintConfig = { rules: rules.eslintRules, }; -const typescriptConfig = { - name: 'oxlint/typescript', - rules: rules.typescriptRules, -}; - const importConfig = { name: 'oxlint/import', rules: rules.importRules, @@ -62,6 +57,11 @@ const reactPerfConfig = { rules: rules.reactPerfRules, }; +const typescriptConfig = { + name: 'oxlint/typescript', + rules: rules.typescriptRules, +}; + const unicornConfig = { name: 'oxlint/unicorn', rules: rules.unicornRules, @@ -74,7 +74,6 @@ const vitestConfig = { const configByScope = { 'flat/eslint': eslintConfig, - 'flat/typescript': typescriptConfig, 'flat/import': importConfig, 'flat/jest': jestConfig, 'flat/jsdoc': jsdocConfig, @@ -85,6 +84,7 @@ const configByScope = { 'flat/react': reactConfig, 'flat/react-hooks': reactHooksConfig, 'flat/react-perf': reactPerfConfig, + 'flat/typescript': typescriptConfig, 'flat/unicorn': unicornConfig, 'flat/vitest': vitestConfig, }; diff --git a/src/generated/rules-by-category.ts b/src/generated/rules-by-category.ts index 72b09c4..e9a3f92 100644 --- a/src/generated/rules-by-category.ts +++ b/src/generated/rules-by-category.ts @@ -6,7 +6,6 @@ const pedanticRules = { 'max-classes-per-file': 'off', 'max-lines': 'off', 'no-array-constructor': 'off', - '@typescript-eslint/no-array-constructor': 'off', 'no-case-declarations': 'off', 'no-constructor-return': 'off', 'no-else-return': 'off', @@ -15,7 +14,6 @@ const pedanticRules = { 'no-new-wrappers': 'off', 'no-prototype-builtins': 'off', 'no-redeclare': 'off', - '@typescript-eslint/no-redeclare': 'off', 'no-self-compare': 'off', 'no-throw-literal': 'off', radix: 'off', @@ -36,6 +34,8 @@ const pedanticRules = { 'react/no-unescaped-entities': 'off', '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/no-array-constructor': 'off', + '@typescript-eslint/no-redeclare': 'off', '@typescript-eslint/no-unsafe-function-type': 'off', '@typescript-eslint/prefer-enum-initializers': 'off', '@typescript-eslint/prefer-ts-expect-error': 'off', @@ -87,8 +87,8 @@ const nurseryRules = { 'import/no-deprecated': 'off', 'import/no-unused-modules': 'off', 'promise/no-return-in-finally': 'off', - 'react-hooks/exhaustive-deps': 'off', 'react/require-render-return': 'off', + 'react-hooks/exhaustive-deps': 'off', 'react-hooks/rules-of-hooks': 'off', '@typescript-eslint/consistent-type-imports': 'off', } as const; @@ -101,7 +101,6 @@ const restrictionRules = { 'no-div-regex': 'off', 'no-empty': 'off', 'no-empty-function': 'off', - '@typescript-eslint/no-empty-function': 'off', 'no-eq-null': 'off', 'no-eval': 'off', 'no-iterator': 'off', @@ -130,6 +129,7 @@ const restrictionRules = { 'react/no-unknown-property': 'off', '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/no-dynamic-delete': 'off', + '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-empty-object-type': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-import-type-side-effects': 'off', @@ -155,15 +155,12 @@ const restrictionRules = { const styleRules = { 'default-case-last': 'off', 'default-param-last': 'off', - '@typescript-eslint/default-param-last': 'off', 'func-names': 'off', 'guard-for-in': 'off', 'max-params': 'off', - '@typescript-eslint/max-params': 'off', 'no-continue': 'off', 'no-label-var': 'off', 'no-magic-numbers': 'off', - '@typescript-eslint/no-magic-numbers': 'off', 'no-multi-str': 'off', 'no-new-func': 'off', 'no-return-assign': 'off', @@ -228,7 +225,10 @@ const styleRules = { '@typescript-eslint/ban-tslint-comment': 'off', '@typescript-eslint/consistent-indexed-object-style': 'off', '@typescript-eslint/consistent-type-definitions': 'off', + '@typescript-eslint/default-param-last': 'off', + '@typescript-eslint/max-params': 'off', '@typescript-eslint/no-empty-interface': 'off', + '@typescript-eslint/no-magic-numbers': 'off', '@typescript-eslint/prefer-for-of': 'off', '@typescript-eslint/prefer-function-type': 'off', '@typescript-eslint/prefer-namespace-keyword': 'off', @@ -280,7 +280,6 @@ const correctnessRules = { 'no-debugger': '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', @@ -295,7 +294,6 @@ 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-nonoctal-decimal-escape': 'off', 'no-obj-calls': 'off', @@ -310,7 +308,6 @@ const correctnessRules = { 'no-unused-labels': 'off', 'no-unused-private-class-members': 'off', 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': 'off', 'no-useless-catch': 'off', 'no-useless-escape': 'off', 'no-useless-rename': 'off', @@ -403,12 +400,15 @@ const correctnessRules = { 'react/no-render-return-value': 'off', 'react/no-string-refs': 'off', 'react/void-dom-elements-no-children': 'off', + '@typescript-eslint/no-dupe-class-members': 'off', '@typescript-eslint/no-duplicate-enum-values': 'off', '@typescript-eslint/no-extra-non-null-assertion': 'off', + '@typescript-eslint/no-loss-of-precision': 'off', '@typescript-eslint/no-misused-new': 'off', '@typescript-eslint/no-non-null-asserted-optional-chain': 'off', '@typescript-eslint/no-this-alias': 'off', '@typescript-eslint/no-unsafe-declaration-merging': 'off', + '@typescript-eslint/no-unused-vars': 'off', '@typescript-eslint/no-useless-empty-export': 'off', '@typescript-eslint/no-wrapper-object-types': 'off', '@typescript-eslint/prefer-as-const': 'off', @@ -445,7 +445,6 @@ const suspiciousRules = { 'no-unexpected-multiline': 'off', 'no-useless-concat': 'off', 'no-useless-constructor': 'off', - '@typescript-eslint/no-useless-constructor': 'off', 'import/no-duplicates': 'off', 'import/no-named-as-default': 'off', 'import/no-named-as-default-member': 'off', @@ -458,6 +457,7 @@ const suspiciousRules = { '@typescript-eslint/no-confusing-non-null-assertion': 'off', '@typescript-eslint/no-extraneous-class': 'off', '@typescript-eslint/no-unnecessary-type-constraint': 'off', + '@typescript-eslint/no-useless-constructor': 'off', 'unicorn/consistent-function-scoping': 'off', 'unicorn/prefer-add-event-listener': 'off', } as const; diff --git a/src/generated/rules-by-scope.ts b/src/generated/rules-by-scope.ts index 00256be..0456f10 100644 --- a/src/generated/rules-by-scope.ts +++ b/src/generated/rules-by-scope.ts @@ -117,58 +117,6 @@ const eslintRules = { 'valid-typeof': 'off', } as const; -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-empty-object-type': '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-require-imports': 'off', - '@typescript-eslint/no-this-alias': 'off', - '@typescript-eslint/no-unnecessary-type-constraint': 'off', - '@typescript-eslint/no-unsafe-declaration-merging': 'off', - '@typescript-eslint/no-unsafe-function-type': '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', -} as const; - const importRules = { 'import/default': 'off', 'import/export': 'off', @@ -380,6 +328,58 @@ const reactPerfRules = { 'react-perf/jsx-no-new-object-as-prop': 'off', } as const; +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/default-param-last': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/max-params': 'off', + '@typescript-eslint/no-array-constructor': 'off', + '@typescript-eslint/no-confusing-non-null-assertion': 'off', + '@typescript-eslint/no-dupe-class-members': 'off', + '@typescript-eslint/no-duplicate-enum-values': 'off', + '@typescript-eslint/no-dynamic-delete': 'off', + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-empty-interface': 'off', + '@typescript-eslint/no-empty-object-type': '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-loss-of-precision': 'off', + '@typescript-eslint/no-magic-numbers': '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-redeclare': 'off', + '@typescript-eslint/no-require-imports': 'off', + '@typescript-eslint/no-this-alias': 'off', + '@typescript-eslint/no-unnecessary-type-constraint': 'off', + '@typescript-eslint/no-unsafe-declaration-merging': 'off', + '@typescript-eslint/no-unsafe-function-type': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-useless-constructor': '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', +} as const; + const unicornRules = { 'unicorn/catch-error-name': 'off', 'unicorn/consistent-empty-array-spread': 'off', @@ -485,7 +485,6 @@ const vitestRules = { export { eslintRules, - typescriptRules, importRules, jestRules, jsdocRules, @@ -496,6 +495,7 @@ export { reactRules, reactHooksRules, reactPerfRules, + typescriptRules, unicornRules, vitestRules, };