Skip to content

Add SlevomatCodingStandard.ControlStructures.DisallowYodaComparison sniff#156

Merged
adamziel merged 2 commits intotrunkfrom
php-cbf
Sep 5, 2025
Merged

Add SlevomatCodingStandard.ControlStructures.DisallowYodaComparison sniff#156
adamziel merged 2 commits intotrunkfrom
php-cbf

Conversation

@adamziel
Copy link
Collaborator

@adamziel adamziel commented Sep 5, 2025

Adds a PHPCBF sniff to auto-fix yoda conditions that WordPress coding standards require

…owYodaComparison to

auto-fix yoda conditions
@adamziel adamziel mentioned this pull request Sep 5, 2025
@adamziel adamziel merged commit 1ff3e03 into trunk Sep 5, 2025
20 of 21 checks passed
@rodrigoprimo
Copy link

@adamziel, when I mentioned this sniff in our Slack conversation, I suggested it as something worth checking to see if it could be used once to automatically fix non-Yoda conditions in this effort to make this repository compatible with WPCS. I don't have previous experience with this sniff, and I don't know if what it flags and fixes match what WPCS flags.

I don't see a problem, per se, with including it in the repository. Just thought it was worth clarifying what I was suggesting.

@adamziel
Copy link
Collaborator Author

adamziel commented Sep 5, 2025

@rodrigoprimo thank you for clarifying! It seems to be doing the right thing. We'll find out for sure when I do a PR to migrate the codebase – if it's not consistent with what WPCS needs, we'll just remove it. For me personally, Yoda conditions are unnatural to write and I'm always left with a few dozens of them to fix before merging anything – an automated sniff to do that is a huge quality of life improvement.

If there weren't other problems with that, I'd suggest an automated mirror repo that takes the original codebase and applies all the WPCS rules to it just to make the day-to-day easier, as in I'd like a minimal set of formatting rules similar to what prettier does in JS (tabs vs spaces, indentation, newlines, where curly braces are etc.) without the rest of it (yoda, filenames, snake_case, dots at the end of // inline comments etc.). Maybe one day 🤷

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants