1
- import { test } from '../utils'
1
+ import { test , getTSParsers } from '../utils'
2
2
import * as path from 'path'
3
3
import * as fs from 'fs'
4
4
@@ -17,6 +17,7 @@ const packageFileWithSyntaxErrorMessage = (() => {
17
17
}
18
18
} ) ( )
19
19
const packageDirWithFlowTyped = path . join ( __dirname , '../../files/with-flow-typed' )
20
+ const packageDirWithTypescriptDevDependencies = path . join ( __dirname , '../../files/with-typescript-dev-dependencies' )
20
21
const packageDirMonoRepoRoot = path . join ( __dirname , '../../files/monorepo' )
21
22
const packageDirMonoRepoWithNested = path . join ( __dirname , '../../files/monorepo/packages/nested-package' )
22
23
const packageDirWithEmpty = path . join ( __dirname , '../../files/empty' )
@@ -312,3 +313,35 @@ ruleTester.run('no-extraneous-dependencies', rule, {
312
313
} ) ,
313
314
] ,
314
315
} )
316
+
317
+ describe ( 'TypeScript' , function ( ) {
318
+ getTSParsers ( ) . forEach ( ( parser ) => {
319
+ const parserConfig = {
320
+ parser : parser ,
321
+ settings : {
322
+ 'import/parsers' : { [ parser ] : [ '.ts' ] } ,
323
+ 'import/resolver' : { 'eslint-import-resolver-typescript' : true } ,
324
+ } ,
325
+ }
326
+
327
+ ruleTester . run ( 'no-extraneous-dependencies' , rule , {
328
+ valid : [
329
+ test ( Object . assign ( {
330
+ code : 'import type { PackageJson } from "type-fest";' ,
331
+ filename : path . join ( packageDirWithTypescriptDevDependencies , 'file.ts' ) ,
332
+ options : [ { packageDir : packageDirWithTypescriptDevDependencies , devDependencies : false } ] ,
333
+ } , parserConfig ) ) ,
334
+ ] ,
335
+ invalid : [
336
+ test ( Object . assign ( {
337
+ code : 'import { PackageJson } from "type-fest";' ,
338
+ filename : path . join ( packageDirWithTypescriptDevDependencies , 'file.ts' ) ,
339
+ options : [ { packageDir : packageDirWithTypescriptDevDependencies , devDependencies : false } ] ,
340
+ errors : [ {
341
+ message : "'type-fest' should be listed in the project's dependencies, not devDependencies." ,
342
+ } ] ,
343
+ } , parserConfig ) ) ,
344
+ ] ,
345
+ } )
346
+ } )
347
+ } )
0 commit comments