Skip to content

Commit

Permalink
Fix: Optionally allow underscores in member names (#11972)
Browse files Browse the repository at this point in the history
  • Loading branch information
eaviles committed Feb 28, 2020
1 parent e997f32 commit 5775b06
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-underscore-dangle.js
Expand Up @@ -205,7 +205,7 @@ module.exports = {
const identifier = node.key.name;
const isMethod = node.type === "MethodDefinition" || node.type === "Property" && node.method;

if (typeof identifier !== "undefined" && enforceInMethodNames && isMethod && hasTrailingUnderscore(identifier)) {
if (typeof identifier !== "undefined" && enforceInMethodNames && isMethod && hasTrailingUnderscore(identifier) && !isAllowed(identifier)) {
context.report({
node,
messageId: "unexpectedUnderscore",
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/no-underscore-dangle.js
Expand Up @@ -37,6 +37,7 @@ ruleTester.run("no-underscore-dangle", rule, {
{ code: "class foo { onClick_() { } }", parserOptions: { ecmaVersion: 6 } },
{ code: "const o = { _onClick() { } }", parserOptions: { ecmaVersion: 6 } },
{ code: "const o = { onClick_() { } }", parserOptions: { ecmaVersion: 6 } },
{ code: "const o = { _onClick() { } }", options: [{ allow: ["_onClick"], enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 } },
{ code: "const o = { _foo: 'bar' }", parserOptions: { ecmaVersion: 6 } },
{ code: "const o = { foo_: 'bar' }", parserOptions: { ecmaVersion: 6 } },
{ code: "this.constructor._bar", options: [{ allowAfterThisConstructor: true }] }
Expand Down

0 comments on commit 5775b06

Please sign in to comment.