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 28, 2024
1 parent 17101d0 commit 06952e7
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions src/build-from-oxlint-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
buildFromOxlintConfigFile,
} from './build-from-oxlint-config.js';
import fs from 'node:fs';
import { execSync } from 'node:child_process';

describe('buildFromOxlintConfig', () => {
describe('rules values', () => {
Expand Down Expand Up @@ -153,3 +154,101 @@ describe('buildFromOxlintConfigFile', () => {
expect(rules).toStrictEqual({});
});
});

const executeOxlintWithConfiguration = (filename: string, content: string) => {
fs.writeFileSync(filename, content);
let oxlintOutput: string;

try {
// --disabled-<foo>-plugin can be disabled after oxc-project/oxc#6896
oxlintOutput = execSync(
`npx oxlint -c ${filename} --disable-oxc-plugin --disable-typescript-plugin --disable-unicorn-plugin --disable-react-plugin`,
{
encoding: 'utf-8',
}
);
} catch {
oxlintOutput = '';
}

fs.unlinkSync(filename);

const result = /with\s(\d+)\srules/.exec(oxlintOutput);

if (result === null) {
return undefined;
}

return parseInt(result[1], 10) ?? undefined;
};

describe('integration test with oxlint', () => {
[
// default
// {}, can be enabled after oxc-project/oxc#6896
// no plugins
{ plugins: [] },
// simple plugin override
{ plugins: ['vite'] },
// custom rule off
{
plugins: [] /** can be removed after oxc-project/oxc#6896 */,
rules: { eqeqeq: 'off' },
},
// combination plugin + rule
{ plugins: ['vite'], rules: { eqeqeq: 'off' } },
// combination plugin + categires + rules
{
plugins: ['vite'],
categories: { correctness: 'off', style: 'warn' },
rules: { eqeqeq: 'off' },
},
// all categories enabled
{
plugins: [] /** can be removed after oxc-project/oxc#6896 */,
categories: {
correctness: 'warn',
nursery: 'warn',
pedantic: 'warn',
perf: 'warn',
restriction: 'warn',
style: 'warn',
suspicious: 'warn',
},
},
// all plugins enabled
{
plugins: [
// can be removed after oxc-project/oxc#6896
// 'typescript',
// 'unicorn',
// 'react',
'react-perf',
'nextjs',
'import',
'jsdoc',
'jsx-a11y',
'n',
'promise',
'jest',
'vitest',
],
},
].forEach((json, index) => {
const fileContent = JSON.stringify(json);

it(`should output same rule count for: ${fileContent}`, () => {
const oxlintRulesCount = executeOxlintWithConfiguration(
`integration-test-${index}-oxlint.json`,
fileContent
);

const eslintRules = createConfigFileAndBuildFromIt(
`integration-test-${index}-eslint.json`,
fileContent
);

expect(Object.keys(eslintRules).length).toBe(oxlintRulesCount);
});
});
});

0 comments on commit 06952e7

Please sign in to comment.