Skip to content

Commit 1a76c52

Browse files
committed
Ignore type imports for named rule.
1 parent cfd4377 commit 1a76c52

File tree

4 files changed

+8
-23
lines changed

4 files changed

+8
-23
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

66
## [Unreleased]
7+
- Ignore type imports for named rule ([#931], thanks [@mattijsbliek])
78
- Add documentation for [`no-useless-path-segments`] rule ([#1068], thanks [@manovotny])
89
- Fixer for [`first`] ([#1046], thanks [@fengkfengk])
910

docs/rules/named.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ Note: for packages, the plugin will find exported names
88
from [`jsnext:main`], if present in `package.json`.
99
Redux's npm module includes this key, and thereby is lintable, for example.
1010

11-
A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported.
11+
A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported. Note that type imports, as used by [Flow], are always ignored.
1212

1313
[ignored]: ../../README.md#importignore
1414
[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar
15+
[Flow]: https://flow.org/
1516

1617

1718
## Rule Details

src/rules/named.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module.exports = {
1111

1212
create: function (context) {
1313
function checkSpecifiers(key, type, node) {
14-
if (node.source == null) return // local export, ignore
14+
// ignore local exports and type imports
15+
if (node.source == null || node.importKind === 'type') return
1516

1617
if (!node.specifiers
1718
.some(function (im) { return im.type === type })) {

tests/src/rules/named.js

+3-21
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,10 @@ ruleTester.run('named', rule, {
6767
test({ code: 'import { deepProp } from "./named-exports"' }),
6868
test({ code: 'import { deepSparseElement } from "./named-exports"' }),
6969

70-
// flow types
70+
// should ignore imported flow types, even if they don’t exist
7171
test({
72-
code: 'import type { MyType } from "./flowtypes"',
73-
'parser': 'babel-eslint',
74-
}),
75-
test({
76-
code: 'import type { MyInterface } from "./flowtypes"',
77-
'parser': 'babel-eslint',
78-
}),
79-
test({
80-
code: 'import type { MyClass } from "./flowtypes"',
81-
'parser': 'babel-eslint',
72+
code: 'import type { MissingType } from "./flowtypes"',
73+
parser: 'babel-eslint',
8274
}),
8375

8476
// TypeScript
@@ -244,16 +236,6 @@ ruleTester.run('named', rule, {
244236
// }],
245237
// }),
246238

247-
// flow types
248-
test({
249-
code: 'import type { MissingType } from "./flowtypes"',
250-
parser: 'babel-eslint',
251-
errors: [{
252-
message: "MissingType not found in './flowtypes'",
253-
type: 'Identifier',
254-
}],
255-
}),
256-
257239
// TypeScript
258240
test({
259241
code: 'import { MissingType } from "./typescript"',

0 commit comments

Comments
 (0)