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

Docs: func-style docs are confusing #18474

Closed
1 task done
camsteffen opened this issue May 18, 2024 · 1 comment · Fixed by #18477
Closed
1 task done

Docs: func-style docs are confusing #18474

camsteffen opened this issue May 18, 2024 · 1 comment · Fixed by #18477
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion documentation Relates to ESLint's documentation

Comments

@camsteffen
Copy link
Contributor

Docs page(s)

https://eslint.org/docs/latest/rules/func-style

What documentation issue do you want to solve?

  1. The lint name suggests that it is about the style of all functions but this is not the case. Based on the name, my initial expectation was that the lint is about the choice between function and arrow functions. That is kinda close but not quite right, and the docs do not anticipate this misconception.
  2. The docs use the term "function expression" to mean "function expression assigned to a variable". This is incorrect and further contributes to the misconception above.

What do you think is the correct solution?

Do not use the term "function expression" to mean "function expression assigned to a variable". That is incorrect and confusing. In const x = () => {}, only the () => {} part is a function expression. As a reference, see the Functions MDN page.

For instance, I would change the summary line to

- Enforce the consistent use of either function declarations or expressions
+ Enforce the consistent use of either function declarations or expressions assigned to variables

Maybe explicitly state that the lint does not apply to callback functions.

Participation

  • I am willing to submit a pull request for this change.

Additional comments

I admit the phrase "function expression assigned to a variable" is verbose. But brevity at the cost of technical correctness is not a good trade. It confused me and I doubt I'm the only one.

@camsteffen camsteffen added the documentation Relates to ESLint's documentation label May 18, 2024
@Tanujkanti4441
Copy link
Contributor

Hi @camsteffen, thanks for the issue, a PR is welcome.

@Tanujkanti4441 Tanujkanti4441 added the accepted There is consensus among the team that this change meets the criteria for inclusion label May 19, 2024
camsteffen added a commit to camsteffen/eslint that referenced this issue May 19, 2024
camsteffen added a commit to camsteffen/eslint that referenced this issue May 19, 2024
camsteffen added a commit to camsteffen/eslint that referenced this issue May 21, 2024
camsteffen added a commit to camsteffen/eslint that referenced this issue May 22, 2024
nzakas added a commit that referenced this issue May 27, 2024
* docs: clarify func-style

Fixes #18474

* Update docs/src/rules/func-style.md

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

---------

Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion documentation Relates to ESLint's documentation
Projects
Status: Complete
Development

Successfully merging a pull request may close this issue.

2 participants