Skip to content

Commit

Permalink
Merge pull request #95 from ext/bugfix/94-empty-script-fn
Browse files Browse the repository at this point in the history
fix(rules): handle functions passed to executeScript
  • Loading branch information
alecxe authored Sep 18, 2019
2 parents 08d0c4a + 78f2cd9 commit bdea5d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/rules/empty-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* @author Alexander Afanasyev
*/

function isLiteral (node) {
return node.type === 'Literal'
}

module.exports = {
meta: {
schema: []
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion test/rules/empty-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit bdea5d5

Please sign in to comment.