Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore type imports for named rule. #1057

Merged
merged 1 commit into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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