Skip to content

Commit

Permalink
Ignore import statements when using 'import type'
Browse files Browse the repository at this point in the history
I was running into this issue and was curious if you all would entertain PRs for typing support.

Refs import-js#931
  • Loading branch information
KevinGrandon committed Dec 24, 2017
1 parent b916ed2 commit b12d871
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ function optDepErrorMessage(packageName) {
}

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

if (importType(name, context) !== 'external') {
return
}

const resolved = resolve(name, context)
if (!resolved) {
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// flow-typed signature: ____
// flow-typed version: ____/myflowtyped_v1.x.x/flow_>=v0.33.x

declare module 'myflowtyped' {}
3 changes: 3 additions & 0 deletions tests/files/with-flow-typed/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dependencies": {}
}
6 changes: 6 additions & 0 deletions tests/src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const packageFileWithSyntaxErrorMessage = (() => {
return error.message
}
})()
const packageDirWithFlowTyped = path.join(__dirname, '../../files/with-flow-typed')

ruleTester.run('no-extraneous-dependencies', rule, {
valid: [
Expand Down Expand Up @@ -69,6 +70,11 @@ ruleTester.run('no-extraneous-dependencies', rule, {
code: 'import "doctrine"',
options: [{packageDir: path.join(__dirname, '../../../')}],
}),
test({
code: 'import type MyType from "myflowtyped";',
options: [{packageDir: packageDirWithFlowTyped}],
parser: 'babel-eslint',
}),
],
invalid: [
test({
Expand Down

0 comments on commit b12d871

Please sign in to comment.