-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Update: check identifier in array pattern in id-length (fixes #12832) #12839
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
By the code it seems that this rule aims to report only variable creations (declarations, params etc.), not all references, maybe we should do that for array patterns as well? [a] = foo; // shouldn't be error? Though, |
@mdjermanovic
Could you please explain it more? /*eslint id-length: "error"*/
var a = 4; // Error
a = 5; // No error
// Object Pattern
var {c} = foo; // Error
({c} = foo); // Error
// AssignmentPattern
var [d = b] = foo; // Error
[d = b] = foo; // Error
// RestElement
var [...d] = foo; // Error
[...d] = foo; // Error
// No Error in v6.8.0 but both Errors in the PR version.
var [a] = foo;
[a] = foo; In my understanding. this rule seems to report the syntax which can make a new identifier if there isn't. (maybe LHS lookup?) // without declaration
[a] = [3]; // it creates an identifier 'a`
({b} = { b: 3 }); // it creates an identifier 'b` From this point of view, the below cases also need to be warned. a = 5; // No error in the current version.
[a] = 5;
({a} = {}); I would like to hear your opinion :) |
Given that other |
A problem is that the current behavior is already inconsistent. I'm not sure if someone may complain about why By looking at the actual and the initial version of the code, I think that |
In the docs, Examples of correct code for this rule with a minimum of 4: Also, Examples of correct code for this rule with the { "min": 4 } option: Hm, these two sections look pretty much same? The first one has text "This rule has a shorthand integer option for the "min" object property". It could be for an option that wasn't implemented? |
Yes, I agree. I'll update the documentation.
It seems so. I think it should be removed because it is not supported actually. Thanks :) |
I think merging #12881 created merge conflicts here - sorry! |
# Conflicts: # docs/rules/id-length.md # tests/lib/rules/id-length.js
@kaicataldo That's no problem 😄 I knew it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Non-blockers:
- Some examples in correct
{ "min": 4 }
are incorrect, but that's another bug. - I still think the intention was to not report left side of assignments unless it's an assignment to a property with invalid length.
…12832) (eslint#12839) * Update: check identifier in array pattern in id-length (fixes eslint#12832) * fix wrong test case * Update documentation
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Change the
id-length
rule to check an identifier in the array pattern.Is there anything you'd like reviewers to focus on?
This PR will fix #12832.
It will generate more errors so I labeled this pr as
Update
.