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

Update: changed curly reporting location (refs #12334) #13282

Closed
wants to merge 8 commits into from

Conversation

anikethsaha
Copy link
Member

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

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 always 1 except for else.

I made the following changes.

  • for missing parens, it will show the location where is should be placed.
    for example
1 for(;;)
2 foo();
  ^ <- this location will be reported.

or

if(foo) bar;
    // ^ <- this location will be reported
  • for unexpected braces,
    the first unexpected { will be reported.
if(foo) {foo()};
     // ^ 

The else logic for both is not changed as I think it was working fine earlier

Is there anything you'd like reviewers to focus on?

None

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label May 11, 2020
@anikethsaha anikethsaha changed the title Update: changed reporting location (ref #12334) Update: changed curly reporting location (ref #12334) May 11, 2020
@anikethsaha
Copy link
Member Author

I am not sure what am I missing in CI cause the failing test is un-related to my changes and tests are passing in my machine.

image

any suggestions would be appreciated 👍

@mdjermanovic
Copy link
Member

Those two failing tests should be fixed by #13277.

@kaicataldo
Copy link
Member

@anikethsaha Do you mind rebasing now that #13277 has been merged?

@kaicataldo kaicataldo added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels May 11, 2020
Copy link
Member

@kaicataldo kaicataldo left a 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!

lib/rules/curly.js Show resolved Hide resolved
lib/rules/curly.js Outdated Show resolved Hide resolved
lib/rules/curly.js Outdated Show resolved Hide resolved
lib/rules/curly.js Outdated Show resolved Hide resolved
@anikethsaha anikethsaha changed the title Update: changed curly reporting location (ref #12334) Update: changed curly reporting location (refs #12334) May 12, 2020
Copy link
Member

@mdjermanovic mdjermanovic left a 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?

@anikethsaha
Copy link
Member Author

Should all of them have the starting location of the body ?

@mdjermanovic
Copy link
Member

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 { at a different place, and the message says "Expected { after...".

Maybe we could instead consider reporting the location of the first token (which would be if, else, while, do, or for):

if (foo) bar();
^^

or the last token before the body (which would be ), else or do):

if (foo) bar();
       ^      

or maybe even the whole range before the body (though, this could underline a lot of code):

if (foo) bar();
^^^^^^^^      

@anikethsaha
Copy link
Member Author

Maybe we could instead consider reporting the location of the first token (which would be if, else, while, do, or for):

if (foo) bar();
^^

I think this is the current behavior, it shows the column as 1

or the last token before the body (which would be ), else or do):

if (foo) bar();
       ^      

let me try this,

or maybe even the whole range before the body (though, this could underline a lot of code):

if (foo) bar();
^^^^^^^^      

true, it can be longer if the condition inside the is long.

@mdjermanovic
Copy link
Member

Maybe we could instead consider reporting the location of the first token (which would be if, else, while, do, or for):

if (foo) bar();
^^

I think this is the current behavior, it shows the column as 1

It is the current behavior for start location, but it doesn't report end location.

If we choose this option, it might make sense to report the whole range of the first token (i.e., both its start and end locations).

@anikethsaha anikethsaha reopened this May 15, 2020
@anikethsaha
Copy link
Member Author

anikethsaha commented May 15, 2020

Update :

Now, the reporting location is as follows.

for missing

if (foo) bar();
    // ^^

if (foo) 
    // ^^   
 bar();
    

// `else`

if (foo) bar(); else bar(1);
    //          ^^^^


// `for`

for (;;) bar();
//     ^^

for unexpected

if (foo) {bar();}
   //    ^^

// `else`

if (foo) bar(); else {bar(1);}
    //               ^^

for (;;) {bar()};
//       ^^

@mdjermanovic let me know if this is ok !

@mdjermanovic
Copy link
Member

@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?

@kaicataldo
Copy link
Member

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()};
       ^^^^

@anikethsaha
Copy link
Member Author

I think that would make sense for missing case.
For Unexpected case, I think it should report the curly brace itself.

WDYT ?

@kaicataldo
Copy link
Member

That makes sense to me!

@anikethsaha
Copy link
Member Author

I have made the changes as discussed above.

Let me know if anything else if required

lib/rules/curly.js Outdated Show resolved Hide resolved
lib/rules/curly.js Outdated Show resolved Hide resolved
lib/rules/curly.js Show resolved Hide resolved
lib/rules/curly.js Show resolved Hide resolved
@snitin315
Copy link
Contributor

I will finish it.

@snitin315
Copy link
Contributor

Stale. Closing in favor of #14766

@snitin315 snitin315 closed this Jul 4, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jan 1, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jan 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants