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: changed curly reporting location (refs #12334) #13282
Conversation
cf31cdb
to
b3330be
Compare
Those two failing tests should be fixed by #13277. |
@anikethsaha Do you mind rebasing now that #13277 has been merged? |
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.
Thanks for working on this!
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.
Locations for missing {
seem to be inconsistent:
/*eslint curly: ["error"]*/
if (a)
// ^
b()
else
// ^
c();
for (d of e)
f();
// ^
Maybe we should discuss first what would be reasonable to report?
Should all of them have the starting location of the body ? |
That would be reasonable given that it marks the place where the auto-fix insert On the other hand, editors usually don't show zero-width ranges well. Also, user might want to insert Maybe we could instead consider reporting the location of the first token (which would be if (foo) bar();
^^ or the last token before the body (which would be if (foo) bar();
^ or maybe even the whole range before the body (though, this could underline a lot of code): if (foo) bar();
^^^^^^^^ |
I think this is the current behavior, it shows the column as
let me try this,
true, it can be longer if the condition inside the is long. |
It is the current behavior for If we choose this option, it might make sense to report the whole range of the first token (i.e., both its |
Update : Now, the reporting location is as follows. for if (foo) bar();
// ^^
if (foo)
// ^^
bar();
// `else`
if (foo) bar(); else bar(1);
// ^^^^
// `for`
for (;;) bar();
// ^^ for if (foo) {bar();}
// ^^
// `else`
if (foo) bar(); else {bar(1);}
// ^^
for (;;) {bar()};
// ^^
@mdjermanovic let me know if this is ok ! |
I'm not sure which of the three solutions I suggested would be the most appropriate, or if there's another one I didn't think of. @kaicataldo thoughts? |
Could it make sense to always report the locations between the last token before the body and the first token of the body, regardless of whether it's missing or not? Missing: if (foo) bar();
^^^
if (foo)
^^
bar();
^^
if (foo) bar(); else bar(1);
^^^ ^^^
for (;;) bar();
^^^ Unexpected: if (foo) {bar();}
^^^^
if (foo) bar(); else {bar(1);}
^^^^
for (;;) {bar()};
^^^^ |
I think that would make sense for missing case. WDYT ? |
That makes sense to me! |
I have made the changes as discussed above. Let me know if anything else if required |
I will finish it. |
Stale. Closing in favor of #14766 |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[X] 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)
Updated the location of reporting for curly braces.
Currently, the
column
while reporting was always1
except forelse
.I made the following changes.
for example
or
the first unexpected
{
will be reported.The
else
logic for both is not changed as I think it was working fine earlierIs there anything you'd like reviewers to focus on?
None