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 }] }