Skip to content

Commit

Permalink
fix(no-extranaeous-dependencies): check if node.parent.importKind is …
Browse files Browse the repository at this point in the history
…'type'

to ignore typescript `import type`
  • Loading branch information
taye committed Jun 13, 2020
1 parent 54eb51b commit df1f80f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rules/no-extraneous-dependencies.js
Expand Up @@ -111,7 +111,7 @@ function optDepErrorMessage(packageName) {

function reportIfMissing(context, deps, depsOptions, node, name) {
// Do not report when importing types
if (node.importKind === 'type') {
if (node.importKind || node.parent.importKind === 'type') {
return
}

Expand Down
21 changes: 20 additions & 1 deletion tests/src/rules/no-extraneous-dependencies.js
@@ -1,11 +1,13 @@
import { test } from '../utils'
import { test, testFilePath } from '../utils'
import typescriptConfig from '../../../config/typescript'
import * as path from 'path'
import * as fs from 'fs'

import { RuleTester } from 'eslint'
import flatMap from 'array.prototype.flatmap'

const ruleTester = new RuleTester()
const typescriptRuleTester = new RuleTester(typescriptConfig)
const rule = require('rules/no-extraneous-dependencies')

const packageDirWithSyntaxError = path.join(__dirname, '../../files/with-syntax-error')
Expand Down Expand Up @@ -312,3 +314,20 @@ ruleTester.run('no-extraneous-dependencies', rule, {
}),
],
})

typescriptRuleTester.run('no-extraneous-dependencies typescript type imports', rule, {
valid: [
test({
code: 'import type MyType from "not-a-dependency";',
filename: testFilePath('./no-unused-modules/typescript/file-ts-a.ts'),
parser: require.resolve('babel-eslint'),
}),
test({
code: 'import type { MyType } from "not-a-dependency";',
filename: testFilePath('./no-unused-modules/typescript/file-ts-a.ts'),
parser: require.resolve('babel-eslint'),
}),
],
invalid: [
],
})

0 comments on commit df1f80f

Please sign in to comment.