New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaking: check unnamed default export in func-names (fixes #12194) #12195
Breaking: check unnamed default export in func-names (fixes #12194) #12195
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good. Just left one question. 😄
parserOptions: { sourceType: "module", ecmaVersion: 6 } | ||
}, | ||
{ | ||
code: "export default function foo() {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this valid? The option is "never"
but the function has a name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would require more checks, foo
is here a declaration and can be used from within the module. And even if that's not the case, I believe this would break some builds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reasoning is that, under option never, function f() is allowed, export function f() is allowed, so likewise export default function f() should be allowed.
I understand in some perspective this should be reported, so this case is controvesial. Not reporting in this case would make both sides happy.
Just to note that this PR at the moment also changes how the rule works with function expressions when the option is Also, all 3 changes would be 'false negatives' if this is seen as a bug, and the message should certainly start with |
How do we want to proceed here? It looks like this was marked as a breaking change rather than a semver-minor bug fix, but it's not entirely clear why. |
@mdjermanovic Can we merge this? |
An overview of the new behavior after this PR: /*eslint func-names: ["error", "always"]*/
export default function () {} // error (*)
export default function foo() {} // ok
export default (function (){}); // error
export default (function foo(){}); // ok /*eslint func-names: ["error", "as-needed"]*/
export default function () {} // error (*)
export default function foo() {} // ok
export default (function (){}); // error (*)
export default (function foo(){}); // ok /*eslint func-names: ["error", "never"]*/
export default function () {} // ok
export default function foo () {} // ok!
export default (function (){}); // ok
export default (function foo(){}); // error
There are three
Also, Questions:
|
In today's TSC meeting, we added this to the v7.0.0 release! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code LGTM!
Should we add a short note that as-needed
requires names for functions in export default
, somewhere in the documentation (maybe in the ### as-needed
section)?
The description for the option is now inaccurate:
"as-needed" requires function expressions to have a name, if the name cannot be assigned automatically in an ES6 environment
so it might be good to clarify the behavior, as this in an exception?
Maybe also a short note that always
and as-needed
options also apply to function declarations in export default
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Thanks for contributing to ESLint! |
) (eslint#12195) * Breaking: check unnamed default export in func-names (fixes eslint#12194) * docs: add that default export functions are checked * Revert "docs: add that default export functions are checked" This reverts commit 036ce53. * docs: add a note that export default functions needs name
fixes #12194
What is the purpose of this pull request? (put an "X" next to item)
[X] Bug fix (template)
What changes did you make? (Give an overview)
Start report code like
export default function() {}
whenalways
oras-needed
.Is there anything you'd like reviewers to focus on?
Yes.