This is a request from the WordPress themes codesniffer, which is an extension of this project. See original ticket: https://github.com/WPTRT/WordPress-Coding-Standards/issues/142
Essentially, we want to allow short echo tags (<?=), which are always available since PHP 5.4.
Reference:
I'm not familiar enough with the code on the project to say exactly what needs to be done, so I'm just going to copy/paste the response from one of the devs on the project:
The current sniff we use - Generic.PHP.DisallowShortOpenTag - does not allow for an exception easily, however as it is a good sniff, it would be kind of silly to duplicate it.
As the sniff comes from PHPCS itself, I think the best course of action would be to propose a custom property to be added to the sniff which can toggle whether "short open echo" is allowed or not.
The easiest way to do this is to exclude that specific error message. The short echo and short open error messages have different codes, so you can do this in your ruleset:
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<exclude name="Generic.PHP.DisallowShortOpenTag.EchoFound"/>
That includes the sniff as normal, but then excludes the specific error message that complains when short echos are found. It will still report errors for short open tags as they use the Generic.PHP.DisallowShortOpenTag.Found error code. You can see error codes in reports by using the -s command line argument.
Does that do what you're after?
@gsherwood Thanks for the response. I'd completely overlooked the different error code.
I'm going to close this issue then since it seems like we have what we need. Thanks for the response!
Most helpful comment
The easiest way to do this is to exclude that specific error message. The short echo and short open error messages have different codes, so you can do this in your ruleset:
That includes the sniff as normal, but then excludes the specific error message that complains when short echos are found. It will still report errors for short open tags as they use the
Generic.PHP.DisallowShortOpenTag.Founderror code. You can see error codes in reports by using the-scommand line argument.Does that do what you're after?