I did my best, but my Google-fu was not strong enough to find any pre-existing sniff for identifying when the alternative control structure syntax is being used, let alone disallowing it. I despise the alternative control structure syntax and would love to be able to rely on a shared PHPCS configuration file to prevent its use.
My questions:
If you do respond, thank you for taking the time to help.
Hi @jrchamp The Mediawiki standard includes one: MediaWiki.AlternativeSyntax.AlternativeSyntax.
- Is this proposed sniff something that could be accepted into the core code? If so, which "category" makes the most sense, perhaps Generic.PHP?
I can't speak for the first part, but for the second, I would suggest Generic.ControlStructures.
- Is this something that is even possible to implement? I've not written a sniff before, so I'm a bit concerned that the tokens might not allow me to differentiate between alternative and brace syntaxes, particularly if they are used interchangeably.
Yes, it's perfectly possible to implement this by looking at what token is used for the scope_opener/scope_closer of a control structure.
It was actually already on my list to add a sniff for this to PHPCSExtra including a fixer, so I'd be happy to sort that out sooner rather than later if you think that would help.
If the MediaWiki one doesn't have a fixer, then there's a lot of added value for me. Please know that's it's not urgent. When it's ready I'll be thrilled to fold that into our process.
@jrchamp The MediaWiki one doesn't have a fixer. I actually got a sniff with fixer ready for this now, but want to run a few more tests before I pull it. Give it a few more days. If you like, watch the PHPCSExtra repo and you'll see the PR soon enough.
@jrchamp PR https://github.com/PHPCSStandards/PHPCSExtra/pull/23 should take care of it. Sorry it took a little while to pull.
Thank you so much @jrfnl ! :clinking_glasses:
My questions are resolved, but I can't tell if this should be left open or closed. @gsherwood Do you want me to leave this here?
Do you want me to leave this here?
Happy to leave it as a feature request
Most helpful comment
Hi @jrchamp The Mediawiki standard includes one:
MediaWiki.AlternativeSyntax.AlternativeSyntax.I can't speak for the first part, but for the second, I would suggest
Generic.ControlStructures.Yes, it's perfectly possible to implement this by looking at what token is used for the
scope_opener/scope_closerof a control structure.It was actually already on my list to add a sniff for this to
PHPCSExtraincluding a fixer, so I'd be happy to sort that out sooner rather than later if you think that would help.