Skip to content

Commit

Permalink
ignore magic AMD modules (fixes #129)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Nov 29, 2015
1 parent f786e88 commit 633205c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/rules/no-unresolved.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module.exports = function (context) {
if (element.type !== 'Literal') continue
if (typeof element.value !== 'string') continue

if (element.value === 'require' ||
element.value === 'exports') continue // magic modules: http://git.io/vByan

checkSourceValue(element)
}
}
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/src/rules/named.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ruleTester.run('named', rule, {
test({ code: 'import { foo } from "crypto"' }),
test({ code: 'import { zoob } from "a"' }),

test({ code: 'import { someThing } from "./module"' }),
test({ code: 'import { someThing } from "./test-module"' }),

// node_modules/a only exports 'foo', should be ignored though
test({ code: 'import { zoob } from "a"' }),
Expand Down Expand Up @@ -91,8 +91,8 @@ ruleTester.run('named', rule, {
, settings: { 'import/ignore': [] }
, errors: [ error('zoob', 'a') ] }),

test({ code: 'import { somethingElse } from "./module"'
, errors: [ error('somethingElse', './module') ] }),
test({ code: 'import { somethingElse } from "./test-module"'
, errors: [ error('somethingElse', './test-module') ] }),

test({code: 'import {a, b, d} from "./common"',
errors: [ error('a', './common')
Expand Down
6 changes: 5 additions & 1 deletion tests/src/rules/no-unresolved.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function runResolverTests(resolver) {
valid: [
rest({ code: 'import foo from "./bar";' }),
rest({ code: "import bar from './bar.js';" }),
rest({ code: "import {someThing} from './module';" }),
rest({ code: "import {someThing} from './test-module';" }),
rest({ code: "import fs from 'fs';" }),

rest({ code: 'import * as foo from "a"' }),
Expand Down Expand Up @@ -55,6 +55,10 @@ function runResolverTests(resolver) {
, options: [{ amd: true }]}),
rest({ code: 'require(["./does-not-exist"], function (bar) {})'
, options: [{ amd: false }]}),
// magic modules: http://git.io/vByan
rest({ code: 'define(["require", "exports", "module"], function (r, e, m) { })'
, options: [{ amd: true }]}),

// don't validate without callback param
rest({ code: 'require(["./does-not-exist"])'
, options: [{ amd: true }]}),
Expand Down

0 comments on commit 633205c

Please sign in to comment.