eslint / eslint

Find and fix problems in your JavaScript code.
https://eslint.org
MIT License
24.44k stars 4.41k forks source link

Docs: func-style docs are confusing #18474

Closed camsteffen closed 5 days ago

camsteffen commented 2 weeks ago

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. 1) 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

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.

Tanujkanti4441 commented 1 week ago

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