diff --git a/tests/src/rules/no-unresolved.js b/tests/src/rules/no-unresolved.js index 5b4f6ae53..5921f28b3 100644 --- a/tests/src/rules/no-unresolved.js +++ b/tests/src/rules/no-unresolved.js @@ -150,6 +150,23 @@ function runResolverTests(resolver) { }], }), + rest({ + code: 'var bar = require.resolve("./baz")', + options: [{ commonjs: true }], + errors: [{ + message: "Unable to resolve path to module './baz'.", + type: 'Literal', + }], + }), + rest({ + code: 'require.resolve("./baz")', + options: [{ commonjs: true }], + errors: [{ + message: "Unable to resolve path to module './baz'.", + type: 'Literal', + }], + }), + // amd rest({ code: 'require(["./baz"], function (bar) {})', diff --git a/utils/moduleVisitor.js b/utils/moduleVisitor.js index 2e736242e..7be5ef124 100644 --- a/utils/moduleVisitor.js +++ b/utils/moduleVisitor.js @@ -49,8 +49,15 @@ exports.default = function visitModules(visitor, options) { // for CommonJS `require` calls // adapted from @mctep: http://git.io/v4rAu function checkCommon(call) { - if (call.callee.type !== 'Identifier') return - if (call.callee.name !== 'require') return + if (call.callee.type === 'Identifier') { + if (call.callee.name !== 'require') return + } + else if (call.callee.type === 'MemberExpression') { + if (call.callee.object.name !== 'require') return + if (call.callee.property.name !== 'resolve') return + } + else return + if (call.arguments.length !== 1) return const modulePath = call.arguments[0]