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 23e9dc9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/rules/no-extraneous-dependencies.js
Expand Up @@ -111,7 +111,9 @@ function optDepErrorMessage(packageName) {

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

if (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 23e9dc9

Please sign in to comment.