From 5775b06a74573cbe068bea56b1d2376421f5e831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgardo=20Avil=C3=A9s?= Date: Thu, 27 Feb 2020 20:06:29 -0500 Subject: [PATCH] Fix: Optionally allow underscores in member names (#11972) --- lib/rules/no-underscore-dangle.js | 2 +- tests/lib/rules/no-underscore-dangle.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-underscore-dangle.js b/lib/rules/no-underscore-dangle.js index 1468198ac4e..cac594e1004 100644 --- a/lib/rules/no-underscore-dangle.js +++ b/lib/rules/no-underscore-dangle.js @@ -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", diff --git a/tests/lib/rules/no-underscore-dangle.js b/tests/lib/rules/no-underscore-dangle.js index afc9813673d..4baef3e82da 100644 --- a/tests/lib/rules/no-underscore-dangle.js +++ b/tests/lib/rules/no-underscore-dangle.js @@ -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 }] }