-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
143 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,130 @@ | ||
import { expect, it } from 'vitest'; | ||
import { buildFromObject } from './build-from-oxlint-config.js'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { | ||
buildFromOxlintConfig, | ||
buildFromOxlintConfigFile, | ||
} from './build-from-oxlint-config.js'; | ||
import fs from 'node:fs'; | ||
|
||
it('detect active rules inside "rules" scope', () => { | ||
['error', ['error'], 'warn', ['warn'], 1, [1], 2, [2]].forEach( | ||
(ruleSetting) => { | ||
const rules = buildFromObject({ | ||
describe('buildFromOxlintConfig', () => { | ||
it('detect active rules inside "rules" scope', () => { | ||
['error', ['error'], 'warn', ['warn'], 1, [1], 2, [2]].forEach( | ||
(ruleSetting) => { | ||
const rules = buildFromOxlintConfig({ | ||
plugins: [], | ||
rules: { | ||
eqeqeq: ruleSetting, | ||
}, | ||
}); | ||
|
||
expect('eqeqeq' in rules).toBe(true); | ||
expect(rules.eqeqeq).toBe('off'); | ||
} | ||
); | ||
}); | ||
|
||
it('skip deactive rules inside "rules" scope', () => { | ||
['off', ['off'], 0, [0]].forEach((ruleSetting) => { | ||
const rules = buildFromOxlintConfig({ | ||
plugins: [], | ||
rules: { | ||
eqeqeq: ruleSetting, | ||
}, | ||
}); | ||
|
||
expect('eqeqeq' in rules).toBe(true); | ||
expect(rules.eqeqeq).toBe('off'); | ||
} | ||
); | ||
}); | ||
|
||
it('skip deactive rules inside "rules" scope', () => { | ||
['off', ['off'], 0, [0]].forEach((ruleSetting) => { | ||
const rules = buildFromObject({ | ||
plugins: [], | ||
rules: { | ||
eqeqeq: ruleSetting, | ||
}, | ||
expect('eqeqeq' in rules).toBe(false); | ||
}); | ||
}); | ||
|
||
it('skip deactive categories', () => { | ||
expect( | ||
buildFromOxlintConfig({ | ||
categories: { | ||
correctness: 'off', | ||
}, | ||
}) | ||
).toStrictEqual({}); | ||
}); | ||
|
||
expect('eqeqeq' in rules).toBe(false); | ||
it('default plugins (react, unicorn, typescript), default categories', () => { | ||
// snapshot because it can change with the next release | ||
expect(buildFromOxlintConfig({})).toMatchSnapshot( | ||
'defaultPluginDefaultCategories' | ||
); | ||
}); | ||
|
||
it('custom plugins, default categories', () => { | ||
// snapshot because it can change with the next release | ||
expect( | ||
buildFromOxlintConfig({ | ||
plugins: ['unicorn'], | ||
}) | ||
).toMatchSnapshot('customPluginDefaultCategories'); | ||
}); | ||
}); | ||
|
||
it('skip deactive categories', () => { | ||
expect( | ||
buildFromObject({ | ||
it('custom plugins, custom categories', () => { | ||
// snapshot because it can change with the next release | ||
expect( | ||
buildFromOxlintConfig({ | ||
plugins: ['import'], | ||
categories: { | ||
nursery: 'warn', | ||
correctness: 'off', | ||
}, | ||
}) | ||
).toMatchSnapshot('customPluginCustomCategories'); | ||
}); | ||
|
||
it('skip deactive rules, for custom enable category', () => { | ||
const rules = buildFromOxlintConfig({ | ||
plugins: ['import'], | ||
categories: { | ||
nursery: 'warn', | ||
correctness: 'off', | ||
}, | ||
}) | ||
).toStrictEqual({}); | ||
rules: { | ||
'import/no-unused-modules': 'off', | ||
}, | ||
}); | ||
expect('import/no-unused-modules' in rules).toBe(false); | ||
}); | ||
}); | ||
|
||
it('default plugins (react, unicorn, typescript), default categories', () => { | ||
// snapshot because it can change with the next release | ||
expect(buildFromObject({})).toMatchSnapshot('defaultPluginDefaultCategories'); | ||
}); | ||
const createConfigFileAndBuildFromIt = ( | ||
filename: string, | ||
content: unknown | ||
): Record<string, unknown> => { | ||
fs.writeFileSync(filename, JSON.stringify(content)); | ||
|
||
it('custom plugins, default categories', () => { | ||
// snapshot because it can change with the next release | ||
expect( | ||
buildFromObject({ | ||
plugins: ['unicorn'], | ||
}) | ||
).toMatchSnapshot('customPluginDefaultCategories'); | ||
}); | ||
const rules = buildFromOxlintConfigFile(filename); | ||
|
||
it('custom plugins, custom categories', () => { | ||
// snapshot because it can change with the next release | ||
expect( | ||
buildFromObject({ | ||
plugins: ['eslint'], | ||
categories: { | ||
perf: 'warn', | ||
correctness: 'off', | ||
fs.unlinkSync(filename); | ||
|
||
return rules; | ||
}; | ||
|
||
describe('buildFromOxlintConfigFile', () => { | ||
it('successfully parse oxlint config', () => { | ||
const rules = createConfigFileAndBuildFromIt('success-config.json', { | ||
rules: { | ||
'no-await-loop': 'on', | ||
}, | ||
}) | ||
).toMatchSnapshot('customPluginCustomCategories'); | ||
}); | ||
}); | ||
|
||
expect('no-await-loop' in rules).toBe(true); | ||
}); | ||
|
||
it('failes to find oxlint config', () => { | ||
const rules = buildFromOxlintConfigFile('not-found.json'); | ||
|
||
expect(rules).toStrictEqual({}); | ||
}); | ||
|
||
it('failes to parse oxlint config', () => { | ||
const rules = createConfigFileAndBuildFromIt( | ||
'invalid-config.json', | ||
'["this", is an invalid json format]' | ||
); | ||
|
||
it('skip deactive rules, for custom enable category', () => { | ||
const rules = buildFromObject({ | ||
plugins: ['eslint'], | ||
categories: { | ||
perf: 'warn', | ||
correctness: 'off', | ||
}, | ||
rules: { | ||
'no-await-in-loop': 'off', | ||
}, | ||
expect(rules).toStrictEqual({}); | ||
}); | ||
expect('no-await-in-loop' in rules).toBe(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters