Skip to content

Commit

Permalink
feat: add buildFromOxlintConfigFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Oct 30, 2024
1 parent e300732 commit 1d54fea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ export default [
];
```

Or build it by an `oxlint.json`-like object:

```js
// eslint.config.js
import { buildFromOxlintConfig } from 'eslint-plugin-oxlint';
export default [
..., // other plugins
...buildFromOxlintConfig({
categories: {
correctness: 'warn'
},
rules: {
eqeqeq: 'warn'
}
}),
];
```

`buildFromOxlintConfigFile` is not supported for legacy configuration (eslint < 9.0).

### Run it before eslint
Expand Down
10 changes: 5 additions & 5 deletions src/build-from-oxlint-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('buildFromOxlintConfig', () => {
});
});

it('skip deactive categories', () => {
it('skip deactivate categories', () => {
expect(
buildFromOxlintConfig({
categories: {
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('buildFromOxlintConfig', () => {
).toMatchSnapshot('customPluginCustomCategories');
});

it('skip deactive rules, for custom enable category', () => {
it('skip deactivate rules, for custom enable category', () => {
const rules = buildFromOxlintConfig({
plugins: ['import'],
categories: {
Expand Down Expand Up @@ -245,7 +245,7 @@ describe('integration test with oxlint', () => {
// combination plugin + rule
{ plugins: ['vite'], rules: { eqeqeq: 'off' } },

// categorie change
// categories change
{ categories: { correctness: 'off', nusery: 'warn' } },
// combination plugin + categires + rules
{
Expand All @@ -257,7 +257,7 @@ describe('integration test with oxlint', () => {
{
categories: {
correctness: 'warn',
nursery: 'off', // enable ofter oxc-project/oxc#7073
nursery: 'off', // enable after oxc-project/oxc#7073
pedantic: 'warn',
perf: 'warn',
restriction: 'warn',
Expand Down Expand Up @@ -302,7 +302,7 @@ describe('integration test with oxlint', () => {
],
categories: {
correctness: 'warn',
nursery: 'off', // enable ofter oxc-project/oxc#7073
nursery: 'off', // enable after oxc-project/oxc#7073
pedantic: 'warn',
perf: 'warn',
restriction: 'warn',
Expand Down
8 changes: 4 additions & 4 deletions src/build-from-oxlint-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const defaultPlugins: OxlintConfigPlugins = ['react', 'unicorn', 'typescript'];
const defaultCategories: OxlintConfigCategories = { correctness: 'warn' };

/**
* tries to ried the oxlint config file and returning its JSON content.
* tries to read the oxlint config file and returning its JSON content.
* if the file is not found or could not be parsed, undefined is returned.
* And an error message will be emitted to `console.error`
*/
Expand Down Expand Up @@ -114,7 +114,7 @@ const handleRulesScope = (
// is this rules not turned off
if (isActiveValue(oxlintRules[rule])) {
rules[rule] = 'off';
} else if (rule in rules && isDeactiveValue(oxlintRules[rule])) {
} else if (rule in rules && isDeactivateValue(oxlintRules[rule])) {
// rules extended by categories or plugins can be disabled manually
delete rules[rule];
}
Expand All @@ -124,7 +124,7 @@ const handleRulesScope = (
/**
* check if the value is "off", 0, ["off", ...], or [0, ...]
*/
const isDeactiveValue = (value: unknown): boolean => {
const isDeactivateValue = (value: unknown): boolean => {
const isOff = (value: unknown) => value === 'off' || value === 0;

return isOff(value) || (Array.isArray(value) && isOff(value[0]));
Expand Down Expand Up @@ -182,7 +182,7 @@ const readRulesFromConfig = (

/**
* builds turned off rules, which are supported by oxlint.
* It accepts an object similiar to the oxlint.json file.
* It accepts an object similar to the oxlint.json file.
*/
export const buildFromOxlintConfig = (
config: OxlintConfig
Expand Down

0 comments on commit 1d54fea

Please sign in to comment.