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 25, 2024
1 parent 0cecffe commit d3dc1fa
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 17 deletions.
72 changes: 72 additions & 0 deletions src/__snapshots__/build-from-oxlint-config.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,42 @@ exports[`custom plugins, custom categories > customPluginCustomCategories 1`] =

exports[`custom plugins, default categories > customPluginDefaultCategories 1`] = `
{
"no-async-promise-executor": "off",
"no-caller": "off",
"no-class-assign": "off",
"no-cond-assign": "off",
"no-const-assign": "off",
"no-constant-binary-expression": "off",
"no-constant-condition": "off",
"no-control-regex": "off",
"no-delete-var": "off",
"no-dupe-class-members": "off",
"no-dupe-else-if": "off",
"no-dupe-keys": "off",
"no-duplicate-case": "off",
"no-empty-character-class": "off",
"no-empty-pattern": "off",
"no-ex-assign": "off",
"no-func-assign": "off",
"no-global-assign": "off",
"no-import-assign": "off",
"no-invalid-regexp": "off",
"no-irregular-whitespace": "off",
"no-loss-of-precision": "off",
"no-new-native-nonconstructor": "off",
"no-obj-calls": "off",
"no-self-assign": "off",
"no-setter-return": "off",
"no-shadow-restricted-names": "off",
"no-sparse-arrays": "off",
"no-this-before-super": "off",
"no-unsafe-finally": "off",
"no-unsafe-optional-chaining": "off",
"no-unused-private-class-members": "off",
"no-useless-catch": "off",
"no-useless-rename": "off",
"no-with": "off",
"require-yield": "off",
"unicorn/no-await-in-promise-methods": "off",
"unicorn/no-document-cookie": "off",
"unicorn/no-empty-file": "off",
Expand All @@ -27,6 +63,41 @@ exports[`default plugins (react, unicorn, typescript), default categories > defa
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-unsafe-declaration-merging": "off",
"@typescript-eslint/triple-slash-reference": "off",
"no-async-promise-executor": "off",
"no-caller": "off",
"no-class-assign": "off",
"no-cond-assign": "off",
"no-const-assign": "off",
"no-constant-binary-expression": "off",
"no-constant-condition": "off",
"no-control-regex": "off",
"no-delete-var": "off",
"no-dupe-class-members": "off",
"no-dupe-else-if": "off",
"no-dupe-keys": "off",
"no-duplicate-case": "off",
"no-empty-character-class": "off",
"no-empty-pattern": "off",
"no-ex-assign": "off",
"no-func-assign": "off",
"no-global-assign": "off",
"no-import-assign": "off",
"no-invalid-regexp": "off",
"no-irregular-whitespace": "off",
"no-loss-of-precision": "off",
"no-new-native-nonconstructor": "off",
"no-obj-calls": "off",
"no-self-assign": "off",
"no-setter-return": "off",
"no-shadow-restricted-names": "off",
"no-sparse-arrays": "off",
"no-this-before-super": "off",
"no-unsafe-finally": "off",
"no-unsafe-optional-chaining": "off",
"no-unused-private-class-members": "off",
"no-useless-catch": "off",
"no-useless-rename": "off",
"no-with": "off",
"react/jsx-key": "off",
"react/jsx-no-duplicate-props": "off",
"react/jsx-no-target-blank": "off",
Expand All @@ -39,6 +110,7 @@ exports[`default plugins (react, unicorn, typescript), default categories > defa
"react/no-render-return-value": "off",
"react/no-string-refs": "off",
"react/void-dom-elements-no-children": "off",
"require-yield": "off",
"unicorn/no-await-in-promise-methods": "off",
"unicorn/no-document-cookie": "off",
"unicorn/no-empty-file": "off",
Expand Down
33 changes: 16 additions & 17 deletions src/build-from-oxlint-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@ import { buildFromObject } from './build-from-oxlint-config.js';
it('detect active rules inside "rules" scope', () => {
['error', ['error'], 'warn', ['warn'], 1, [1], 2, [2]].forEach(
(ruleSetting) => {
expect(
buildFromObject({
plugins: [],
rules: {
eqeqeq: ruleSetting,
},
})
).toStrictEqual({
eqeqeq: 'off',
const rules = buildFromObject({
plugins: [],
rules: {
eqeqeq: ruleSetting,
},
});

expect('eqeqeq' in rules).toBe(true);
expect(rules.eqeqeq).toBe('off');
}
);
});

it('skip deactive rules inside "rules" scope', () => {
['off', ['off'], 0, [0]].forEach((ruleSetting) => {
expect(
buildFromObject({
plugins: [],
rules: {
eqeqeq: ruleSetting,
},
})
).toStrictEqual({});
const rules = buildFromObject({
plugins: [],
rules: {
eqeqeq: ruleSetting,
},
});

expect('eqeqeq' in rules).toBe(false);
});
});

Expand Down
3 changes: 3 additions & 0 deletions src/build-from-oxlint-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export const buildFromObject = (
const rules: Record<string, 'off'> = {};
const plugins = readPluginsFromConfig(config);

// it is not a plugin but it is activated by default
plugins.push('eslint');

if (
'categories' in config &&
typeof config.categories === 'object' &&
Expand Down

0 comments on commit d3dc1fa

Please sign in to comment.