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: Add always-multiline option to multiline-ternary (fixes #8770) #8841

Merged
merged 1 commit into from Jul 4, 2017

Conversation

nwoltman
Copy link
Contributor

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

[x] Changes an existing rule

See #8770

What changes did you make? (Give an overview)

This adds an always-multiline option to multiline-ternary. This option enforces newlines between the operands of a ternary expression only if the expression spans multiple lines.

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

Nope.

However, I would like out point out that with the addition of this option, the name of this rule could be changed to ternary-newline to follow the naming convention of similar ESLint rules.

@jsf-clabot
Copy link

jsf-clabot commented Jun 30, 2017

CLA assistant check
All committers have signed the CLA.

@eslintbot
Copy link

LGTM

@mention-bot
Copy link

@nwoltman, thanks for your PR! By analyzing the history of the files in this pull request, we identified @kaicataldo and @mysticatea to be potential reviewers.

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules labels Jun 30, 2017
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. Thanks for contributing to ESLint!

@@ -69,6 +71,10 @@ module.exports = {
reportError(node.consequent, node, false);
}
} else {
if (allowSingleLine && astUtils.isTokenOnSameLine(node, node)) {
Copy link
Member

Choose a reason for hiding this comment

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

Ha, interesting use of astUtils.isTokenOnSameLine().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😅

Copy link
Member

Choose a reason for hiding this comment

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

Not to ruin the fun, but I feel like this makes the code a bit hard to read -- semantically a node would always be on the same line as itself, and this only works due to an implementation detail of astUtils.isTokenOnSameLine where it assumed that the two tokens would be different. Personally I think it would be better to be explicit here instead:

if (allowSingleLine && node.loc.start.line === node.loc.end.line) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree that is more readable. Fixed 👍

@eslintbot
Copy link

LGTM

@kaicataldo kaicataldo merged commit 1f5bfc2 into eslint:master Jul 4, 2017
@kaicataldo
Copy link
Member

kaicataldo commented Jul 4, 2017

Thanks for contributing to ESLint! 🎉

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