Skip to content

Commit

Permalink
PR note fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Jul 6, 2017
1 parent 5aa2fe0 commit e4b8884
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/core/importType.js
Expand Up @@ -8,6 +8,10 @@ function constant(value) {
return () => value
}

export function isAbsolute(name) {
return name.indexOf('/') === 0
}

export function isBuiltIn(name, settings) {
const extras = (settings && settings['import/core-modules']) || []
return builtinModules.indexOf(name) !== -1 || extras.indexOf(name) > -1
Expand Down Expand Up @@ -46,6 +50,7 @@ function isRelativeToSibling(name) {
}

const typeTest = cond([
[isAbsolute, constant('absolute')],
[isBuiltIn, constant('builtin')],
[isExternalModule, constant('external')],
[isScoped, constant('external')],
Expand Down
5 changes: 1 addition & 4 deletions src/rules/no-absolute-path.js
@@ -1,3 +1,4 @@
import { isAbsolute } from '../core/importType'
import isStaticRequire from '../core/staticRequire'

function reportIfAbsolute(context, node, name) {
Expand All @@ -6,10 +7,6 @@ function reportIfAbsolute(context, node, name) {
}
}

function isAbsolute(name) {
return name.indexOf('/') === 0
}

module.exports = {
meta: {
docs: {},
Expand Down
6 changes: 6 additions & 0 deletions tests/src/core/importType.js
Expand Up @@ -8,6 +8,12 @@ import { testContext } from '../utils'
describe('importType(name)', function () {
const context = testContext()

it("should return 'absolute' for paths starting with a /", function() {
expect(importType('/', context)).to.equal('absolute')
expect(importType('/path', context)).to.equal('absolute')
expect(importType('/some/path', context)).to.equal('absolute')
})

it("should return 'builtin' for node.js modules", function() {
expect(importType('fs', context)).to.equal('builtin')
expect(importType('path', context)).to.equal('builtin')
Expand Down

0 comments on commit e4b8884

Please sign in to comment.