Skip to content

Commit

Permalink
flow: Ignore import statements when using 'import type'
Browse files Browse the repository at this point in the history
Fixes #931
  • Loading branch information
KevinGrandon authored and ljharb committed Dec 24, 2017
1 parent 1c41350 commit 523789f
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 523789f

Please sign in to comment.