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

Incorrect documentation for func-style #12900

Closed
revolter opened this issue Feb 10, 2020 · 9 comments · Fixed by #13004
Closed

Incorrect documentation for func-style #12900

revolter opened this issue Feb 10, 2020 · 9 comments · Fixed by #13004
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 documentation Relates to ESLint's documentation good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue rule Relates to ESLint's core rules

Comments

@revolter
Copy link
Contributor

Tell us about your environment

  • ESLint Version:
  • Node Version:
  • npm Version:

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

Please show your full configuration:

Configuration

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

What did you expect to happen?

The correct code example for the configuration /*eslint func-style: ["error", "expression"]*/ shouldn't have an arrow function, as they're disallowed by default.

https://eslint.org/docs/rules/func-style#expression

What actually happened? Please include the actual, raw output from ESLint.

/*eslint func-style: ["error", "expression"]*/

var foo = function() {
    // ...
};

var foo = () => {};

Are you willing to submit a pull request to fix this bug?

Maybe.

@revolter revolter added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Feb 10, 2020
@platinumazure
Copy link
Member

I can't reproduce this: Both examples are lint-free when run in the demo.

It might help to fill in the issue template and share your ESLint version. Also, please let me know if something is wrong with my demo example. Thanks!

@mdjermanovic
Copy link
Member

Hi @revolter, thanks for the issue!

I can confirm that the example is actually correct. The "expression" option allows all function expressions and all arrow functions, regardless of the context. It just disallows function declarations.

"allowArrowFunctions": true (default false) allows the use of arrow functions (honoured only when using declaration)

"honoured only when using declaration" applies to the option, and means that this option changes the behavior of this rule only if the main string option is "declaration".

I agree that this sentence can be misinterpreted.

A PR to improve the documentation is welcome!

@platinumazure
Copy link
Member

Should we disallow the allowArrowFunctions: true option when the user is using "expression" mode? It's not a great experience to have an option that doesn't do anything in some cases.

@mdjermanovic
Copy link
Member

mdjermanovic commented Feb 10, 2020

@revolter just to confirm that we understand this bug report:

/*eslint func-style: ["error", "expression"]*/

var foo = () => {};

You think that var foo = () => {}; should be in Examples of incorrect code for this rule with the default "expression" option?

@mdjermanovic
Copy link
Member

Should we disallow the allowArrowFunctions: true option when the user is using "expression" mode? It's not a great experience to have an option that doesn't do anything in some cases.

Someone might also expect that ["error", "expression", { "allowArrowFunctions": false }] disallows arrow functions.

Would it be a breaking change to remove a misleading option that doesn't affect the behavior?

@mdjermanovic
Copy link
Member

Documentation for the "declaration" option could be also improved.

The option disallows only function expressions/arrow functions used to initialize a variable. It also never disallows arrow functions that use this.

/*eslint func-style: ["error", "declaration", { "allowArrowFunctions": false }]*/

var foo = function () {}; // error

var bar = () => {}; // error

arr.map(function() {}); // ok

arr.map(() => {}); // ok

var baz = () => this.something; // ok

@kaicataldo kaicataldo added 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 Feb 14, 2020
@revolter
Copy link
Contributor Author

You think that var foo = () => {}; should be in Examples of incorrect code for this rule with the default "expression" option?

Yes.

@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion documentation Relates to ESLint's documentation and removed bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Feb 15, 2020
@mdjermanovic
Copy link
Member

Thanks!

The example is correct and the rule is in sync with the example.

That's indeed the intended behavior. If the main string option is set to "expression", arrow functions are allowed.

(even if "allowArrowFunctions" is set to false, because it applies only to "declaration")

I agree that the following can be easily misinterpreted:

"allowArrowFunctions": true (default false) allows the use of arrow functions (honoured only when using declaration)

PR to clarify this option in the documentation is welcome!

@kaicataldo kaicataldo added good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue labels Feb 16, 2020
Caryyon pushed a commit to Caryyon/eslint that referenced this issue Feb 18, 2020
Caryyon added a commit to Caryyon/eslint that referenced this issue Feb 29, 2020
@anikethsaha
Copy link
Member

Should we disallow the allowArrowFunctions: true option when the user is using "expression" mode? It's not a great experience to have an option that doesn't do anything in some cases.

I think allowArrowFunctions does nothing as arrow function cant be possible for declaration.

nzakas pushed a commit that referenced this issue Mar 10, 2020
…13004)

* Docs: added less confusing explanation for func-style

* Docs: updated func-style allowArrowFunctions info
anikethsaha added a commit to anikethsaha/eslint that referenced this issue Mar 11, 2020
…2900) (eslint#13004)

* Docs: added less confusing explanation for func-style

* Docs: updated func-style allowArrowFunctions info
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Sep 8, 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 Sep 8, 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 documentation Relates to ESLint's documentation good first issue Good for people who haven't worked on ESLint before 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

Successfully merging a pull request may close this issue.

5 participants