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: avoid creating gratuitous whitespace in arrow-body-style fixer #7504

Merged
merged 2 commits into from
Nov 10, 2016

Conversation

not-an-aardvark
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[x] Changes an existing rule

What rule do you want to change?

arrow-body-style

Does this change cause the rule to produce more or fewer warnings?

The same amount

How will the change be implemented? (New option, new default behavior, etc.)?

This will change the default behavior.

Please provide some example code that this change will affect:

/* eslint arrow-body-style: "error" */

foo(bar => {
  return baz;
}, qux);

What does the rule currently do for this code?

It reports an error. With the --fix option, it fixes the code to:

foo(bar => 
   baz
, qux);

What will the rule do after it's changed?

It will still report an error. With the --fix option, it will fix the code to:

foo(bar => baz, qux);

This version of the fix is more idiomatic, and it avoids unexpected whitespace around the resulting expression.

What changes did you make? (Give an overview)

This updates the arrow-body-style fixer to remove whitespace when converting an arrow block body to an expression. It will only do this if there are no non-whitespace characters between the { and the return statement/between the expression and the }, so lines with comments will be unaffected.

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

Nothing in particular.

@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @alberto, @vitorbal and @ajhyndman to be potential reviewers.

@not-an-aardvark not-an-aardvark added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Oct 31, 2016
@not-an-aardvark not-an-aardvark self-assigned this Oct 31, 2016
@eslintbot
Copy link

LGTM

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some test cases for when the returned value is itself multi-line?

E.g.:

var x = () => {
    return foo
        .bar();
};

I'm wondering if maybe those cases shouldn't be fixed, but let's see how the test cases look with your changes.

@eslintbot
Copy link

LGTM

@not-an-aardvark
Copy link
Member Author

Added some testcases. I think I like how the output for this case looks, but I don't like the output of this case as much.

@mysticatea
Copy link
Member

FYI: A bit related: #6067

@kaicataldo
Copy link
Member

@not-an-aardvark Agreed, but I think it's the safe approach. I don't think this fixer should take on the responsibility of formatting the returned value.

As an example:
Say the user has "newline-per-chained-call": "error" in their configuration and they run this fixer on the following code:

var foo = () => {
  return foo
    .bar()
    .baz();
};

is fixed to:

var foo = () => foo
    .bar()
    .baz();
};

The off indentation should be the responsibility of the indent rule, and the newline before the method call should be the responsibility of newline-per-chained-call. Since newline-per-chained-call doesn't have a fixer, fixing that to one line would result in a new errors.

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.

LGTM

@not-an-aardvark
Copy link
Member Author

@platinumazure, what do you think about the added testcases for multiline expressions? It would be good to come to a consensus on how to handle those cases.

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are fairly sensible fixes. The CallExpression chain is a bit unfortunate, but I think tolerable given indent's autofixer. The ObjectExpression looks good to me (again, I would personally de-indent those lines but I know some are okay with a double-indent for an ObjectExpression inside parentheses). This is much better than what could otherwise have happened.

@platinumazure
Copy link
Member

Sorry for dropping the ball on this. Not for the first time, I look forward to GitHub providing a way for me to track PRs which have had commits or history rewrites since my last review.

@not-an-aardvark
Copy link
Member Author

Thanks! Regarding your comment about ObjectExpression indentation, keep in mind that this is also handled by indent's autofixer. (I couldn't tell whether you were just talking about the autofixer in the context of CallExpressions.)

Based on your comment, should I assume that you're 👍 on this proposal (in addition to approving the implementation)?

@platinumazure
Copy link
Member

Yes, I'm :+1 on the proposal and implementation. (And yes, I know the indent autofixer handles both cases. Sorry for being unclear.)

@nzakas nzakas added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 10, 2016
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nzakas nzakas merged commit 2bd1dd7 into master Nov 10, 2016
@not-an-aardvark not-an-aardvark deleted the arrow-body-style-whitespace branch November 10, 2016 16:49
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
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

7 participants