Skip to content

Commit 33e9afe

Browse files
committed
Allow defineConfig to resolve multiple configs
1 parent 0570b73 commit 33e9afe

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

src/define-config/index.test.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('defines a valid Oxlint config', () => {
1010

1111
expect(config).toHaveProperty('rules', expect.any(Object));
1212
expect(config.rules).toHaveProperty('unicorn/no-null', 'off');
13-
expect(config.rules).not.toHaveProperty('react/jsx-filename-extension');
13+
expect(config.rules).not.toHaveProperty('react/jsx-key');
1414

1515
config = defineConfig({
1616
ignorePatterns: ['fixtures/**'],
@@ -24,7 +24,33 @@ test('defines a valid Oxlint config', () => {
2424
expect(config.ignorePatterns).toContain('fixtures/**');
2525
expect(config).toHaveProperty('rules', expect.any(Object));
2626
expect(config.rules).toHaveProperty('unicorn/no-null', 'error');
27-
expect(config.rules).not.toHaveProperty('react/jsx-filename-extension');
27+
expect(config.rules).not.toHaveProperty('react/jsx-key');
28+
29+
config = defineConfig(
30+
{
31+
rules: {
32+
'unicorn/no-null': 'warn',
33+
'unicorn/no-useless-undefined': 'error',
34+
},
35+
},
36+
{
37+
ignorePatterns: ['fixtures/**'],
38+
rules: {
39+
'unicorn/no-null': 'error',
40+
},
41+
}
42+
);
43+
44+
expectTypeOf(config).toEqualTypeOf<OxlintConfig>();
45+
expect(config).toHaveProperty('ignorePatterns', expect.any(Array));
46+
expect(config.ignorePatterns).toContain('fixtures/**');
47+
expect(config).toHaveProperty('rules', expect.any(Object));
48+
expect(config.rules).toHaveProperty('unicorn/no-null', 'error');
49+
expect(config.rules).toHaveProperty(
50+
'unicorn/no-useless-undefined',
51+
'error'
52+
);
53+
expect(config.rules).not.toHaveProperty('react/jsx-key');
2854
});
2955

3056
test('supports the `react` option', () => {
@@ -36,5 +62,10 @@ test('supports the `react` option', () => {
3662
expect(config).not.toStrictEqual(defineConfig());
3763
expect(config).not.toHaveProperty('react');
3864
expect(config.rules).toHaveProperty('unicorn/no-null', 'off');
39-
expect(config.rules).toHaveProperty('react/jsx-filename-extension');
65+
expect(config.rules).toHaveProperty('react/jsx-key');
66+
67+
expect(defineConfig({}, { react: true }, {})).toStrictEqual(config);
68+
expect(defineConfig({}, { react: true }, { react: false })).toStrictEqual(
69+
defineConfig()
70+
);
4071
});

src/define-config/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,26 @@ import configTypeDefinitions from '../config-type-definitions/index.ts';
99
import mergeConfig from '../merge-config/index.ts';
1010

1111
export default function defineConfig(
12-
config: StandardConfig = {}
12+
...configs: ReadonlyArray<StandardConfig>
1313
): OxlintConfig {
14-
const { react, ...extensionConfig } = config;
14+
let extensionConfig: OxlintConfig = {};
15+
let includeReactConfig = false;
16+
17+
for (const config of configs) {
18+
const { react, ...otherConfig } = config;
19+
20+
extensionConfig = mergeConfig(extensionConfig, otherConfig);
21+
22+
if (react !== undefined) {
23+
includeReactConfig = react;
24+
}
25+
}
1526

1627
const baseConfig: OxlintConfig = {
17-
...(react ? mergeConfig(configBase, configReact) : configBase),
28+
...(includeReactConfig
29+
? mergeConfig(configBase, configReact)
30+
: configBase),
31+
1832
overrides: [
1933
{
2034
files: [

0 commit comments

Comments
 (0)