Skip to content

Commit

Permalink
Merge branch 'main' into fix-sync-jest-and-vitest-compatible-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Dec 6, 2024
2 parents 7e1e9e8 + 9bf4277 commit 3e295bb
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 48 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-oxlint",
"version": "0.14.0",
"version": "0.14.1",
"description": "Turn off all rules already supported by oxlint",
"type": "module",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -66,7 +66,7 @@
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"memfs": "^4.14.0",
"oxlint": "^0.14.0",
"oxlint": "^0.14.1",
"prettier": "^3.3.3",
"scule": "^1.3.0",
"shelljs": "^0.8.5",
Expand Down
74 changes: 37 additions & 37 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/__snapshots__/configs.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,15 @@ exports[`contains all the oxlint rules 1`] = `
"disallowArithmeticOperators": false,
},
],
"no-unused-expressions": [
0,
{
"allowShortCircuit": false,
"allowTaggedTemplates": false,
"allowTernary": false,
"enforceForJSX": false,
},
],
"no-unused-labels": [
0,
],
Expand Down Expand Up @@ -979,6 +988,9 @@ exports[`contains all the oxlint rules 1`] = `
0,
"always",
],
"react-hooks/rules-of-hooks": [
0,
],
"react-perf/jsx-no-jsx-as-prop": [
0,
],
Expand Down Expand Up @@ -1475,5 +1487,13 @@ exports[`contains all the oxlint rules 1`] = `
"vitest/valid-expect": [
0,
],
"yoda": [
0,
"never",
{
"exceptRange": false,
"onlyEquality": false,
},
],
}
`;
11 changes: 11 additions & 0 deletions src/build-from-oxlint-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ describe('buildFromOxlintConfig', () => {
}
});
}

describe('ignorePattern Property', () => {
it('should append ignorePatterns to eslint v9 ignore property', () => {
const configs = buildFromOxlintConfig({
ignorePatterns: ['./tests/.*ts'],
});

expect(configs.length).toBe(1);
expect(configs[0].ignores).toStrictEqual(['./tests/.*ts']);
});
});
});

const createConfigFileAndBuildFromIt = (
Expand Down
26 changes: 26 additions & 0 deletions src/build-from-oxlint-config/ignore-patterns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
EslintPluginOxlintConfig,
OxlintConfig,
OxlintConfigIgnorePatterns,
} from './types.js';

/**
* adds the ignore patterns to the config
*/
export const handleIgnorePatternsScope = (
ignorePatterns: OxlintConfigIgnorePatterns,
config: EslintPluginOxlintConfig
): void => {
config.ignores = ignorePatterns;
};
/**
* tries to return the "ignorePattern" section from the config.
* it returns `undefined` when not found or invalid.
*/
export const readIgnorePatternsFromConfig = (
config: OxlintConfig
): OxlintConfigIgnorePatterns | undefined => {
return 'ignorePatterns' in config && Array.isArray(config.ignorePatterns)
? (config.ignorePatterns as OxlintConfigIgnorePatterns)
: undefined;
};
28 changes: 19 additions & 9 deletions src/build-from-oxlint-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs';
import type { Linter } from 'eslint';
import JSONCParser from 'jsonc-parser';
import {
EslintPluginOxlintConfig,
OxlintConfig,
OxlintConfigCategories,
OxlintConfigPlugins,
Expand All @@ -13,6 +13,10 @@ import {
readCategoriesFromConfig,
} from './categories.js';
import { readPluginsFromConfig } from './plugins.js';
import {
handleIgnorePatternsScope,
readIgnorePatternsFromConfig,
} from './ignore-patterns.js';

// default plugins, see <https://oxc.rs/docs/guide/usage/linter/config#plugins>
const defaultPlugins: OxlintConfigPlugins = ['react', 'unicorn', 'typescript'];
Expand Down Expand Up @@ -59,7 +63,7 @@ const getConfigContent = (
*/
export const buildFromOxlintConfig = (
config: OxlintConfig
): Linter.Config<Record<string, 'off'>>[] => {
): EslintPluginOxlintConfig[] => {
const rules: Record<string, 'off'> = {};
const plugins = readPluginsFromConfig(config) ?? defaultPlugins;

Expand All @@ -84,12 +88,18 @@ export const buildFromOxlintConfig = (
handleRulesScope(configRules, rules);
}

return [
{
name: 'oxlint/from-oxlint-config',
rules,
},
];
const baseConfig = {
name: 'oxlint/from-oxlint-config',
rules,
};

const ignorePatterns = readIgnorePatternsFromConfig(config);

if (ignorePatterns !== undefined) {
handleIgnorePatternsScope(ignorePatterns, baseConfig);
}

return [baseConfig];
};

/**
Expand All @@ -101,7 +111,7 @@ export const buildFromOxlintConfig = (
*/
export const buildFromOxlintConfigFile = (
oxlintConfigFile: string
): Linter.Config<Record<string, 'off'>>[] => {
): EslintPluginOxlintConfig[] => {
const config = getConfigContent(oxlintConfigFile);

// we could not parse form the file, do not build with default values
Expand Down
7 changes: 7 additions & 0 deletions src/build-from-oxlint-config/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import type { Linter } from 'eslint';

export type OxlintConfigPlugins = string[];

export type OxlintConfigCategories = Record<string, unknown>;

export type OxlintConfigRules = Record<string, unknown>;

export type OxlintConfigIgnorePatterns = string[];

export type EslintPluginOxlintConfig = Linter.Config<Record<string, 'off'>>;

export type OxlintConfig = {
[key: string]: unknown;
plugins?: OxlintConfigPlugins;
categories?: OxlintConfigCategories;
rules?: OxlintConfigRules;
ignorePatterns?: OxlintConfigIgnorePatterns;
};
6 changes: 6 additions & 0 deletions src/generated/configs-by-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const reactConfig = {
rules: rules.reactRules,
};

const reactHooksConfig = {
name: 'oxlint/react-hooks',
rules: rules.reactHooksRules,
};

const reactPerfConfig = {
name: 'oxlint/react-perf',
rules: rules.reactPerfRules,
Expand Down Expand Up @@ -77,6 +82,7 @@ const configByScope = {
'flat/node': nodeConfig,
'flat/promise': promiseConfig,
'flat/react': reactConfig,
'flat/react-hooks': reactHooksConfig,
'flat/react-perf': reactPerfConfig,
'flat/typescript': typescriptConfig,
'flat/unicorn': unicornConfig,
Expand Down
3 changes: 3 additions & 0 deletions src/generated/rules-by-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const pedanticRules = {
'react/checked-requires-onchange-or-readonly': 'off',
'react/jsx-no-useless-fragment': 'off',
'react/no-unescaped-entities': 'off',
'react-hooks/rules-of-hooks': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-array-constructor': 'off',
Expand Down Expand Up @@ -96,6 +97,7 @@ const restrictionRules = {
'no-regex-spaces': 'off',
'no-restricted-globals': 'off',
'no-undefined': 'off',
'no-unused-expressions': 'off',
'no-var': 'off',
'no-void': 'off',
'unicode-bom': 'off',
Expand Down Expand Up @@ -163,6 +165,7 @@ const styleRules = {
'prefer-spread': 'off',
'sort-imports': 'off',
'sort-keys': 'off',
yoda: 'off',
'import/first': 'off',
'import/no-namespace': 'off',
'jest/consistent-test-it': 'off',
Expand Down
Loading

0 comments on commit 3e295bb

Please sign in to comment.