Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/src/rules/no-unresolved.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {})',
Expand Down
11 changes: 9 additions & 2 deletions utils/moduleVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down