Skip to content

Commit

Permalink
Update: func-names as-needed false negative with AssignmentPattern (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Feb 28, 2020
1 parent afde78b commit 9038a29
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/func-names.js
Expand Up @@ -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);
}

/**
Expand Down
48 changes: 48 additions & 0 deletions tests/lib/rules/func-names.js
Expand Up @@ -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"],
Expand Down

0 comments on commit 9038a29

Please sign in to comment.