Skip to content

Commit

Permalink
Extract isAbsolutePath from importTypes helper
Browse files Browse the repository at this point in the history
importTypes helper performs resolve() - which does not look needed for the no-absolute-path rule.

Additionally, the absolute condition only seems like it was used for no-absolute-path.

Finally, all the tests continue to pass.
  • Loading branch information
Joachim Seminck committed May 24, 2017
1 parent b79e083 commit 3e8438e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
5 changes: 0 additions & 5 deletions src/core/importType.js
Expand Up @@ -8,10 +8,6 @@ function constant(value) {
return () => value
}

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 @@ -50,7 +46,6 @@ function isRelativeToSibling(name) {
}

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

function reportIfMissing(context, node, name) {
if (importType(name, context) === 'absolute') {
if (isAbsolute(name)) {
context.report(node, 'Do not import modules using an absolute path')
}
}

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

module.exports = {
meta: {
docs: {},
Expand Down
6 changes: 0 additions & 6 deletions tests/src/core/importType.js
Expand Up @@ -8,12 +8,6 @@ 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 3e8438e

Please sign in to comment.