From 9038a29569548c0563c29dbe9f7dae280ff3addd Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Fri, 28 Feb 2020 21:48:23 +0100 Subject: [PATCH] Update: func-names `as-needed` false negative with AssignmentPattern (#12932) --- lib/rules/func-names.js | 2 +- tests/lib/rules/func-names.js | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/rules/func-names.js b/lib/rules/func-names.js index 4416dd35e6e..ecfedb9e0e9 100644 --- a/lib/rules/func-names.js +++ b/lib/rules/func-names.js @@ -119,7 +119,7 @@ module.exports = { (parent.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.init === node) || (parent.type === "Property" && parent.value === node) || (parent.type === "AssignmentExpression" && parent.left.type === "Identifier" && parent.right === node) || - (parent.type === "AssignmentPattern" && parent.right === node); + (parent.type === "AssignmentPattern" && parent.left.type === "Identifier" && parent.right === node); } /** diff --git a/tests/lib/rules/func-names.js b/tests/lib/rules/func-names.js index 94a5e335118..bf930eecfc9 100644 --- a/tests/lib/rules/func-names.js +++ b/tests/lib/rules/func-names.js @@ -392,6 +392,54 @@ ruleTester.run("func-names", rule, { endColumn: 21 }] }, + { + code: "({ a: obj.prop = function(){} } = foo);", + options: ["as-needed"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + messageId: "unnamed", + type: "FunctionExpression", + line: 1, + column: 18, + endColumn: 26 + }] + }, + { + code: "[obj.prop = function(){}] = foo;", + options: ["as-needed"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + messageId: "unnamed", + type: "FunctionExpression", + line: 1, + column: 13, + endColumn: 21 + }] + }, + { + code: "var { a: [b] = function(){} } = foo;", + options: ["as-needed"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + messageId: "unnamed", + type: "FunctionExpression", + line: 1, + column: 16, + endColumn: 24 + }] + }, + { + code: "function foo({ a } = function(){}) {};", + options: ["as-needed"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + messageId: "unnamed", + type: "FunctionExpression", + line: 1, + column: 22, + endColumn: 30 + }] + }, { code: "var x = function foo() {};", options: ["never"],