-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Performance increase for no-absolute-path #843
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -50,7 +46,6 @@ function isRelativeToSibling(name) { | |
} | ||
|
||
const typeTest = cond([ | ||
[isAbsolute, constant('absolute')], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also keep this here, needed for |
||
[isBuiltIn, constant('builtin')], | ||
[isExternalModule, constant('external')], | ||
[isScoped, constant('external')], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import importType from '../core/importType' | ||
import isStaticRequire from '../core/staticRequire' | ||
|
||
function reportIfMissing(context, node, name) { | ||
if (importType(name, context) === 'absolute') { | ||
function reportIfAbsolute(context, node, name) { | ||
if (isAbsolute(name)) { | ||
context.report(node, 'Do not import modules using an absolute path') | ||
} | ||
} | ||
|
||
function isAbsolute(name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so this is replaced with |
||
return name.indexOf('/') === 0 | ||
} | ||
|
||
module.exports = { | ||
meta: { | ||
docs: {}, | ||
|
@@ -15,11 +18,11 @@ module.exports = { | |
create: function (context) { | ||
return { | ||
ImportDeclaration: function handleImports(node) { | ||
reportIfMissing(context, node, node.source.value) | ||
reportIfAbsolute(context, node, node.source.value) | ||
}, | ||
CallExpression: function handleRequires(node) { | ||
if (isStaticRequire(node)) { | ||
reportIfMissing(context, node, node.arguments[0].value) | ||
reportIfAbsolute(context, node, node.arguments[0].value) | ||
} | ||
}, | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and then put these tests back 😁 |
||
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') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of removing this, could you export it and then import it in
no-absolute-path
?