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 30, 2024
1 parent ae5ccbc commit b1b3df5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@
},
"volta": {
"node": "20.14.0"
},
"dependencies": {
"jsonc-parser": "^3.3.1"
}
}
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

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

13 changes: 6 additions & 7 deletions src/build-from-oxlint-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ const createConfigFileAndBuildFromIt = (
};

describe('buildFromOxlintConfigFile', () => {
it('successfully parse oxlint config', () => {
it('successfully parse oxlint json config', () => {
const rules = createConfigFileAndBuildFromIt(
'success-config.json',
JSON.stringify({
rules: {
'no-await-loop': 'error',
`{
"rules": {
// hello world
"no-await-loop": "error",
},
})
}`
);

expect(rules.length).toBe(1);
Expand Down Expand Up @@ -317,8 +318,6 @@ describe('integration test with oxlint', () => {
expect(eslintRules.length).toBe(1);
expect(eslintRules[0].rules).not.toBeUndefined();

console.log(eslintRules[0].rules!);

let expectedCount = oxlintRulesCount ?? 0;

// special mapping for ts alias rules
Expand Down
5 changes: 3 additions & 2 deletions src/build-from-oxlint-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'node:fs';
import configByCategory from './configs-by-category.js';
import type { Linter } from 'eslint';
import JSONCParser from 'jsonc-parser';

// these are the mappings from the scope in the rules.rs to the eslint scope
// only used for the scopes where the directory structure doesn't reflect the eslint scope
Expand Down Expand Up @@ -41,10 +42,10 @@ const getConfigContent = (
oxlintConfigFile: string
): OxlintConfig | undefined => {
try {
const buffer = fs.readFileSync(oxlintConfigFile, 'utf8');
const content = fs.readFileSync(oxlintConfigFile, 'utf8');

try {
const configContent = JSON.parse(buffer);
const configContent = JSONCParser.parse(content);

if (typeof configContent !== 'object' || Array.isArray(configContent)) {
throw new TypeError('not an valid config file');
Expand Down

0 comments on commit b1b3df5

Please sign in to comment.