Skip to content

Commit

Permalink
feat: add buildFromOxlintConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Oct 26, 2024
1 parent d3dc1fa commit caf5f58
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions scripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const ignoreScope = new Set(['oxc', 'deepscan', 'security']);
// only used for the scopes where the directory structure doesn't reflect the eslint scope
// such as `typescript` vs `@typescript-eslint` or others. Eslint as a scope is an exception,
// as eslint doesn't have a scope.
// There is a duplicate in src/build-from-oxlint-config.ts, for clean builds we manage it in 2 files.
// In the future we can generate maybe this constant into src folder
export const scopeMaps = {
eslint: '',
typescript: '@typescript-eslint',
Expand Down
13 changes: 11 additions & 2 deletions src/build-from-oxlint-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import fs from 'node:fs';
import configByCategory from './configs-by-category.js';
import { scopeMaps } from '../scripts/constants.js';

// these are the mappings from the scope in the rules.rs to the eslint scope
// only used for the scopes where the directory structure doesn't reflect the eslint scope
// such as `typescript` vs `@typescript-eslint` or others. Eslint as a scope is an exception,
// as eslint doesn't have a scope.
// There is a duplicate in scripts/constants.js, for clean builds we manage it in 2 files.
// In the future we can generate maybe this constant into src folder
const scopeMaps = {
eslint: '',
typescript: '@typescript-eslint',
};

const getConfigContent = (
oxlintConfigFile: string
Expand Down Expand Up @@ -49,7 +59,6 @@ const appendCategoriesScope = (
const pluginPrefix = plugin in scopeMaps ? scopeMaps[plugin] : plugin;

// the rule has no prefix, so it is a eslint one

if (pluginPrefix === '' && !rule.includes('/')) {
rules[rule] = 'off';
// other rules with a prefix like @typescript-eslint/
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as ruleMapsByScope from './rules-by-scope.js';
import * as ruleMapsByCategory from './rules-by-category.js';
import configByScope from './configs-by-scope.js';
import configByCategory from './configs-by-category.js';

import * as build from './build-from-oxlint-config.js';
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
x: infer I
) => void
Expand All @@ -17,6 +17,9 @@ const allRules: UnionToIntersection<AllRules> = Object.assign(
...Object.values(ruleMapsByScope)
);

export const buildFromOxlintConfigFile = build.default;
export const buildFromOxlintConfig = build.buildFromObject;

export default {
configs: {
recommended: {
Expand Down

0 comments on commit caf5f58

Please sign in to comment.