Navigation Menu

Skip to content
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

Closed
golopot opened this issue Aug 31, 2019 · 11 comments · Fixed by #12195
Closed

func-names does not report default exported function #12194

golopot opened this issue Aug 31, 2019 · 11 comments · Fixed by #12195
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion breaking This change is backwards-incompatible bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects

Comments

@golopot
Copy link
Contributor

golopot commented Aug 31, 2019

Tell us about your environment

  • ESLint Version: 6.3.0
  • Node Version: 12

What parser (default, Babel-ESLint, etc.) are you using?
default

Please show your full configuration:
func-names: [2, "always"] or
func-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.

/* eslint func-names: [2, 'as-needed'] */
// or  'always'

export default function () {}

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, or default for node 12 experimental modules. These names are uninformative for debugging. So func-names should report this case.

@golopot golopot added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Aug 31, 2019
@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Aug 31, 2019
@mysticatea
Copy link
Member

Thank you for your report.

I agreed.

In technical, func-names rule has checked only function expressions, but export default function () {} is a function declaration. I guess that this is an overlook in ES6 updates.

@mdjermanovic
Copy link
Member

In technical, func-names rule has checked only function expressions, but export default function () {} is a function declaration. I guess that this is an overlook in ES6 updates.

Would this be a bug fix or an enhancement, because by the documentation the rule works only with function expressions.

@mysticatea
Copy link
Member

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 export default function () {} was FunctionExpression at first, but it has been fixed in order to distinguish export default function f() {} and export default (function f() {});.

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.

@mysticatea mysticatea added the enhancement This change enhances an existing feature of ESLint label Aug 31, 2019
@mdjermanovic
Copy link
Member

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 as-needed:

"as-needed" requires function expressions to have a name, if the name cannot be assigned automatically in an ES6 environment

The actual code is explicitly treating export default (function () {}) as an automatically assigned name in this line, and for example this is not an error:

/*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 Stylistic Issues category) it makes sense to change this as well.

@mysticatea
Copy link
Member

mysticatea commented Sep 3, 2019

Good point. I agree that to report anonymous default exported function expressions makes sense.

@mdjermanovic
Copy link
Member

A good thing for this is that no-unused-vars doesn't report export default function foo () {} although it is an unused variable in the module scope.

@platinumazure
Copy link
Member

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.

@mysticatea mysticatea added this to Memorandum in v7.0.0 Sep 6, 2019
@golopot
Copy link
Contributor Author

golopot commented Sep 7, 2019

Creating an option - avoids breaking users' CI for now, but adds a vestige that burdens all future users.

@mdjermanovic
Copy link
Member

This looks more like 2 options?

One to enforce the rule on function declarations, the other to change as-needed logic for export default.

@mysticatea
Copy link
Member

I prefer changing the default behavior on 7.0.0. I'm not sure if there are the cases we use the options.

@kaicataldo kaicataldo added breaking This change is backwards-incompatible and removed enhancement This change enhances an existing feature of ESLint labels Sep 30, 2019
@kaicataldo
Copy link
Member

Adding the breaking label, as it sounds like consensus is to hold off on this until v7.0.0. Feel free to change that if I misunderstood anything!

@mysticatea mysticatea moved this from Memorandum to Accepted, ready to implement in v7.0.0 Nov 7, 2019
@mysticatea mysticatea moved this from Accepted, ready to implement to Issues which have PR in v7.0.0 Feb 13, 2020
v7.0.0 automation moved this from Issues which have PR to Done Feb 17, 2020
kaicataldo pushed a commit that referenced this issue Feb 17, 2020
…12195)

* Breaking: check unnamed default export in func-names (fixes #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
montmanu pushed a commit to montmanu/eslint that referenced this issue Mar 4, 2020
) (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
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Aug 17, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Aug 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion breaking This change is backwards-incompatible bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
No open projects
v7.0.0
  
Done
Development

Successfully merging a pull request may close this issue.

5 participants