Skip to content

Commit

Permalink
Ignore type imports for named rule. (#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattijsbliek authored and benmosher committed Apr 13, 2018
1 parent d5d8b35 commit ec87b64
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

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

Expand Down
3 changes: 2 additions & 1 deletion docs/rules/named.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ Note: for packages, the plugin will find exported names
from [`jsnext:main`], if present in `package.json`.
Redux's npm module includes this key, and thereby is lintable, for example.

A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported.
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.

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


## Rule Details
Expand Down
3 changes: 2 additions & 1 deletion src/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = {

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

if (!node.specifiers
.some(function (im) { return im.type === type })) {
Expand Down
24 changes: 3 additions & 21 deletions tests/src/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,10 @@ ruleTester.run('named', rule, {
test({ code: 'import { deepProp } from "./named-exports"' }),
test({ code: 'import { deepSparseElement } from "./named-exports"' }),

// flow types
// should ignore imported flow types, even if they don’t exist
test({
code: 'import type { MyType } from "./flowtypes"',
'parser': 'babel-eslint',
}),
test({
code: 'import type { MyInterface } from "./flowtypes"',
'parser': 'babel-eslint',
}),
test({
code: 'import type { MyClass } from "./flowtypes"',
'parser': 'babel-eslint',
code: 'import type { MissingType } from "./flowtypes"',
parser: 'babel-eslint',
}),

// TypeScript
Expand Down Expand Up @@ -244,16 +236,6 @@ ruleTester.run('named', rule, {
// }],
// }),

// flow types
test({
code: 'import type { MissingType } from "./flowtypes"',
parser: 'babel-eslint',
errors: [{
message: "MissingType not found in './flowtypes'",
type: 'Identifier',
}],
}),

// TypeScript
test({
code: 'import { MissingType } from "./typescript"',
Expand Down

0 comments on commit ec87b64

Please sign in to comment.