Skip to content

Commit

Permalink
Prevent the no-import-test rule to crash when imported path is not …
Browse files Browse the repository at this point in the history
…a string (#228)
  • Loading branch information
GMartigny authored and sindresorhus committed May 18, 2019
1 parent 9ec0565 commit 1c8ca97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion rules/no-import-test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ function getProjectInfo() {

function createImportValidator(context, files, projectInfo, filename) {
return (node, importPath) => {
if (!importPath || typeof importPath !== 'string') {
return;
}

const isImportingExternalModule = isExternalModule(importPath);
if (isImportingExternalModule) {
return;
Expand Down Expand Up @@ -70,7 +74,7 @@ const create = context => {
return;
}

if (node.arguments[0] && node.arguments[0].type === 'Literal') {
if (node.arguments[0]) {
validateImportPath(node, node.arguments[0].value);
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/no-import-test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ ruleTester.run('no-import-test-files', rule, {
{
code: 'var highlight = require(\'highlight.js\')',
filename: toPath('test/index.js')
}
},
'const value = require(true);',
'const value = require();'
],
invalid: [
{
Expand Down

0 comments on commit 1c8ca97

Please sign in to comment.