1
1
import type { TSESLint } from '@typescript-eslint/utils' ;
2
2
3
- import plugin from '../src/index' ;
3
+ import tseslint from '../src/index' ;
4
4
5
5
describe ( 'config helper' , ( ) => {
6
6
it ( 'works without extends' , ( ) => {
7
7
expect (
8
- plugin . config ( {
8
+ tseslint . config ( {
9
9
files : [ 'file' ] ,
10
10
ignores : [ 'ignored' ] ,
11
11
rules : { rule : 'error' } ,
@@ -21,7 +21,7 @@ describe('config helper', () => {
21
21
22
22
it ( 'flattens extended configs' , ( ) => {
23
23
expect (
24
- plugin . config ( {
24
+ tseslint . config ( {
25
25
extends : [ { rules : { rule1 : 'error' } } , { rules : { rule2 : 'error' } } ] ,
26
26
rules : { rule : 'error' } ,
27
27
} ) ,
@@ -34,7 +34,7 @@ describe('config helper', () => {
34
34
35
35
it ( 'flattens extended configs with files and ignores' , ( ) => {
36
36
expect (
37
- plugin . config ( {
37
+ tseslint . config ( {
38
38
extends : [ { rules : { rule1 : 'error' } } , { rules : { rule2 : 'error' } } ] ,
39
39
files : [ 'common-file' ] ,
40
40
ignores : [ 'common-ignored' ] ,
@@ -63,7 +63,7 @@ describe('config helper', () => {
63
63
const extension : TSESLint . FlatConfig . Config = { rules : { rule1 : 'error' } } ;
64
64
65
65
expect ( ( ) =>
66
- plugin . config (
66
+ tseslint . config (
67
67
{
68
68
extends : [ extension ] ,
69
69
files : [ 'common-file' ] ,
@@ -81,7 +81,7 @@ describe('config helper', () => {
81
81
} ,
82
82
) ,
83
83
) . toThrow (
84
- 'Your config at index 1, named "my-config-2", contains undefined ' +
84
+ 'tseslint. config(): Config at index 1, named "my-config-2", contains non-object ' +
85
85
'extensions at the following indices: 0, 2' ,
86
86
) ;
87
87
} ) ;
@@ -90,7 +90,7 @@ describe('config helper', () => {
90
90
const extension : TSESLint . FlatConfig . Config = { rules : { rule1 : 'error' } } ;
91
91
92
92
expect ( ( ) =>
93
- plugin . config (
93
+ tseslint . config (
94
94
{
95
95
extends : [ extension ] ,
96
96
files : [ 'common-file' ] ,
@@ -107,14 +107,14 @@ describe('config helper', () => {
107
107
} ,
108
108
) ,
109
109
) . toThrow (
110
- 'Your config at index 1 (anonymous) contains undefined extensions at ' +
110
+ 'tseslint. config(): Config at index 1 (anonymous) contains non-object extensions at ' +
111
111
'the following indices: 0, 2' ,
112
112
) ;
113
113
} ) ;
114
114
115
115
it ( 'flattens extended configs with config name' , ( ) => {
116
116
expect (
117
- plugin . config ( {
117
+ tseslint . config ( {
118
118
extends : [ { rules : { rule1 : 'error' } } , { rules : { rule2 : 'error' } } ] ,
119
119
files : [ 'common-file' ] ,
120
120
ignores : [ 'common-ignored' ] ,
@@ -145,7 +145,7 @@ describe('config helper', () => {
145
145
146
146
it ( 'flattens extended configs with names if base config is unnamed' , ( ) => {
147
147
expect (
148
- plugin . config ( {
148
+ tseslint . config ( {
149
149
extends : [
150
150
{ name : 'extension-1' , rules : { rule1 : 'error' } } ,
151
151
{ rules : { rule2 : 'error' } } ,
@@ -176,7 +176,7 @@ describe('config helper', () => {
176
176
177
177
it ( 'merges config items names' , ( ) => {
178
178
expect (
179
- plugin . config ( {
179
+ tseslint . config ( {
180
180
extends : [
181
181
{ name : 'extension-1' , rules : { rule1 : 'error' } } ,
182
182
{ rules : { rule2 : 'error' } } ,
@@ -210,7 +210,7 @@ describe('config helper', () => {
210
210
211
211
it ( 'allows nested arrays in the config function' , ( ) => {
212
212
expect (
213
- plugin . config (
213
+ tseslint . config (
214
214
{ rules : { rule1 : 'error' } } ,
215
215
[ { rules : { rule2 : 'error' } } ] ,
216
216
[ [ { rules : { rule3 : 'error' } } ] ] ,
@@ -228,7 +228,7 @@ describe('config helper', () => {
228
228
229
229
it ( 'allows nested arrays in extends' , ( ) => {
230
230
expect (
231
- plugin . config ( {
231
+ tseslint . config ( {
232
232
extends : [
233
233
{ rules : { rule1 : 'error' } } ,
234
234
[ { rules : { rule2 : 'error' } } ] ,
@@ -249,7 +249,7 @@ describe('config helper', () => {
249
249
} ) ;
250
250
251
251
it ( 'does not create global ignores in extends' , ( ) => {
252
- const configWithIgnores = plugin . config ( {
252
+ const configWithIgnores = tseslint . config ( {
253
253
extends : [ { rules : { rule1 : 'error' } } , { rules : { rule2 : 'error' } } ] ,
254
254
ignores : [ 'ignored' ] ,
255
255
} ) ;
@@ -265,7 +265,7 @@ describe('config helper', () => {
265
265
} ) ;
266
266
267
267
it ( 'creates noop config in extends' , ( ) => {
268
- const configWithMetadata = plugin . config ( {
268
+ const configWithMetadata = tseslint . config ( {
269
269
extends : [ { rules : { rule1 : 'error' } } , { rules : { rule2 : 'error' } } ] ,
270
270
files : [ 'file' ] ,
271
271
ignores : [ 'ignored' ] ,
@@ -297,7 +297,7 @@ describe('config helper', () => {
297
297
298
298
it ( 'does not create global ignores when extending empty configs' , ( ) => {
299
299
expect (
300
- plugin . config ( {
300
+ tseslint . config ( {
301
301
extends : [ { rules : { rule1 : 'error' } } , { } ] ,
302
302
ignores : [ 'ignored' ] ,
303
303
} ) ,
@@ -310,10 +310,68 @@ describe('config helper', () => {
310
310
311
311
it ( 'handles name field when global-ignoring in extension' , ( ) => {
312
312
expect (
313
- plugin . config ( {
313
+ tseslint . config ( {
314
314
extends : [ { ignores : [ 'files/**/*' ] , name : 'global-ignore-stuff' } ] ,
315
315
ignores : [ 'ignored' ] ,
316
316
} ) ,
317
317
) . toEqual ( [ { ignores : [ 'files/**/*' ] , name : 'global-ignore-stuff' } ] ) ;
318
318
} ) ;
319
+
320
+ it ( 'throws error when extends is not an array' , ( ) => {
321
+ expect ( ( ) =>
322
+ tseslint . config ( {
323
+ // @ts -expect-error purposely testing invalid values
324
+ extends : 42 ,
325
+ } ) ,
326
+ ) . toThrow (
327
+ "tseslint.config(): Config at index 0 (anonymous) has an 'extends' property that is not an array." ,
328
+ ) ;
329
+ } ) ;
330
+
331
+ it . each ( [ undefined , null , 'not a config object' , 42 ] ) (
332
+ 'passes invalid arguments through unchanged' ,
333
+ config => {
334
+ expect (
335
+ tseslint . config (
336
+ // @ts -expect-error purposely testing invalid values
337
+ config ,
338
+ ) ,
339
+ ) . toStrictEqual ( [ config ] ) ;
340
+ } ,
341
+ ) ;
342
+
343
+ it ( 'gives a special error message for string extends' , ( ) => {
344
+ expect ( ( ) =>
345
+ tseslint . config ( {
346
+ // @ts -expect-error purposely testing invalid values
347
+ extends : [ 'some-string' ] ,
348
+ } ) ,
349
+ ) . toThrow (
350
+ 'tseslint.config(): Config at index 0 (anonymous) has an \'extends\' array that contains a string ("some-string") at index 0. ' +
351
+ "This is a feature of eslint's `defineConfig()` helper and is not supported by typescript-eslint. " +
352
+ 'Please provide a config object instead.' ,
353
+ ) ;
354
+ } ) ;
355
+
356
+ it ( 'strips nullish extends arrays from the config object' , ( ) => {
357
+ expect (
358
+ tseslint . config ( {
359
+ // @ts -expect-error purposely testing invalid values
360
+ extends : null ,
361
+ files : [ 'files' ] ,
362
+ } ) ,
363
+ ) . toEqual ( [ { files : [ 'files' ] } ] ) ;
364
+ } ) ;
365
+
366
+ it ( 'complains when given an object with an invalid name' , ( ) => {
367
+ expect ( ( ) =>
368
+ tseslint . config ( {
369
+ extends : [ ] ,
370
+ // @ts -expect-error purposely testing invalid values
371
+ name : 42 ,
372
+ } ) ,
373
+ ) . toThrow (
374
+ "tseslint.config(): Config at index 0 has a 'name' property that is not a string." ,
375
+ ) ;
376
+ } ) ;
319
377
} ) ;
0 commit comments