1- import { test } from '../utils'
1+ import { getTSParsers , test } from '../utils'
22import * as path from 'path'
33import * as fs from 'fs'
44
@@ -17,6 +17,7 @@ const packageFileWithSyntaxErrorMessage = (() => {
1717 }
1818} ) ( )
1919const packageDirWithFlowTyped = path . join ( __dirname , '../../files/with-flow-typed' )
20+ const packageDirWithTypescriptDevDependencies = path . join ( __dirname , '../../files/with-typescript-dev-dependencies' )
2021const packageDirMonoRepoRoot = path . join ( __dirname , '../../files/monorepo' )
2122const packageDirMonoRepoWithNested = path . join ( __dirname , '../../files/monorepo/packages/nested-package' )
2223const packageDirWithEmpty = path . join ( __dirname , '../../files/empty' )
@@ -312,3 +313,56 @@ ruleTester.run('no-extraneous-dependencies', rule, {
312313 } ) ,
313314 ] ,
314315} )
316+
317+ describe ( 'TypeScript' , function ( ) {
318+ getTSParsers ( )
319+ . forEach ( ( parser ) => {
320+ const parserConfig = {
321+ parser : parser ,
322+ settings : {
323+ 'import/parsers' : { [ parser ] : [ '.ts' ] } ,
324+ 'import/resolver' : { 'eslint-import-resolver-typescript' : true } ,
325+ } ,
326+ }
327+
328+ if ( parser !== require . resolve ( 'typescript-eslint-parser' ) ) {
329+ ruleTester . run ( 'no-extraneous-dependencies' , rule , {
330+ valid : [
331+ test ( Object . assign ( {
332+ code : 'import type { JSONSchema7Type } from "@types/json-schema";' ,
333+ options : [ { packageDir : packageDirWithTypescriptDevDependencies , devDependencies : false } ] ,
334+ } , parserConfig ) ) ,
335+ ] ,
336+ invalid : [
337+ test ( Object . assign ( {
338+ code : 'import { JSONSchema7Type } from "@types/json-schema";' ,
339+ options : [ { packageDir : packageDirWithTypescriptDevDependencies , devDependencies : false } ] ,
340+ errors : [ {
341+ message : "'@types/json-schema' should be listed in the project's dependencies, not devDependencies." ,
342+ } ] ,
343+ } , parserConfig ) ) ,
344+ ] ,
345+ } )
346+ } else {
347+ ruleTester . run ( 'no-extraneous-dependencies' , rule , {
348+ valid : [ ] ,
349+ invalid : [
350+ test ( Object . assign ( {
351+ code : 'import { JSONSchema7Type } from "@types/json-schema";' ,
352+ options : [ { packageDir : packageDirWithTypescriptDevDependencies , devDependencies : false } ] ,
353+ errors : [ {
354+ message : "'@types/json-schema' should be listed in the project's dependencies, not devDependencies." ,
355+ } ] ,
356+ } , parserConfig ) ) ,
357+ test ( Object . assign ( {
358+ code : 'import type { JSONSchema7Type } from "@types/json-schema";' ,
359+ options : [ { packageDir : packageDirWithTypescriptDevDependencies , devDependencies : false } ] ,
360+ errors : [ {
361+ message : "'@types/json-schema' should be listed in the project's dependencies, not devDependencies." ,
362+ } ] ,
363+ } , parserConfig ) ) ,
364+ ] ,
365+ } )
366+ }
367+ } )
368+ } )
0 commit comments