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
func-names does not report default exported function #12194
Comments
Thank you for your report. I agreed. In technical, |
Would this be a bug fix or an enhancement, because by the documentation the rule works only with function expressions. |
Indeed, it's a concern that the fix has big impact. Personally, this is a bug -- I think that the rule intends the naming convention of functions (regardless of expressions/declarations) as we consider the fact that we could not omit function names on function declarations at the time the rule created. I can remember that the AST of If now is 2015, it's a bug fix definitely. but now...? I'd like to hear the opinion of the rest members of the team. |
I think that the following should be also discussed, because the proposed change doesn't treat function declarations in the same way as the rule at the moment treats function expressions when the option is
The actual code is explicitly treating /*eslint func-names: ["error", "as-needed"]*/
export default (function () {}) // no error but this is an error: /*eslint func-names: ["error", "always"]*/
export default (function () {}) // error This is probably technically correct by the documentation, though if the rule's purpose is to have meaningful names in the stack trace (is this assumption correct? the rule is in the |
Good point. I agree that to report anonymous default exported function expressions makes sense. |
A good thing for this is that |
I think it would be best to treat this as a breaking change or create an option, personally- just in case. I can see the case for it being a bug, but I'm concerned about potential large impact. |
Creating an option - avoids breaking users' CI for now, but adds a vestige that burdens all future users. |
This looks more like 2 options? One to enforce the rule on function declarations, the other to change |
I prefer changing the default behavior on 7.0.0. I'm not sure if there are the cases we use the options. |
Adding the |
) (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
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
func-names: [2, "always"]
orfunc-names: [2, "as-needed"]
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
https://eslint.org/demo#eyJ0ZXh0IjoiLyogZXNsaW50IGZ1bmMtbmFtZXM6IFsyLCAnYXMtbmVlZGVkJ10gKi9cbi8vIG9yICAnYWx3YXlzJ1xuXG5leHBvcnQgZGVmYXVsdCBmdW5jdGlvbiAoKSB7fVxuIiwib3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFWZXJzaW9uIjo5LCJzb3VyY2VUeXBlIjoibW9kdWxlIiwiZWNtYUZlYXR1cmVzIjp7fX0sInJ1bGVzIjp7fSwiZW52Ijp7fX19
What did you expect to happen?
Unnamed function to be reported.
What actually happened? Please include the actual, raw output from ESLint.
No error is reported.
Are you willing to submit a pull request to fix this bug?
Yes please.
Notes
The main purpose of func-names is to avoid unhelpful names like "anonymous" popping up in stack trace or profiling chart. In the case of unnamed default export, the function names will be
_default
for babel transformed code, ordefault
for node 12 experimental modules. These names are uninformative for debugging. So func-names should report this case.The text was updated successfully, but these errors were encountered: