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: Allow unnamed generators (option) #9511

Closed
joegoldbeck opened this issue Oct 24, 2017 · 9 comments
Closed

func-names: Allow unnamed generators (option) #9511

joegoldbeck opened this issue Oct 24, 2017 · 9 comments
Assignees
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 enhancement This change enhances an existing feature of ESLint help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules

Comments

@joegoldbeck
Copy link

What rule do you want to change?
func-names

Does this change cause the rule to produce more or fewer warnings?
Fewer

How will the change be implemented? (New option, new default behavior, etc.)?
New option

Please provide some example code that this change will affect:

const parse = coroutinify(function* (input) { ... })

What does the rule currently do for this code?
"Unexpected unnamed generator function" unless the option is set to "never"

What will the rule do after it's changed?
Allow unnamed generator functions if a second option is set to { generators: false } or similar

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Oct 24, 2017
@not-an-aardvark not-an-aardvark changed the title func-rules: Allow unnamed generators (option) func-names: Allow unnamed generators (option) Oct 24, 2017
@not-an-aardvark
Copy link
Member

Thanks for the proposal. Could you clarify what the motivation for this option is? Why do you want to allow unnamed generators while disallowing other unnamed functions?

@not-an-aardvark not-an-aardvark added enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it 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 Oct 25, 2017
@joegoldbeck
Copy link
Author

joegoldbeck commented Oct 25, 2017

Sure, happy to clarify!

The reason comes down to language-level limitations, and in particular, that arrow notation can be used to create functions but not generators.

When we create lightweight functions, we use arrow notation, which are inherently unnamed. As one reference point, the AirBnb styleguide recommends this approach.

However, for generators, we can only use the standard function*, and so an exception for generators would allow us to create lightweight unnamed generators while leaving our stricter linting rules for functions intact.

@not-an-aardvark
Copy link
Member

I see, thanks. That makes sense to me -- let's see if the rest of the team would be in favor of adding an option like this.

@ekimlinger
Copy link

Not sure if this would have to be a new rule request, however generators also spark a similar break with the 'func-style' rule.

Say for example we have the following code:

const anExampleGenFunc= function* () {
    yield () => console.log('Do Something more than a console.log here');
};

I feel as though that this is perfectly valid JS (please correct me if I am wrong), but it raises a warning in eslint.
[eslint] Expected a function declaration. (func-style)

@ilyavolodin
Copy link
Member

It looks like there's more then enough support from the team to accept this. We just need somebody to champion this change to mark it as accepted. @eslint/eslint-team anyone willing to champion?

@not-an-aardvark
Copy link
Member

@eslint/eslint-team Anyone willing to champion this change? If not, it's probably time to close it.

@platinumazure platinumazure self-assigned this Jul 22, 2018
@platinumazure
Copy link
Member

I'll champion this.

@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jul 23, 2018
@platinumazure
Copy link
Member

@joegoldbeck After quite some time, this issue is now accepted. Would you be interested in submitting a pull request? (If not, no worries-- maybe someone else will, or maybe I can find some time myself in the next few weeks.)

@kaicataldo kaicataldo added the help wanted The team would welcome a contribution from the community for this issue label Jul 23, 2018
@OscarBarrett
Copy link
Contributor

I'll submit a PR for this in the next couple of days.

OscarBarrett added a commit to OscarBarrett/eslint that referenced this issue Jul 29, 2018
OscarBarrett added a commit to OscarBarrett/eslint that referenced this issue Jul 29, 2018
OscarBarrett added a commit to OscarBarrett/eslint that referenced this issue Jul 29, 2018
OscarBarrett added a commit to OscarBarrett/eslint that referenced this issue Jul 29, 2018
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 6, 2019
@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 Mar 6, 2019
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 enhancement This change enhances an existing feature of ESLint help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

8 participants