Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

(require|disallow)YodaConditions: add support for listing specific operators#1031

Closed
Slayer95 wants to merge 2 commits intojscs-dev:masterfrom
Slayer95:yoda-conditions-array
Closed

(require|disallow)YodaConditions: add support for listing specific operators#1031
Slayer95 wants to merge 2 commits intojscs-dev:masterfrom
Slayer95:yoda-conditions-array

Conversation

@Slayer95
Copy link
Copy Markdown
Contributor

@Slayer95 Slayer95 commented Feb 9, 2015

Fixes #1026

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0%) to 99.0% when pulling ee117d3 on Slayer95:yoda-conditions-array into 0feb327 on jscs-dev:master.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there's an extra != here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed it.

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Feb 9, 2015

looks good!

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0%) to 99.0% when pulling 3633159 on Slayer95:yoda-conditions-array into 0feb327 on jscs-dev:master.

@Slayer95 Slayer95 force-pushed the yoda-conditions-array branch from 3633159 to 3508bbf Compare February 9, 2015 14:48
Slayer95 added a commit to Slayer95/node-jscs that referenced this pull request Feb 9, 2015
@Slayer95 Slayer95 force-pushed the yoda-conditions-array branch from 3508bbf to 8c9c772 Compare February 9, 2015 14:49
Slayer95 added a commit to Slayer95/node-jscs that referenced this pull request Feb 9, 2015
@Slayer95 Slayer95 force-pushed the yoda-conditions-array branch from 8c9c772 to 6425ebd Compare February 9, 2015 14:54
Slayer95 added a commit to Slayer95/node-jscs that referenced this pull request Feb 9, 2015
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0%) to 99.0% when pulling 6425ebd on Slayer95:yoda-conditions-array into 0feb327 on jscs-dev:master.

@qfox
Copy link
Copy Markdown
Member

qfox commented Feb 10, 2015

I thought about it. Look like we lost a reason of denying yoda conditions.

Afaik it was a bad code style because there is a difference between a = 5 and a == 5. And mistype is not a syntax error. But it's impossible to mistype a < 5. Do we really need this fix or we should just rethink this rule?

@Slayer95
Copy link
Copy Markdown
Contributor Author

I agree that yoda conditions are only useful to guard against that typo (i.e. requireYodaConditions can be limited to it. However, that's more easily dealt with other sort of rules, like JSHint's "Expected a conditional expression and instead saw an assignment".

Regarding disallowYodaConditions, an argument based on aesthetics and backwards compatibility can be made to keep supporting the current behavior, but I wouldn't mind its getting restricted to ==.

Interestingly, ESLint provides the option to forbid Yoda Conditions except for ranges, which is my exact use case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why was this removed from the beforeEach?

@mrjoelkemp
Copy link
Copy Markdown
Member

Is this PR mergeable (once rebased)?

cc @zxqfox @hzoo

@qfox
Copy link
Copy Markdown
Member

qfox commented Mar 17, 2015

@mrjoelkemp I think it's too complicated and can be simplified. I'm not sure that 5 <= value should be interpreted as yoda condition.

@Slayer95 Slayer95 force-pushed the yoda-conditions-array branch from 6425ebd to ef4b343 Compare March 25, 2015 02:19
Slayer95 added a commit to Slayer95/node-jscs that referenced this pull request Mar 25, 2015
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0%) to 99.09% when pulling ef4b343 on Slayer95:yoda-conditions-array into 02bf7ac on jscs-dev:master.

@Slayer95 Slayer95 changed the title (require|disallow)YodaConditions: add support for listing specific operators [WIP] (require|disallow)YodaConditions: add support for listing specific operators Mar 25, 2015
@markelog
Copy link
Copy Markdown
Member

markelog commented Apr 7, 2015

Is that still WIP?

@Slayer95
Copy link
Copy Markdown
Contributor Author

Slayer95 commented Apr 7, 2015

Waiting for feedback / replies to @zxqfox with details regarding what we want as destination.

I guess I should have used something like "WFF" rather than "WIP" -if that's a thing.

@markelog
Copy link
Copy Markdown
Member

ping @zxqfox

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if make ['==', '===', '!='] by default (true)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Even just '===' and '=='.
Historical reasons.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure about this. As to me they are all Yoda-style. And still I can't see enough reasons to break backwards compatibility.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It wouldn't actually break anything though. That is, no failing builds on update.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not talking about the builds. I'm about the unexpected behaviour change. For instance, I know several projects which rely on the current behaviour.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually I'm fine if we left it as is.

@qfox
Copy link
Copy Markdown
Member

qfox commented May 31, 2015

Sorry for delay, somehow missed this PR. ;-(

@Slayer95 Slayer95 force-pushed the yoda-conditions-array branch from ef4b343 to dbfd67b Compare June 4, 2015 05:45
Slayer95 added a commit to Slayer95/node-jscs that referenced this pull request Jun 4, 2015
@Slayer95 Slayer95 force-pushed the yoda-conditions-array branch from dbfd67b to 7034ae9 Compare June 4, 2015 06:02
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0%) to 99.17% when pulling 7034ae9 on Slayer95:yoda-conditions-array into f963cd4 on jscs-dev:master.

@Slayer95
Copy link
Copy Markdown
Contributor Author

Slayer95 commented Jun 4, 2015

Updated tests as requested.

@qfox
Copy link
Copy Markdown
Member

qfox commented Jun 4, 2015

@Slayer95 Thanks!

LGTM

@mdevils
Copy link
Copy Markdown
Member

mdevils commented Jun 4, 2015

LGTM! Good job!

@Slayer95 Slayer95 changed the title [WIP] (require|disallow)YodaConditions: add support for listing specific operators (require|disallow)YodaConditions: add support for listing specific operators Jun 4, 2015
@markelog
Copy link
Copy Markdown
Member

markelog commented Jun 8, 2015

Just a remainder, if pr has two "LGTM" you can definitely merge it, @mdevils, @zxqfox could one of you do that?

@mdevils
Copy link
Copy Markdown
Member

mdevils commented Jun 10, 2015

@markelog Yes, sure :)

@mdevils
Copy link
Copy Markdown
Member

mdevils commented Jun 10, 2015

Merged into 2.0. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] (Disallow|Require)YodaConditions for specific operators

7 participants