Skip to content

Commit 2d48704

Browse files
committed
fix #213: fix a bug in no-import-test-files
1 parent e69bb71 commit 2d48704

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

rules/no-import-test-files.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,16 @@ const create = context => {
6565

6666
return {
6767
ImportDeclaration: node => {
68-
validateImportPath(node, node.source.value);
68+
if (typeof node.source.value === 'string') {
69+
validateImportPath(node, node.source.value);
70+
}
6971
},
7072
CallExpression: node => {
7173
if (!(node.callee.type === 'Identifier' && node.callee.name === 'require')) {
7274
return;
7375
}
7476

75-
if (node.arguments[0] && node.arguments[0].type === 'Literal') {
77+
if (node.arguments[0] && node.arguments[0].type === 'Literal' && typeof node.arguments[0].value === 'string') {
7678
validateImportPath(node, node.arguments[0].value);
7779
}
7880
}

test/no-import-test-files.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ ruleTester.run('no-import-test-files', rule, {
5757
{
5858
code: 'import * as highlight from \'highlight.js\'',
5959
filename: toPath('lib/foo.test.js')
60+
},
61+
{
62+
code: 'const foo = require(\'\')'
63+
},
64+
{
65+
code: 'const foo = require(false)'
6066
}
6167
],
6268
invalid: [

0 commit comments

Comments
 (0)