From ff25e89ab8b8bb0318e51ba9db8c4405e442235d Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 10 Nov 2015 06:05:13 -0500 Subject: [PATCH 1/8] cleanup --- tests/src/rules/no-unresolved.js | 40 +++++++++++++++----------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/tests/src/rules/no-unresolved.js b/tests/src/rules/no-unresolved.js index 264d87a65..0ea09e576 100644 --- a/tests/src/rules/no-unresolved.js +++ b/tests/src/rules/no-unresolved.js @@ -19,38 +19,36 @@ ruleTester.run('no-unresolved', rule, { settings: { 'import/resolve': { 'paths': [path.join( process.cwd() - , 'tests', 'files', 'alternate-root')] - } - } + , 'tests', 'files', 'alternate-root')], + }, + }, }), test({ code: "import { DEEP } from 'in-alternate-root'; " + "import { bar } from 'src-bar';", settings: {'import/resolve': { 'paths': [ path.join('tests', 'files', 'src-root'), - path.join('tests', 'files', 'alternate-root') + path.join('tests', 'files', 'alternate-root'), ]}}}), test({ code: 'import * as foo from "a"' }), - test({ code: 'import * as foo from "jsx-module/foo"' - , settings: { 'import/resolve': { 'extensions': ['.jsx'] } } - }) - - , test({ code: 'export { foo } from "./bar"' }) - , test({ code: 'export * from "./bar"' }) - , test({ code: 'export { foo }' }) + test({ + code: 'import * as foo from "jsx-module/foo"', + settings: { 'import/resolve': { 'extensions': ['.jsx'] } }, + }), - // stage 1 proposal for export symmetry - , test({ code: 'export * as bar from "./bar"' - , parser: 'babel-eslint' - }) - , test({ code: 'export bar from "./bar"' - , parser: 'babel-eslint' - }) - , test({ code: 'import foo from "./jsx/MyUnCoolComponent.jsx"' - , options: ['case-sensitive'] - }) + test({ code: 'export { foo } from "./bar"' }), + test({ code: 'export * from "./bar"' }), + test({ code: 'export { foo }' }), + + // stage 1 proposal for export symmetry, + test({ code: 'export * as bar from "./bar"' + , parser: 'babel-eslint' }), + test({ code: 'export bar from "./bar"' + , parser: 'babel-eslint' }), + test({ code: 'import foo from "./jsx/MyUnCoolComponent.jsx"' + , options: ['case-sensitive'] }), ], invalid: [ From fa23c366221422dec8ea7f8e643ad45ec89ff388 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 10 Nov 2015 06:11:42 -0500 Subject: [PATCH 2/8] more test cleanup + one false-positive test for require --- src/rules/no-unresolved.js | 26 ++++++++--- tests/src/rules/no-unresolved.js | 76 ++++++++++++++++---------------- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/src/rules/no-unresolved.js b/src/rules/no-unresolved.js index e978a7ec1..0d3a71b03 100644 --- a/src/rules/no-unresolved.js +++ b/src/rules/no-unresolved.js @@ -6,18 +6,34 @@ import resolve from '../core/resolve' module.exports = function (context) { - function checkSource(node) { - if (node.source == null) return + function checkSourceValue(source) { + if (source == null) return - if (resolve(node.source.value, context) == null) { - context.report(node.source, - 'Unable to resolve path to module \'' + node.source.value + '\'.') + if (resolve(source.value, context) == null) { + context.report(source, + 'Unable to resolve path to module \'' + source.value + '\'.') } } + function checkSource(node) { + checkSourceValue(node.source) + } + return { 'ImportDeclaration': checkSource, 'ExportNamedDeclaration': checkSource, 'ExportAllDeclaration': checkSource } } + +module.exports.schema = [ + { + "type": "object", + "properties": { + "commonjs": { + "type": "boolean" + } + }, + "additionalProperties": false + } +] diff --git a/tests/src/rules/no-unresolved.js b/tests/src/rules/no-unresolved.js index 0ea09e576..e70a7daf5 100644 --- a/tests/src/rules/no-unresolved.js +++ b/tests/src/rules/no-unresolved.js @@ -47,39 +47,43 @@ ruleTester.run('no-unresolved', rule, { , parser: 'babel-eslint' }), test({ code: 'export bar from "./bar"' , parser: 'babel-eslint' }), - test({ code: 'import foo from "./jsx/MyUnCoolComponent.jsx"' - , options: ['case-sensitive'] }), + test({ code: 'import foo from "./jsx/MyUnCoolComponent.jsx"' }), + + // commonjs setting + test({ code: 'var foo = require("./bar")' + , options: [{ commonjs: true }]}), ], invalid: [ // should fail for jsx by default - test({ code: 'import * as foo from "jsx-module/foo"' - , errors: [ {message: 'Unable to resolve path to ' + - 'module \'jsx-module/foo\'.'} ] - }), + test({ + code: 'import * as foo from "jsx-module/foo"', + errors: [ {message: 'Unable to resolve path to ' + + 'module \'jsx-module/foo\'.'} ], + }), - test({ code: 'import reallyfake from "./reallyfake/module"' - , settings: { 'import/ignore': ['^\\./fake/'] } - , errors: [{ message: 'Unable to resolve path to module ' + - '\'./reallyfake/module\'.' }] - }), + test({ + code: 'import reallyfake from "./reallyfake/module"', + settings: { 'import/ignore': ['^\\./fake/'] }, + errors: [{ message: 'Unable to resolve path to module ' + + '\'./reallyfake/module\'.' }], + }), test({ code: "import bar from './baz';", errors: [{ message: "Unable to resolve path to module './baz'." - , type: 'Literal' - }]}), + , type: 'Literal' }], + }), test({ code: "import bar from './baz';" , errors: [{ message: "Unable to resolve path to module './baz'." - , type: 'Literal' - }] - }), + , type: 'Literal', + }] }), test({ code: "import bar from './empty-folder';", errors: [{ message: "Unable to resolve path to module './empty-folder'." - , type: 'Literal' + , type: 'Literal', }]}), // sanity check that this module is _not_ found without proper settings @@ -87,29 +91,27 @@ ruleTester.run('no-unresolved', rule, { code: "import { DEEP } from 'in-alternate-root';", errors: [{ message: 'Unable to resolve path to ' + "module 'in-alternate-root'." - , type: 'Literal' - }]}) + , type: 'Literal', + }]}), - , test({ code: 'export { foo } from "./does-not-exist"' - , errors: 1 - }) - , test({ code: 'export * from "./does-not-exist"' - , errors: 1 - }) + test({ code: 'export { foo } from "./does-not-exist"' + , errors: 1 }), + test({ + code: 'export * from "./does-not-exist"', + errors: 1, + }), // export symmetry proposal - , test({ code: 'export * as bar from "./does-not-exist"' + test({ code: 'export * as bar from "./does-not-exist"' , parser: 'babel-eslint' - , errors: 1 - }) - , test({ code: 'export bar from "./does-not-exist"' + , errors: 1, + }), + test({ code: 'export bar from "./does-not-exist"' , parser: 'babel-eslint' - , errors: 1 - }) - - , test({ code: 'import foo from "./jsx/MyUncoolComponent.jsx"' - , options: ['case-sensitive'] - , errors: 1 - }) - ] + , errors: 1, + }), + + test({ code: 'import foo from "./jsx/MyUncoolComponent.jsx"' + , errors: 1 }), + ], }) From 3511191634e14e545ee963f7da01c193d8a093c7 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 10 Nov 2015 06:23:18 -0500 Subject: [PATCH 3/8] Adapted mctep's alternate rule as an option on no-unresolved. --- src/rules/no-unresolved.js | 26 +++++++++++++++++++++++++- tests/src/rules/no-unresolved.js | 26 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/rules/no-unresolved.js b/src/rules/no-unresolved.js index 0d3a71b03..f1fb62d2c 100644 --- a/src/rules/no-unresolved.js +++ b/src/rules/no-unresolved.js @@ -15,15 +15,39 @@ module.exports = function (context) { } } + // for import-y declarations function checkSource(node) { checkSourceValue(node.source) } - return { + // for CommonJS `require` calls + // adapted from https://github.com/mctep/eslint-plugin-import/commit/acd4b4508d551f7f800fdd06e5c64ec01f3d1113 + function checkCommon(call) { + if (call.callee.type !== 'Identifier') return + if (call.callee.name !== 'require') return + if (call.arguments.length !== 1) return + + const modulePath = call.arguments[0] + if (modulePath.type !== 'Literal') return + if (typeof modulePath.value !== 'string') return + + checkSourceValue(modulePath) + } + + const visitors = { 'ImportDeclaration': checkSource, 'ExportNamedDeclaration': checkSource, 'ExportAllDeclaration': checkSource } + + if (context.options[0] != null) { + const { commonjs } = context.options[0] + if (commonjs) { + visitors['CallExpression'] = checkCommon + } + } + + return visitors } module.exports.schema = [ diff --git a/tests/src/rules/no-unresolved.js b/tests/src/rules/no-unresolved.js index e70a7daf5..0cf2921f2 100644 --- a/tests/src/rules/no-unresolved.js +++ b/tests/src/rules/no-unresolved.js @@ -52,6 +52,13 @@ ruleTester.run('no-unresolved', rule, { // commonjs setting test({ code: 'var foo = require("./bar")' , options: [{ commonjs: true }]}), + test({ code: 'require("./bar")' + , options: [{ commonjs: true }]}), + + // validate it doesn't check if turned off (default) + test({ code: 'require("./does-not-exist")' + , options: [{ commonjs: false }]}), + test({ code: 'require("./does-not-exist")' }), ], invalid: [ @@ -113,5 +120,24 @@ ruleTester.run('no-unresolved', rule, { test({ code: 'import foo from "./jsx/MyUncoolComponent.jsx"' , errors: 1 }), + + + // commonjs setting + test({ + code: 'var bar = require("./baz")', + options: [{ commonjs: true }], + errors: [{ + message: "Unable to resolve path to module './baz'.", + type: 'Literal', + }], + }), + test({ + code: 'require("./baz")', + options: [{ commonjs: true }], + errors: [{ + message: "Unable to resolve path to module './baz'.", + type: 'Literal', + }], + }), ], }) From 1a17a240c6dec3d714f1a25e882b5438e14d088c Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 10 Nov 2015 06:23:32 -0500 Subject: [PATCH 4/8] eqeqeq! --- .eslintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc b/.eslintrc index d3762ad9e..9e4a6f983 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,3 +8,4 @@ rules: quotes: [2, "single"] curly: [2, "multi-line"] comma-dangle: [2, always-multiline] + eqeqeq: [2, "allow-null"] From 96952c3093c10bbf641a0bdd6fdc1c4f6cb6d807 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 10 Nov 2015 06:33:02 -0500 Subject: [PATCH 5/8] man, the eslintrcs on this thing --- src/.eslintrc | 6 +++++- src/core/parse.js | 6 +++--- src/rules/imports-first.js | 4 ++-- src/rules/namespace.js | 2 +- src/rules/no-duplicates.js | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/.eslintrc b/src/.eslintrc index 285b044f4..a3e81e44f 100644 --- a/src/.eslintrc +++ b/src/.eslintrc @@ -1,7 +1,11 @@ --- -extends: eslint:recommended +extends: '../.eslintrc' + env: es6: true + ecmaFeatures: modules: true +rules: + comma-dangle: [1, "always-multiline"] diff --git a/src/core/parse.js b/src/core/parse.js index 647f51824..0651c141a 100644 --- a/src/core/parse.js +++ b/src/core/parse.js @@ -2,12 +2,12 @@ import fs from 'fs' const defaultParseOptions = { ecmaVersion: 6 // for espree, esprima. not needed // for babylon - , sourceType: "module" + , sourceType: 'module' } export default function parse(path, context) { const { settings } = context - , parser = settings['import/parser'] || "babylon" + , parser = settings['import/parser'] || 'babylon' const { parse } = require(parser) , options = Object.assign( {} @@ -15,7 +15,7 @@ export default function parse(path, context) { , settings['import/parse-options']) // detect and handle "jsx" ecmaFeature - if (context.ecmaFeatures && parser === "babylon") { + if (context.ecmaFeatures && parser === 'babylon') { const { jsx } = context.ecmaFeatures if (jsx && (!options.plugins || options.plugins.indexOf('jsx') < 0)) { if (!options.plugins) options.plugins = ['jsx'] diff --git a/src/rules/imports-first.js b/src/rules/imports-first.js index d9256999b..a9cb16867 100644 --- a/src/rules/imports-first.js +++ b/src/rules/imports-first.js @@ -1,12 +1,12 @@ module.exports = function (context) { return { - "Program": function (n) { + 'Program': function (n) { const body = n.body , absoluteFirst = context.options[0] === 'absolute-first' let last = -1 , anyRelative = false body.forEach(function (node, i){ - if (node.type === "ImportDeclaration") { + if (node.type === 'ImportDeclaration') { if (absoluteFirst) { if (/^\./.test(node.source.value)) { anyRelative = true diff --git a/src/rules/namespace.js b/src/rules/namespace.js index a12d4b90b..6c31481ed 100644 --- a/src/rules/namespace.js +++ b/src/rules/namespace.js @@ -90,7 +90,7 @@ module.exports = function (context) { for (let property of id.properties) { if (property.key.type !== 'Identifier') { context.report( property - , "Only destructure top-level names.") + , 'Only destructure top-level names.') } else if (!namespace.has(property.key.name)) { context.report( property , message(property.key, init) diff --git a/src/rules/no-duplicates.js b/src/rules/no-duplicates.js index 8d34cf5a3..81dd45124 100644 --- a/src/rules/no-duplicates.js +++ b/src/rules/no-duplicates.js @@ -3,7 +3,7 @@ import resolve from '../core/resolve' module.exports = function (context) { const imported = new Map() return { - "ImportDeclaration": function (n) { + 'ImportDeclaration': function (n) { // resolved path will cover aliased duplicates let resolvedPath = resolve(n.source.value, context) || n.source.value @@ -14,7 +14,7 @@ module.exports = function (context) { } }, - "Program:exit": function () { + 'Program:exit': function () { for (let [module, nodes] of imported.entries()) { if (nodes.size > 1) { for (let node of nodes) { From dadff67b0a428799c8bd78854cfce16737f84693 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 10 Nov 2015 06:45:22 -0500 Subject: [PATCH 6/8] no-unresolved: also optionally sensitive to AMD, now --- src/rules/no-unresolved.js | 42 +++++++++++++++++++++++-------- tests/src/rules/no-unresolved.js | 43 ++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 13 deletions(-) diff --git a/src/rules/no-unresolved.js b/src/rules/no-unresolved.js index f1fb62d2c..4c54973b6 100644 --- a/src/rules/no-unresolved.js +++ b/src/rules/no-unresolved.js @@ -34,16 +34,37 @@ module.exports = function (context) { checkSourceValue(modulePath) } + function checkAMD(call) { + if (call.callee.type !== 'Identifier') return + if (call.callee.name !== 'require' && + call.callee.name !== 'define') return + if (call.arguments.length !== 2) return + + const modules = call.arguments[0] + if (modules.type !== 'ArrayExpression') return + + for (let element of modules.elements) { + if (element.type !== 'Literal') continue + if (typeof element.value !== 'string') continue + + checkSourceValue(element) + } + } + const visitors = { 'ImportDeclaration': checkSource, 'ExportNamedDeclaration': checkSource, - 'ExportAllDeclaration': checkSource + 'ExportAllDeclaration': checkSource, } if (context.options[0] != null) { - const { commonjs } = context.options[0] - if (commonjs) { - visitors['CallExpression'] = checkCommon + const { commonjs, amd } = context.options[0] + + if (commonjs || amd) { + visitors['CallExpression'] = function (call) { + if (commonjs) checkCommon(call) + if (amd) checkAMD(call) + } } } @@ -52,12 +73,11 @@ module.exports = function (context) { module.exports.schema = [ { - "type": "object", - "properties": { - "commonjs": { - "type": "boolean" - } + 'type': 'object', + 'properties': { + 'commonjs': { 'type': 'boolean' }, + 'amd': { 'type': 'boolean' }, }, - "additionalProperties": false - } + 'additionalProperties': false, + }, ] diff --git a/tests/src/rules/no-unresolved.js b/tests/src/rules/no-unresolved.js index 0cf2921f2..fbda65e60 100644 --- a/tests/src/rules/no-unresolved.js +++ b/tests/src/rules/no-unresolved.js @@ -54,11 +54,21 @@ ruleTester.run('no-unresolved', rule, { , options: [{ commonjs: true }]}), test({ code: 'require("./bar")' , options: [{ commonjs: true }]}), - - // validate it doesn't check if turned off (default) test({ code: 'require("./does-not-exist")' , options: [{ commonjs: false }]}), test({ code: 'require("./does-not-exist")' }), + + // amd setting + test({ code: 'require(["./bar"], function (bar) {})' + , options: [{ amd: true }]}), + test({ code: 'define(["./bar"], function (bar) {})' + , options: [{ amd: true }]}), + test({ code: 'require(["./does-not-exist"], function (bar) {})' + , options: [{ amd: false }]}), + // don't validate without callback param + test({ code: 'require(["./does-not-exist"])' + , options: [{ amd: true }]}), + test({ code: 'define(["./does-not-exist"], function (bar) {})' }), ], invalid: [ @@ -139,5 +149,34 @@ ruleTester.run('no-unresolved', rule, { type: 'Literal', }], }), + + // amd + test({ + code: 'require(["./baz"], function (bar) {})', + options: [{ amd: true }], + errors: [{ + message: "Unable to resolve path to module './baz'.", + type: 'Literal', + }], + }), + test({ + code: 'define(["./baz"], function (bar) {})', + options: [{ amd: true }], + errors: [{ + message: "Unable to resolve path to module './baz'.", + type: 'Literal', + }], + }), + test({ + code: 'define(["./baz", "./bar", "./does-not-exist"], function (bar) {})', + options: [{ amd: true }], + errors: [{ + message: "Unable to resolve path to module './baz'.", + type: 'Literal', + },{ + message: "Unable to resolve path to module './does-not-exist'.", + type: 'Literal', + }], + }), ], }) From ebb4403556e5e14baaa6df1bd60d417407c104b6 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 10 Nov 2015 06:50:41 -0500 Subject: [PATCH 7/8] linty-fresh --- .eslintrc | 2 +- src/core/parse.js | 2 +- src/rules/default.js | 2 +- src/rules/export.js | 2 +- src/rules/imports-first.js | 12 +++++++++--- src/rules/named.js | 2 +- src/rules/namespace.js | 2 +- src/rules/no-duplicates.js | 2 +- src/rules/no-errors.js | 2 +- src/rules/no-named-as-default.js | 2 +- src/rules/no-require.js | 4 ++-- 11 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9e4a6f983..b63d962ad 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,7 +3,7 @@ extends: eslint:recommended env: node: true rules: - max-len: [1, 80, 2] + max-len: [1, 99, 2] semi: [2, "never"] quotes: [2, "single"] curly: [2, "multi-line"] diff --git a/src/core/parse.js b/src/core/parse.js index 0651c141a..f8dfcb0c9 100644 --- a/src/core/parse.js +++ b/src/core/parse.js @@ -2,7 +2,7 @@ import fs from 'fs' const defaultParseOptions = { ecmaVersion: 6 // for espree, esprima. not needed // for babylon - , sourceType: 'module' + , sourceType: 'module', } export default function parse(path, context) { diff --git a/src/rules/default.js b/src/rules/default.js index d2bb14aa2..b107ee13b 100644 --- a/src/rules/default.js +++ b/src/rules/default.js @@ -24,6 +24,6 @@ module.exports = function (context) { return { 'ImportDeclaration': checkDefault.bind(null, 'ImportDefaultSpecifier'), - 'ExportNamedDeclaration': checkDefault.bind(null, 'ExportDefaultSpecifier') + 'ExportNamedDeclaration': checkDefault.bind(null, 'ExportDefaultSpecifier'), } } diff --git a/src/rules/export.js b/src/rules/export.js index 3695698f0..acd592e26 100644 --- a/src/rules/export.js +++ b/src/rules/export.js @@ -69,6 +69,6 @@ module.exports = function (context) { context.report(node, `Multiple exports of name '${name}'.`) } } - } + }, } } diff --git a/src/rules/imports-first.js b/src/rules/imports-first.js index a9cb16867..8e044e6fb 100644 --- a/src/rules/imports-first.js +++ b/src/rules/imports-first.js @@ -11,14 +11,20 @@ module.exports = function (context) { if (/^\./.test(node.source.value)) { anyRelative = true } else if (anyRelative) { - context.report(node.source, 'Absolute imports should come before relative imports.') + context.report({ + node: node.source, + message: 'Absolute imports should come before relative imports.', + }) } } if (i !== ++last) { - context.report(node, 'Import in body of module; reorder to top.') + context.report({ + node, + message: 'Import in body of module; reorder to top.', + }) } } }) - } + }, } } diff --git a/src/rules/named.js b/src/rules/named.js index d04456c00..bd1002cdb 100644 --- a/src/rules/named.js +++ b/src/rules/named.js @@ -33,7 +33,7 @@ module.exports = function (context) { 'ExportNamedDeclaration': checkSpecifiers.bind( null , 'local' , 'ExportSpecifier' - ) + ), } } diff --git a/src/rules/namespace.js b/src/rules/namespace.js index 6c31481ed..1d4775c41 100644 --- a/src/rules/namespace.js +++ b/src/rules/namespace.js @@ -97,6 +97,6 @@ module.exports = function (context) { ) } } - } + }, } } diff --git a/src/rules/no-duplicates.js b/src/rules/no-duplicates.js index 81dd45124..e25695cb9 100644 --- a/src/rules/no-duplicates.js +++ b/src/rules/no-duplicates.js @@ -22,6 +22,6 @@ module.exports = function (context) { } } } - } + }, } } diff --git a/src/rules/no-errors.js b/src/rules/no-errors.js index c1a8da4af..9d3582a59 100644 --- a/src/rules/no-errors.js +++ b/src/rules/no-errors.js @@ -23,6 +23,6 @@ module.exports = function (context) { if (imports.errors.length > 0) { context.report(node.source, message(node, imports.errors)) } - } + }, } } diff --git a/src/rules/no-named-as-default.js b/src/rules/no-named-as-default.js index 442338747..eea5f2e56 100644 --- a/src/rules/no-named-as-default.js +++ b/src/rules/no-named-as-default.js @@ -19,6 +19,6 @@ module.exports = function (context) { } return { 'ImportDefaultSpecifier': checkDefault.bind(null, 'local'), - 'ExportDefaultSpecifier': checkDefault.bind(null, 'exported') + 'ExportDefaultSpecifier': checkDefault.bind(null, 'exported'), } } diff --git a/src/rules/no-require.js b/src/rules/no-require.js index 71f537394..35a3d3cc3 100644 --- a/src/rules/no-require.js +++ b/src/rules/no-require.js @@ -13,8 +13,8 @@ module.exports = function (context) { // keeping it simple: all 1-string-arg `require` calls are reported context.report({ node: call.callee, - message: `CommonJS require of module '${module.value}'.` + message: `CommonJS require of module '${module.value}'.`, }) - } + }, } } From 5a71c8969c5776ecd842bb442ba5aa25d5ea86a3 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 10 Nov 2015 08:59:37 -0500 Subject: [PATCH 8/8] documented AMD + CommonJS report/resolution options under no-unresolved --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e5dd8571b..5302133e3 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ plugins: - import rules: - import/no-unresolved: 2 + import/no-unresolved: [2, {commonjs: true, amd: true}] import/named: 2 import/namespace: 2 import/default: 2 @@ -73,6 +73,10 @@ as defined by standard Node `require.resolve` behavior. See [settings](#settings) for customization options for the resolution (i.e. additional filetypes, `NODE_PATH`, etc.) +This rule can also optionally report on unresolved modules in CommonJS `require('./foo')` calls and AMD `require(['./foo'], function (foo){...})` and `define(['./foo'], function (foo){...})`. + +To enable this, send `{ commonjs: true/false, amd: true/false }` as a rule option. +Both are disabled by default. ### `named`