forked from babel/babel
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
@babel/eslint-plugin/no-undef
for accessor props
- Loading branch information
1 parent
3f66d23
commit 154ba7b
Showing
6 changed files
with
46 additions
and
1 deletion.
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,20 @@ | ||
const ruleComposer = require("eslint-rule-composer"); | ||
const eslint = require("eslint"); | ||
|
||
const rule = new eslint.Linter().getRules().get("no-undef"); | ||
|
||
/** | ||
* Returns whether a node is under a decorator or not. | ||
* @param {ASTNode} node CallExpression node | ||
* @returns {Boolean} Returns true if the node is under a decorator. | ||
*/ | ||
function isAccessorField(node) { | ||
return ( | ||
node.parent.type === "ClassAccessorProperty" && node.parent.key === node | ||
); | ||
} | ||
|
||
module.exports = ruleComposer.filterReports( | ||
rule, | ||
problem => !isAccessorField(problem.node), | ||
); |
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,20 @@ | ||
import rule from "../../lib/rules/no-undef.cjs"; | ||
import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester.js"; | ||
|
||
const ruleTester = new RuleTester(); | ||
ruleTester.run("@babel/no-undef", rule, { | ||
valid: [ | ||
{ code: "class MyClass { accessor x = 2 }" }, | ||
{ code: "using x = 2; x;" }, | ||
], | ||
invalid: [ | ||
{ | ||
code: "class MyClass { accessor x = y }", | ||
errors: [{ message: "'y' is not defined." }], | ||
}, | ||
{ | ||
code: "{ using x = 2; } x;", | ||
errors: [{ message: "'x' is not defined." }], | ||
}, | ||
], | ||
}); |
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
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