Skip to content

Commit

Permalink
Fix arrow function name
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 11, 2020
1 parent 66e6653 commit a9657e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion rules/consistent-function-scoping.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,17 @@ const create = context => {
':matches(ArrowFunctionExpression, FunctionDeclaration):exit': node => {
if (!hasJsx && !checkNode(node, scopeManager)) {
const functionType = node.type === 'ArrowFunctionExpression' ? 'arrow function' : 'function';
const functionName = node.id && node.id.name;
let functionName = '';
if (node.id) {
functionName = node.id.name;
} else if (
node.parent &&
node.parent.type === 'VariableDeclarator' &&
node.parent.id &&
node.parent.id.type === 'Identifier'
) {
functionName = node.parent.id.name;
}

context.report({
node,
Expand Down
2 changes: 1 addition & 1 deletion test/consistent-function-scoping.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ ruleTester.run('consistent-function-scoping', rule, {
}
}
`,
errors: [createError({arrow: true})]
errors: [createError({name: 'doBar', arrow: true})]
},
{
code: outdent`
Expand Down

0 comments on commit a9657e1

Please sign in to comment.