File tree Expand file tree Collapse file tree 5 files changed +48
-6
lines changed
utilities/define-oxlint-config Expand file tree Collapse file tree 5 files changed +48
-6
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ test('is a valid ESLint config', async () => {
1818} ) ;
1919
2020test ( 'skips parser options when `typescript-eslint` is unavailable' , async ( ) => {
21- vi . doMock ( 'typescript-eslint' , ( ) => ( { } ) ) ;
21+ /* @ts -expect-error */
22+ vi . doMock ( 'typescript-eslint' , ( ) => undefined ) ;
2223
2324 const { default : config } = await import ( './eslint.ts' ) ;
2425
Original file line number Diff line number Diff line change 11import type { ExternalPluginEntry , OxlintConfig , OxlintOverride } from 'oxlint' ;
2+ import type { StandardConfigOptions } from './common.d.ts' ;
23
34export type OxlintOverrideEntry = Pick < OxlintOverride , 'rules' > ;
45
56export type OxlintPluginEntry = Exclude < ExternalPluginEntry , string > ;
7+
8+ export type StandardConfig = OxlintConfig & StandardConfigOptions ;
Original file line number Diff line number Diff line change 1- import type { OxlintOverrideEntry , OxlintPluginEntry } from './oxlint.d.ts' ;
1+ import type { StandardConfigOptions } from './common.d.ts' ;
2+ import type {
3+ OxlintOverrideEntry ,
4+ OxlintPluginEntry ,
5+ StandardConfig ,
6+ } from './oxlint.d.ts' ;
27import { expectTypeOf , test } from 'vitest' ;
38
49test ( 'exposes valid types' , ( ) => {
@@ -8,4 +13,8 @@ test('exposes valid types', () => {
813 expectTypeOf < OxlintPluginEntry > ( ) . toBeObject ( ) ;
914 expectTypeOf < OxlintPluginEntry > ( ) . toHaveProperty ( 'name' ) ;
1015 expectTypeOf < OxlintPluginEntry > ( ) . toHaveProperty ( 'specifier' ) ;
16+
17+ expectTypeOf < StandardConfig > ( ) . toBeObject ( ) ;
18+ expectTypeOf < StandardConfig > ( ) . toHaveProperty ( 'react' ) ;
19+ expectTypeOf < StandardConfig > ( ) . not . toEqualTypeOf < StandardConfigOptions > ( ) ;
1120} ) ;
Original file line number Diff line number Diff line change 11import { defineConfig as standardDefineConfig } from '@standard-config/oxlint' ;
2- import { expect , test , vi } from 'vitest' ;
2+ import { beforeEach , expect , test , vi } from 'vitest' ;
33import oxlintConfigBase from '../../config-base/oxlint.ts' ;
44import oxlintConfigBaseReact from '../../config-react/oxlint.ts' ;
55import defineOxlintConfig from './index.ts' ;
66
7+ beforeEach ( ( ) => {
8+ vi . resetModules ( ) ;
9+ } ) ;
10+
711vi . mock ( import ( '@standard-config/oxlint' ) , async ( importActual ) => {
812 const actual = await importActual ( ) ;
913
@@ -42,3 +46,12 @@ test('forwards the `react` option', () => {
4246 } ,
4347 } ) ;
4448} ) ;
49+
50+ test ( 'throws when `@standard-config/oxlint` is unavailable' , async ( ) => {
51+ /* @ts -expect-error */
52+ vi . doMock ( '@standard-config/oxlint' , ( ) => undefined ) ;
53+
54+ const { default : defineOxlintConfig } = await import ( './index.ts' ) ;
55+
56+ expect ( ( ) => defineOxlintConfig ( ) ) . toThrowError ( '@standard-config/oxlint' ) ;
57+ } ) ;
Original file line number Diff line number Diff line change 11import type { OxlintConfig } from 'oxlint' ;
2- import { defineConfig as standardDefineConfig } from '@standard-config/ oxlint' ;
2+ import type { StandardConfig } from '../../types/ oxlint.d.ts ' ;
33import oxlintConfigBase from '../../config-base/oxlint.ts' ;
44import oxlintConfigBaseReact from '../../config-react/oxlint.ts' ;
55
6+ /* oxlint-disable-next-line typescript/consistent-type-imports */
7+ let oxlintConfig : typeof import ( '@standard-config/oxlint' ) | undefined ;
8+
9+ try {
10+ oxlintConfig = await import ( '@standard-config/oxlint' ) ;
11+ } catch { }
12+
613/**
714 * Wrapper around `defineConfig` from `@standard-config/oxlint` that combines
815 * Standard Config’s Oxlint and ESLint configs, with optional overrides.
916 */
1017export default function defineOxlintConfig (
11- ...configs : Parameters < typeof standardDefineConfig >
18+ ...configs : StandardConfig [ ]
1219) : OxlintConfig {
20+ const { defineConfig } = oxlintConfig ?? { } ;
21+
22+ if ( typeof defineConfig !== 'function' ) {
23+ /* oxlint-disable-next-line eslint-plugin-unicorn/prefer-type-error */
24+ throw new Error (
25+ 'Standard Config error: `@standard-config/oxlint` is missing'
26+ ) ;
27+ }
28+
1329 let includeReactConfig = false ;
1430
1531 for ( const { react } of configs ) {
@@ -18,7 +34,7 @@ export default function defineOxlintConfig(
1834 }
1935 }
2036
21- return standardDefineConfig (
37+ return defineConfig (
2238 includeReactConfig ? oxlintConfigBaseReact : oxlintConfigBase ,
2339 ...configs
2440 ) ;
You can’t perform that action at this time.
0 commit comments