Skip to content

Commit

Permalink
build improve traverse-rules performance and order them
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Nov 11, 2024
1 parent 4769da9 commit 2ee0ec3
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 86 deletions.
53 changes: 34 additions & 19 deletions scripts/traverse-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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`
);
Expand Down
12 changes: 6 additions & 6 deletions src/generated/configs-by-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -67,6 +62,11 @@ const treeShakingConfig = {
rules: rules.treeShakingRules,
};

const typescriptConfig = {
name: 'oxlint/typescript',
rules: rules.typescriptRules,
};

const unicornConfig = {
name: 'oxlint/unicorn',
rules: rules.unicornRules,
Expand All @@ -79,7 +79,6 @@ const vitestConfig = {

const configByScope = {
'flat/eslint': eslintConfig,
'flat/typescript': typescriptConfig,
'flat/import': importConfig,
'flat/jest': jestConfig,
'flat/jsdoc': jsdocConfig,
Expand All @@ -91,6 +90,7 @@ const configByScope = {
'flat/react-hooks': reactHooksConfig,
'flat/react-perf': reactPerfConfig,
'flat/tree-shaking': treeShakingConfig,
'flat/typescript': typescriptConfig,
'flat/unicorn': unicornConfig,
'flat/vitest': vitestConfig,
};
Expand Down
20 changes: 10 additions & 10 deletions src/generated/rules-by-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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-explicit-any': 'off',
'@typescript-eslint/no-import-type-side-effects': 'off',
'@typescript-eslint/no-namespace': 'off',
Expand All @@ -153,15 +153,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',
Expand Down Expand Up @@ -225,7 +222,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',
Expand Down Expand Up @@ -275,7 +275,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',
Expand All @@ -290,7 +289,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',
Expand All @@ -305,7 +303,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',
Expand Down Expand Up @@ -398,12 +395,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',
Expand Down Expand Up @@ -439,7 +439,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',
Expand All @@ -452,6 +451,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;
Expand Down
102 changes: 51 additions & 51 deletions src/generated/rules-by-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,56 +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-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-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',
Expand Down Expand Up @@ -379,6 +329,56 @@ const treeShakingRules = {
'tree-shaking/no-side-effects-in-initialization': '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-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-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',
Expand Down Expand Up @@ -482,7 +482,6 @@ const vitestRules = {

export {
eslintRules,
typescriptRules,
importRules,
jestRules,
jsdocRules,
Expand All @@ -494,6 +493,7 @@ export {
reactHooksRules,
reactPerfRules,
treeShakingRules,
typescriptRules,
unicornRules,
vitestRules,
};

0 comments on commit 2ee0ec3

Please sign in to comment.