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 24, 2024
1 parent d43a81e commit a021951
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": ["eslint"],
"rules": {
"no-invalid-regexp": "off"
}
}
8 changes: 8 additions & 0 deletions src/__mocks__/oxlint-complex-plugin-active-rule-deactive.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"categories": {
"correctness": "error"
},
"rules": {
"no-invalid-regexp": "off"
}
}
24 changes: 24 additions & 0 deletions src/build-from-oxlint-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,27 @@ it('detects plugin and append its rules', () => {
// snapshot because it can change with the next release
expect(rules).toMatchSnapshot('detectPluginRules');
});

it('detects manually disabled rules, which are extended by category', () => {
const rules = buildFromOxlintConfig(
path.resolve(
import.meta.dirname,
'__mocks__',
'oxlint-complex-category-active-rule-deactive.json'
)
);

expect('no-invalid-regexp' in rules).toBe(false);
});

it('detects manually disabled rules, which are extended by plugin', () => {
const rules = buildFromOxlintConfig(
path.resolve(
import.meta.dirname,
'__mocks__',
'oxlint-complex-plugin-active-rule-deactive.json'
)
);

expect('no-invalid-regexp' in rules).toBe(false);
});
3 changes: 3 additions & 0 deletions src/build-from-oxlint-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const appendRulesScope = (
// is this rules not turned off
if (oxlintRules[rule] !== 'off') {
rules[rule] = 'off';
} else {
// rules extended by categories or plugins can be disabled manually
delete rules[rule];
}
}
};
Expand Down

0 comments on commit a021951

Please sign in to comment.