diff --git a/lib/rules/empty-script.js b/lib/rules/empty-script.js index 78eccd6..57c42dc 100644 --- a/lib/rules/empty-script.js +++ b/lib/rules/empty-script.js @@ -5,6 +5,10 @@ * @author Alexander Afanasyev */ +function isLiteral (node) { + return node.type === 'Literal' +} + module.exports = { meta: { schema: [] @@ -29,7 +33,12 @@ module.exports = { return } - var firstArgumentNonEmpty = argumentExists && node.arguments[0].value + var firstArgument = node.arguments[0] + if (!isLiteral(firstArgument)) { + return + } + + var firstArgumentNonEmpty = firstArgument.value if (!firstArgumentNonEmpty) { context.report({ node: property, diff --git a/test/rules/empty-script.js b/test/rules/empty-script.js index 5302816..7f21413 100644 --- a/test/rules/empty-script.js +++ b/test/rules/empty-script.js @@ -10,7 +10,9 @@ eslintTester.run('empty-script', rule, { 'browser.executeScript("var a = 1;");', 'browser.executeAsyncScript("var a = 1;");', 'var tag = browser.executeScript("return arguments[0].tagName", el);', - 'browser.executeAsyncScript("var callback = arguments[arguments.length - 1];");' + 'browser.executeAsyncScript("var callback = arguments[arguments.length - 1];");', + 'var script = "var a = 1"; browser.executeScript(clientScript);', + 'function clientScript(){ return 1; }; browser.executeScript(clientScript);' ], invalid: [