-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- lookup package.json relative to file being linted - added 'project' import type, which is ignored - uses resolved path to disambiguate some types of imports
- Loading branch information
Showing
8 changed files
with
85 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ env: | |
mocha: true | ||
rules: | ||
no-unused-expressions: 0 | ||
quotes: [2, 'single', 'avoid-escape'] | ||
max-len: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* for importType test, just needs to exist */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
{ "dummy": true } | ||
{ | ||
"dummy": true, | ||
"devDependencies": { | ||
"eslint": "2.x" | ||
}, | ||
"peerDependencies": { | ||
"eslint": "2.x" | ||
}, | ||
"dependencies": { | ||
"lodash.cond": "^4.3.0", | ||
"pkg-up": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,60 @@ | ||
import { expect } from 'chai' | ||
import * as path from 'path' | ||
|
||
import importType from 'core/importType' | ||
|
||
import { testContext } from '../utils' | ||
|
||
describe('importType(name)', function () { | ||
const context = testContext() | ||
|
||
it("should return 'builtin' for node.js modules", function() { | ||
expect(importType('fs')).to.equal('builtin') | ||
expect(importType('path')).to.equal('builtin') | ||
expect(importType('fs', context)).to.equal('builtin') | ||
expect(importType('path', context)).to.equal('builtin') | ||
}) | ||
|
||
it("should return 'external' for non-builtin modules without a relative path", function() { | ||
expect(importType('lodash')).to.equal('external') | ||
expect(importType('async')).to.equal('external') | ||
expect(importType('chalk')).to.equal('external') | ||
expect(importType('foo')).to.equal('external') | ||
expect(importType('lodash.find')).to.equal('external') | ||
expect(importType('lodash/fp')).to.equal('external') | ||
expect(importType('lodash', context)).to.equal('external') | ||
expect(importType('async', context)).to.equal('external') | ||
expect(importType('chalk', context)).to.equal('external') | ||
expect(importType('foo', context)).to.equal('external') | ||
expect(importType('lodash.find', context)).to.equal('external') | ||
expect(importType('lodash/fp', context)).to.equal('external') | ||
}) | ||
|
||
it("should return 'project' for non-builtins resolved outside of node_modules", function () { | ||
const pathContext = testContext({ "import/resolver": { node: { paths: [ path.join(__dirname, '..', '..', 'files') ] } } }) | ||
expect(importType('importType', pathContext)).to.equal('project') | ||
}) | ||
|
||
it("should return 'parent' for internal modules that go through the parent", function() { | ||
expect(importType('../foo')).to.equal('parent') | ||
expect(importType('../../foo')).to.equal('parent') | ||
expect(importType('../bar/foo')).to.equal('parent') | ||
expect(importType('../foo', context)).to.equal('parent') | ||
expect(importType('../../foo', context)).to.equal('parent') | ||
expect(importType('../bar/foo', context)).to.equal('parent') | ||
}) | ||
|
||
it("should return 'sibling' for internal modules that are connected to one of the siblings", function() { | ||
expect(importType('./foo')).to.equal('sibling') | ||
expect(importType('./foo/bar')).to.equal('sibling') | ||
expect(importType('./foo', context)).to.equal('sibling') | ||
expect(importType('./foo/bar', context)).to.equal('sibling') | ||
}) | ||
|
||
it("should return 'index' for sibling index file", function() { | ||
expect(importType('.')).to.equal('index') | ||
expect(importType('./')).to.equal('index') | ||
expect(importType('./index')).to.equal('index') | ||
expect(importType('./index.js')).to.equal('index') | ||
describe("should return 'index' for sibling index file when", function() { | ||
it("resolves", function() { | ||
expect(importType('./importType', context)).to.equal('index') | ||
expect(importType('./importType/', context)).to.equal('index') | ||
expect(importType('./importType/index', context)).to.equal('index') | ||
expect(importType('./importType/index.js', context)).to.equal('index') | ||
}) | ||
it("doesn't resolve", function() { | ||
expect(importType('.', context)).to.equal('index') | ||
expect(importType('./', context)).to.equal('index') | ||
expect(importType('./index', context)).to.equal('index') | ||
expect(importType('./index.js', context)).to.equal('index') | ||
}) | ||
}) | ||
|
||
it("should return 'unknown' for any unhandled cases", function() { | ||
expect(importType('/malformed')).to.equal('unknown') | ||
expect(importType(' foo')).to.equal('unknown') | ||
expect(importType('/malformed', context)).to.equal('unknown') | ||
expect(importType(' foo', context)).to.equal('unknown') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters