Skip to content

Commit

Permalink
feat(build): output rules for flat config in dts file
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Oct 14, 2024
1 parent fe61c85 commit 309f4e3
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 153 deletions.
8 changes: 4 additions & 4 deletions scripts/__snapshots__/rules-generator.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ exports[`RulesGenerator > RulesGenerator generates rules correctly > byCategory
const styleRules = {
'rulename-with-mod': "off"
} as const
} as const;
const correctnessRules = {
'@typescript-eslint/rulename-without-mod': "off"
} as const
} as const;
export {
styleRules,
Expand All @@ -22,11 +22,11 @@ exports[`RulesGenerator > RulesGenerator generates rules correctly > byScope 1`]
const eslintRules = {
'rulename-with-mod': "off"
} as const
} as const;
const typescriptRules = {
'@typescript-eslint/rulename-without-mod': "off"
} as const
} as const;
export {
eslintRules,
Expand Down
17 changes: 10 additions & 7 deletions scripts/config-generator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFileSync } from 'node:fs';
import path from 'node:path';
import type { Rule } from './traverse-rules.js';
import { camelCase, kebabCase } from 'scule';
import { camelCase, kebabCase, pascalCase } from 'scule';

const __dirname = new URL('.', import.meta.url).pathname;

Expand Down Expand Up @@ -54,6 +54,7 @@ export class ConfigGenerator {
const rulesArray = this.rulesArray;

const rulesMap = this.groupItemsBy(rulesArray, rulesGrouping);
const exportName = pascalCase(this.rulesGrouping);

const exportGrouping: string[] = [];
let code =
Expand All @@ -66,18 +67,20 @@ export class ConfigGenerator {

code += `const ${camelCase(grouping)}Config = {\n`;

code += `\tname: 'oxlint/${kebabCase(grouping)}',\n`;
code += `\trules: rules.${camelCase(grouping)}Rules,`;
code += '\n} as const;\n\n';
code += ` name: 'oxlint/${kebabCase(grouping)}',\n`;
code += ` rules: rules.${camelCase(grouping)}Rules,`;
code += '\n};\n\n';
}

code += 'export {\n';
code += `const configBy${exportName} = {\n`;
code += exportGrouping
.map((grouping) => {
return `\t${camelCase(grouping)}Config as "flat/${kebabCase(grouping)}"`;
return ` 'flat/${kebabCase(grouping)}': ${camelCase(grouping)}Config`;
})
.join(',\n');
code += '\n}';
code += '\n}\n\n';

code += `export default configBy${exportName}`;

return code;
}
Expand Down
146 changes: 74 additions & 72 deletions src/configs-by-category.ts
Original file line number Diff line number Diff line change
@@ -1,108 +1,110 @@
// These rules are automatically generated by scripts/generate-rules.ts

import * as rules from "./rules-by-category.js";
import * as rules from './rules-by-category.js';

const pedanticConfig = {
name: 'oxlint/pedantic',
rules: rules.pedanticRules,
} as const;
name: 'oxlint/pedantic',
rules: rules.pedanticRules,
};

const nurseryConfig = {
name: 'oxlint/nursery',
rules: rules.nurseryRules,
} as const;
name: 'oxlint/nursery',
rules: rules.nurseryRules,
};

const restrictionConfig = {
name: 'oxlint/restriction',
rules: rules.restrictionRules,
} as const;
name: 'oxlint/restriction',
rules: rules.restrictionRules,
};

const styleConfig = {
name: 'oxlint/style',
rules: rules.styleRules,
} as const;
name: 'oxlint/style',
rules: rules.styleRules,
};

const conditionalFixConfig = {
name: 'oxlint/conditional-fix',
rules: rules.conditionalFixRules,
} as const;
name: 'oxlint/conditional-fix',
rules: rules.conditionalFixRules,
};

const dangerousFixConfig = {
name: 'oxlint/dangerous-fix',
rules: rules.dangerousFixRules,
} as const;
name: 'oxlint/dangerous-fix',
rules: rules.dangerousFixRules,
};

const conditionalFixSuggestionConfig = {
name: 'oxlint/conditional-fix-suggestion',
rules: rules.conditionalFixSuggestionRules,
} as const;
name: 'oxlint/conditional-fix-suggestion',
rules: rules.conditionalFixSuggestionRules,
};

const pendingConfig = {
name: 'oxlint/pending',
rules: rules.pendingRules,
} as const;
name: 'oxlint/pending',
rules: rules.pendingRules,
};

const correctnessConfig = {
name: 'oxlint/correctness',
rules: rules.correctnessRules,
} as const;
name: 'oxlint/correctness',
rules: rules.correctnessRules,
};

const perfConfig = {
name: 'oxlint/perf',
rules: rules.perfRules,
} as const;
name: 'oxlint/perf',
rules: rules.perfRules,
};

const conditionalSuggestionFixConfig = {
name: 'oxlint/conditional-suggestion-fix',
rules: rules.conditionalSuggestionFixRules,
} as const;
name: 'oxlint/conditional-suggestion-fix',
rules: rules.conditionalSuggestionFixRules,
};

const fixConfig = {
name: 'oxlint/fix',
rules: rules.fixRules,
} as const;
name: 'oxlint/fix',
rules: rules.fixRules,
};

const suggestionConfig = {
name: 'oxlint/suggestion',
rules: rules.suggestionRules,
} as const;
name: 'oxlint/suggestion',
rules: rules.suggestionRules,
};

const fixDangerousConfig = {
name: 'oxlint/fix-dangerous',
rules: rules.fixDangerousRules,
} as const;
name: 'oxlint/fix-dangerous',
rules: rules.fixDangerousRules,
};

const suspiciousConfig = {
name: 'oxlint/suspicious',
rules: rules.suspiciousRules,
} as const;
name: 'oxlint/suspicious',
rules: rules.suspiciousRules,
};

const conditionalSuggestionConfig = {
name: 'oxlint/conditional-suggestion',
rules: rules.conditionalSuggestionRules,
} as const;
name: 'oxlint/conditional-suggestion',
rules: rules.conditionalSuggestionRules,
};

const dangerousSuggestionConfig = {
name: 'oxlint/dangerous-suggestion',
rules: rules.dangerousSuggestionRules,
} as const;

export {
pedanticConfig as "flat/pedantic",
nurseryConfig as "flat/nursery",
restrictionConfig as "flat/restriction",
styleConfig as "flat/style",
conditionalFixConfig as "flat/conditional-fix",
dangerousFixConfig as "flat/dangerous-fix",
conditionalFixSuggestionConfig as "flat/conditional-fix-suggestion",
pendingConfig as "flat/pending",
correctnessConfig as "flat/correctness",
perfConfig as "flat/perf",
conditionalSuggestionFixConfig as "flat/conditional-suggestion-fix",
fixConfig as "flat/fix",
suggestionConfig as "flat/suggestion",
fixDangerousConfig as "flat/fix-dangerous",
suspiciousConfig as "flat/suspicious",
conditionalSuggestionConfig as "flat/conditional-suggestion",
dangerousSuggestionConfig as "flat/dangerous-suggestion"
}
name: 'oxlint/dangerous-suggestion',
rules: rules.dangerousSuggestionRules,
};

const configByCategory = {
'flat/pedantic': pedanticConfig,
'flat/nursery': nurseryConfig,
'flat/restriction': restrictionConfig,
'flat/style': styleConfig,
'flat/conditional-fix': conditionalFixConfig,
'flat/dangerous-fix': dangerousFixConfig,
'flat/conditional-fix-suggestion': conditionalFixSuggestionConfig,
'flat/pending': pendingConfig,
'flat/correctness': correctnessConfig,
'flat/perf': perfConfig,
'flat/conditional-suggestion-fix': conditionalSuggestionFixConfig,
'flat/fix': fixConfig,
'flat/suggestion': suggestionConfig,
'flat/fix-dangerous': fixDangerousConfig,
'flat/suspicious': suspiciousConfig,
'flat/conditional-suggestion': conditionalSuggestionConfig,
'flat/dangerous-suggestion': dangerousSuggestionConfig,
};

export default configByCategory;
Loading

0 comments on commit 309f4e3

Please sign in to comment.