-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Improve no-func-assign docs and add tests #13705
Comments
Thanks for the issue. IMO, this is out of the scope of this rule. This rule checks for the
no-func-assign does catches the same. Let me know if I am missing something. |
I understand your point about the scope - that it is only supposed to catch const s declared explicitly by the user. But what about the ones implicitly created by the language? This is one such example. Is there any other rule for that? Also no-func-assign might be moved to warning in some configs, because it alone does not cause a error. This throws the exact same error that assigning to a const throws. User would expect no-const-assign to protect against all such errors. |
Ok, i take back my words. Only suggestion in that case is to add more strict words to no-func-assign doc saying that it can throw error also, not just a clean code issue Does that make sense? |
Yeah, I think there can be some more effective docs as an example similar to the one you shared. |
Sounds good to me! Marked as an accepted issue to improve documentation for The actual document doesn't even mention named function expressions and doesn't have any examples with them. Also, there are no test cases, so it's possible that the original intention was to check only function declarations:
Either way, this rule checks function expressions from the start (v0.0.9), this behavior does make sense, so we should update the docs to reflect the actual behavior. |
@bendtherules would you like to submit a pull request to improve documentation for |
Yes, i would like to add the pr. But it will probably take some time. |
|
Feel free to pick it up. I have not done any work on this. (in case you meant to ask me) |
While the PR adds a example of incorrect code, i think the whole scope is not holistically covered.
Can we reopen this? (can't see button) |
We added an example in #13777, and a test in #13783. @bendtherules I agree that the docs and the tests can be further improved, feel free to submit a PR! |
Ahh, i missed the tests pr. Then it looks better, maybe some text can be changed in the description is all. I'll try to raise a pr for this. |
Tell us about your environment
Eslint demo page with Eslint v7.9.0 - Demo URL
What parser (default,
@babel/eslint-parser
,@typescript-eslint/parser
, etc.) are you using? - defaultPlease show your full configuration:
Configuration
Only actual change from default config is - disabled "no-func-assign"
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
Ran demo web version - Demo URL
What did you expect to happen?
I have disabled "no-func-assign" rule.
On the line "hello = 123" within named function expression, this will always throw a runtime JS error saying
TypeError: Assignment to constant variable
. That means, this is a assignment to a (implicitly created) immutable binding for the function name "hello". "no-const-assign" rule should also catch this error, irrespective of "no-func-assign" - because this is a const reassignment.The spec says that for named function expressions, there is a implicitly created extra scope above the function local scope which has immutable binding for funcName = funcObject. So, this means -
A. This code should not be allowed
B. but this should be allowed -
What actually happened? Please include the actual, raw output from ESLint.
No lint error or warning (lint-free)
Are you willing to submit a pull request to fix this bug?
Yes
The text was updated successfully, but these errors were encountered: