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: Check indentation for multi-line chained properties (refs #1801) #5940

Merged
merged 1 commit into from Jul 20, 2016

Conversation

Trott
Copy link
Contributor

@Trott Trott commented Apr 23, 2016

The end user can choose whether and how much to indent.

foo()
.bar
.baz()

vs.

foo()
  .bar
  .baz()

and so forth...

@eslintbot
Copy link

LGTM

@jquerybot
Copy link

Thank you for your pull request. It looks like this may be your first contribution to a jQuery Foundation project, if so we need you to sign our Contributor License Agreement (CLA).

📝 Please visit http://contribute.jquery.org/CLA/ to sign.

After you signed, the PR is checked again automatically after a minute. If there's still an issue, please reply here to let us know.


If you've already signed our CLA, it's possible your git author information doesn't match your CLA signature (both your name and email have to match), for more information, check the status of your CLA check.

@Trott
Copy link
Contributor Author

Trott commented Apr 23, 2016

I've signed the CLA and the information provided appears to match my git author information. Not sure if there's something up with the automatic CLA checker thingy or if I'm just Doing It Wrong somehow...

@Trott
Copy link
Contributor Author

Trott commented Apr 23, 2016

There's going to definitely be people that will prefer this:

var a = foo.bar()
           .baz()
           .bip()
           .bap();

...instead of:

var a = foo.bar()
  .baz()
  .bip()
  .bap();

It may be possible to write a rule smart enough to distinguish between that and other cases where it may make sense to indent-by-two rather than align, but I suspect there will be many edge cases. Indentation of then() in promise chains would seem to be a likely one too.

Maybe I'm overthinking it?

@Trott
Copy link
Contributor Author

Trott commented Apr 23, 2016

(Rebased against master, conflicts resolved, force pushed.)

@Trott
Copy link
Contributor Author

Trott commented Apr 23, 2016

Looks like the Travis failure was a bitbucket issue?

@gyandeeps
Copy link
Member

@Trott Thanks a lot. I think implementation looks good. CC: @BYK
Couple of minor things:

  • Please change your commit message to start with "Update:"
  • Since this rule is able to apply auto-fixes, the invalid cases should have an output property with fixed code.
  • Would like to see some tests with tabs (/t) in it as well as some with chaining value greater than 1.

@Trott Trott force-pushed the indent-chain branch 3 times, most recently from 21fe90b to 8017738 Compare April 24, 2016 03:04
@Trott Trott changed the title New: Validate indentation for multi-line chained properties (refs #1801) Update: Check indentation for multi-line chained properties (refs #1801) Apr 24, 2016
@Trott
Copy link
Contributor Author

Trott commented Apr 24, 2016

@gyandeeps Thanks! I think I've addressed each of your requests at this point.

One question:

Should there be a setting to disable the indentation check on chained properties and/or a setting to ignore the indentation but to guarantee alignment? The idea is to enable people using the indent rule to have code like this if they wish:

var a = foo.bar()
           .baz()
           .bip()
           .bap();

@BYK
Copy link
Member

BYK commented Apr 24, 2016

I actually have some concerns:

  • The name, Chaining is not aligned with our other option names. I think it should just say MemberExpression.
  • Giving a numerical indent multiplier was a big mistake for other options so I think following that mistake is not also great. I feel like this should be a string value: indent, none, align or { indent: "loose", align: true} to separate indentation from aligning (indent can be any of these: "strict", "loose", "none"). This would allow code like the following
_.map(something, somethingElse)
 .filter(lalala)

@Trott
Copy link
Contributor Author

Trott commented Apr 25, 2016

If you can set it to align rather than indent, is that an indication that perhaps it should be its own separate rule rather than part of the indent rule?

@BYK
Copy link
Member

BYK commented May 2, 2016

@Trott - disagree. This is clearly related to indentation. Aligning from the left-most side is always indent-related.

@nzakas
Copy link
Member

nzakas commented May 18, 2016

@BYK @gyandeeps what's the next step here?

@BYK
Copy link
Member

BYK commented May 19, 2016

I haven't changed my position and @Trott seems to be fed up with my insistence :D

@Trott
Copy link
Contributor Author

Trott commented May 19, 2016

@BYK Nah, not fed up. Just fell of my radar...

@eslintbot
Copy link

LGTM

@Trott
Copy link
Contributor Author

Trott commented May 19, 2016

Rebased against master, resolved the resulting conflict in the documentation file, force pushed.

@eslintbot
Copy link

LGTM

@Trott
Copy link
Contributor Author

Trott commented May 19, 2016

Chaining -> MemberExpression per @BYK. Force-pushed.

@nzakas
Copy link
Member

nzakas commented Jun 3, 2016

The plan is make the other options follow the same, better new option scheme (with backwards compatibility) if you agree. Reason is they still suffer from the same problem (think about VariableDeclaration).

This seems like a very confusing incremental step towards that. If that's your goal, then I think we should start with a new issue describing all the changes you want to make. I don't like the idea of using this task as a backdoor for significant changes to this rule.

@BYK
Copy link
Member

BYK commented Jun 6, 2016

@nzakas so is your preference to make this like the others and then file a separate ticket to make a transition for all (in a backwards-compatible manner)?

If so I can live with that.

@nzakas
Copy link
Member

nzakas commented Jun 6, 2016

@BYK yup, exactly.

@BYK
Copy link
Member

BYK commented Jun 6, 2016

Alright, removing my reservations about how the option is coded for this PR then. I'll file a new ticket once this is completed.

@nzakas
Copy link
Member

nzakas commented Jun 6, 2016

@BYK so is this ready to merge?


var dot = context.getTokenBefore(node.property);

if (dot.type === "Punctuator" && dot.value === ".") {
Copy link
Member

Choose a reason for hiding this comment

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

This logic here is a bit confusing to me. Why are we checking the dot additionally? Here's what I think:

  • If the dot is on the previous line, we only need to check the MemberExpression node.
  • If the dot is on the same line with MemberExpression, then we only need to check the dot's indentation.

Am I right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everywhere else, the checking for whether the node is the first item on the line is delegated to the check* functions, so I was following that pattern. They all just send everything to check*() and let that function figure out if it's the first thing on the line and needs to be checked or not.

Your suggested logic would work just fine too. If that would be less confusing, I can do that instead.

@BYK
Copy link
Member

BYK commented Jun 16, 2016

Sorry for the late review. I have a few concerns around how the Punctuator dot is handled and reported. Rest looks good (especially tests).

@Trott
Copy link
Contributor Author

Trott commented Jun 28, 2016

@BYK I've responded to the concerns/questions you raised inline. Do those responses satisfy your concerns? If not, I'm happy to keep working at this...

@kaicataldo
Copy link
Member

kaicataldo commented Jul 6, 2016

@BYK Friendly ping

@Trott Looks like we might have had a merge conflict crop up since your last update

@eslintbot
Copy link

LGTM

@Trott
Copy link
Contributor Author

Trott commented Jul 13, 2016

@kaicataldo Merge conflict resolved.

@kaicataldo @BYK Let me know if there's anything I can do to get this un-stalled.

@kaicataldo
Copy link
Member

@Trott Thanks!

@eslint/eslint-team Friendly ping to make sure this doesn't get lost

@nzakas
Copy link
Member

nzakas commented Jul 18, 2016

@Trott can you rebase?

@tarwich
Copy link

tarwich commented Jul 18, 2016

😭 So close!
I've got all these programmers writing

foo()
  .bar()
    .bin();

I can't wait to enforce

foo()
.bar()
.bin();

GL @Trott I'm cheering for you over here.

…nt#1801)

The end user can choose whether and how much to indent.
@eslintbot
Copy link

LGTM

@Trott
Copy link
Contributor Author

Trott commented Jul 18, 2016

@Trott can you rebase?

@nzakas Done!

@nzakas
Copy link
Member

nzakas commented Jul 20, 2016

LGTM. I think the open questions are minor ones, so it seems like we can go with this and then see what feedback we get. Thanks @Trott for sticking with this, I know it's been a long journey and we really appreciate your patience.

@nzakas nzakas merged commit 95ea25a into eslint:master Jul 20, 2016
@curiousdannii
Copy link
Contributor

curiousdannii commented Jul 29, 2016

I don't fully understand the technicalities of semver, but adding this made our lint fail. And I can't fix it by simply setting MemberExpression to a different default because I sometimes indent these lines and sometimes don't. (Well I could fix it with inline rules, but that's a nasty hack.)

This should've been a new rule, or delayed to sermver major. 👎

@platinumazure
Copy link
Member

@curiousdannii Please read our README for information on our semver policy. The short version is, we will sometimes release CI-breaking changes under semver-minor if they are new features for a rule (with opt-in configuration) or if they are bugfixes that will result in more errors being reported. We may have erred in this case, but I want to make sure it is understood that CI-breaking changes are not considered semver-major in all cases here.

If you want to avoid CI breaks, you can always use tilde ranges in your dependency configuration.

If you have questions/concerns, please stop by our Gitter chat. Thanks!

@curiousdannii
Copy link
Contributor

@platinumazure I did think that that would probably be the case.

But there should still be a way to disable the MemberExpression check.

@platinumazure
Copy link
Member

Absolutely. We do have an issue and multiple proposed PRs available, so
we'll consider the best way forward probably this weekend or early next
week. In the meantime, you can pin your ESLint dev dependency while we get
this sorted. Thanks so much for your patience!

On Jul 29, 2016 3:58 PM, "Dannii Willis" notifications@github.com wrote:

@platinumazure https://github.com/platinumazure I did think that that
would probably be the case.

But there should still be a way to disable the MemberExpression check.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#5940 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AARWejR3D9cxKT4gOPIXSxZrNTi-NF2tks5qaoWqgaJpZM4IOHqz
.

@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
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet