From 7abb1e1c9ec95dcad44bf4882e05b094b7f67400 Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Tue, 26 Jun 2018 18:33:44 +0100 Subject: [PATCH 1/3] feat: make no-cycle ignore Flow imports --- src/rules/no-cycle.js | 4 ++++ tests/src/rules/no-cycle.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/rules/no-cycle.js b/src/rules/no-cycle.js index bbc251e38..ccf77dcf2 100644 --- a/src/rules/no-cycle.js +++ b/src/rules/no-cycle.js @@ -30,6 +30,10 @@ module.exports = { function checkSourceValue(sourceNode, importer) { const imported = Exports.get(sourceNode.value, context) + if (sourceNode.parent.importKind === 'type') { + return // no Flow import resolution + } + if (imported == null) { return // no-unresolved territory } diff --git a/tests/src/rules/no-cycle.js b/tests/src/rules/no-cycle.js index ae45ba36e..4ee4daacb 100644 --- a/tests/src/rules/no-cycle.js +++ b/tests/src/rules/no-cycle.js @@ -36,6 +36,10 @@ ruleTester.run('no-cycle', rule, { code: 'import { foo } from "./depth-two"', options: [{ maxDepth: 1 }], }), + test({ + code: 'import type { FooType } from "./depth-one"', + parser: 'babel-eslint', + }), ], invalid: [ test({ From 60f65979fae29fc38d11cd79ade6336037a789ea Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Tue, 26 Jun 2018 19:30:36 +0100 Subject: [PATCH 2/3] fix: handly possible undefined parent --- src/rules/no-cycle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/no-cycle.js b/src/rules/no-cycle.js index ccf77dcf2..a925f9871 100644 --- a/src/rules/no-cycle.js +++ b/src/rules/no-cycle.js @@ -30,7 +30,7 @@ module.exports = { function checkSourceValue(sourceNode, importer) { const imported = Exports.get(sourceNode.value, context) - if (sourceNode.parent.importKind === 'type') { + if (sourceNode.parent && sourceNode.parent.importKind === 'type') { return // no Flow import resolution } From 3feb54cfa20db3ed39b8a32e430b4ea3508eda8a Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Sun, 29 Jul 2018 12:50:40 +0100 Subject: [PATCH 3/3] fix: add a workaround for ESLint < v5 --- src/rules/no-cycle.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rules/no-cycle.js b/src/rules/no-cycle.js index a925f9871..1a70db2c7 100644 --- a/src/rules/no-cycle.js +++ b/src/rules/no-cycle.js @@ -34,6 +34,10 @@ module.exports = { return // no Flow import resolution } + if (sourceNode._babelType === 'Literal') { + return // no Flow import resolution, workaround for ESLint < 5.x + } + if (imported == null) { return // no-unresolved territory }