Follow

You should never lint for Yoda conditions.

If you have a linter, you should lint for assignment inside conditionals.

Yoda conditions are a convention that prevents you from accidentally assigning when you meant to compare. A linter is just a better tool for this.

@WomanCorn Do people really run linters configured to complain about e.g. if (null == foo)? Like pretty much all my code would fail that; I write the checks that way out of habit. Or are you saying the linter complains if you write if (foo == null) and makes you reverse it? Boo on that if so, and agree with your suggested fix.

@flats yeah. The project I'm on is using the WordPress coding standards and they demand

If ( 0 === $count )

and lint for that too. So annoying.

Sign in to participate in the conversation
Mastodon

a Schelling point for those who seek one