-
-
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.
Merge branch 'no-absolute-path-perf'
- Loading branch information
Showing
4 changed files
with
70 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,20 @@ | ||
import importType from '../core/importType' | ||
import isStaticRequire from '../core/staticRequire' | ||
|
||
function reportIfMissing(context, node, name) { | ||
if (importType(name, context) === 'absolute') { | ||
context.report(node, 'Do not import modules using an absolute path') | ||
} | ||
} | ||
import { isAbsolute } from '../core/importType' | ||
import moduleVisitor, { makeOptionsSchema } from 'eslint-module-utils/moduleVisitor' | ||
|
||
module.exports = { | ||
meta: { | ||
docs: {}, | ||
schema: [ makeOptionsSchema() ], | ||
}, | ||
|
||
create: function (context) { | ||
return { | ||
ImportDeclaration: function handleImports(node) { | ||
reportIfMissing(context, node, node.source.value) | ||
}, | ||
CallExpression: function handleRequires(node) { | ||
if (isStaticRequire(node)) { | ||
reportIfMissing(context, node, node.arguments[0].value) | ||
} | ||
}, | ||
function reportIfAbsolute(source) { | ||
if (isAbsolute(source.value)) { | ||
context.report(source, 'Do not import modules using an absolute path') | ||
} | ||
} | ||
|
||
const options = Object.assign({ esmodule: true, commonjs: true }, context.options[0]) | ||
return moduleVisitor(reportIfAbsolute, options) | ||
}, | ||
} |
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