-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rule no-invalid-xpath: fix a eslint crash
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}] | ||
}, | ||
] | ||
}); |