Skip to content

Commit

Permalink
rule no-invalid-xpath: fix a eslint crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Manu1400 committed Apr 13, 2019
1 parent 8b135af commit 037999a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/no-invalid-xpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const create = context => {
'CallExpression[callee.object.name=\'document\'][callee.property.name=\'evaluate\'][arguments.length > 0]': node => {
const xpathExpression = node.arguments[0].value

if (typeof xpathExpression != "string") {
return;
}

if (xpathExpression.length > 100) {
context.report({node, message: "large XPath expression detected"})
}
Expand Down
28 changes: 28 additions & 0 deletions lib/rules/no-reuse-function-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const create = context => {
return {
"FunctionDeclaration[id.name] VariableDeclarator[id.name]": node => {
const functionName = node.id.name;

if (functionName != node.parent.parent.parent.id.name) {
return;
}
context.report({
node,
message: `valid but see https://gist.github.com/bakkot/24c28836580a94989084`,
});
}
};
};

module.exports = {
create,
meta: {
docs: {
description: "TODO"
//url: getDocsUrl(__filename)
},
fixable: 'code'
}
};
4 changes: 4 additions & 0 deletions tests/lib/rules/no-invalid-xpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ ruleTester.run("no-invalid-xpath", rule, {
{
code: "document.evaluate(\"/html/body[0] | /html[0]\", document)",
},
// var str = "//test";\ndocument.evaluate(str, body);
{
code: "var t = ''; \n document.evaluate(t, body);"
},
],

invalid: [
Expand Down
46 changes: 46 additions & 0 deletions tests/lib/rules/no-reuse-function-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @fileoverview
* @author Emmanuel
*/
"use strict";

const rule = require("../../../lib/rules/no-reuse-function-name")
const RuleTester = require("eslint").RuleTester

var ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2017 } });
ruleTester.run("no-reuse-function-name", rule, {

valid: [
{
code: "function x(){const a = 1;}",
},
{
code: "function a(){const x = 1;}",
},
{
code: "const x = function (){const x = 1;}",
},
// from https://gist.github.com/bakkot/24c28836580a94989084
{
code: "(function x(){\"use strict\"; x = 1;}());", // TypeError in Chrome
},
{
code: "(function x(){x = 1; return x !== 1;}());", // write fails silently; function returns true
},
],

invalid: [
{
code: "function x(){const x = 1;}",
errors: [{
message: "valid but see https://gist.github.com/bakkot/24c28836580a94989084",
}]
},
{
code: "function x(){const a = 1; const x = 2}",
errors: [{
message: "valid but see https://gist.github.com/bakkot/24c28836580a94989084",
}]
},
]
});

0 comments on commit 037999a

Please sign in to comment.