WPTT / WPThemeReview

PHP_CodeSniffer rules (sniffs) to enforce WordPress theme review coding conventions
MIT License
209 stars 37 forks source link

Allow short PHP echo tags #142

Open justintadlock opened 6 years ago

justintadlock commented 6 years ago

Short PHP <? tags should be disallowed (see: https://github.com/WPTRT/WordPress-Coding-Standards/issues/2). However, as of PHP 5.4, the short echo syntax <?= is always available. The sniffer should make a distinction between the two.

For those of us no longer coding for PHP versions that have reached EOL, it'd be nice to be able to use the short echo syntax, especially within templates.

Here's an example:

<?= esc_html( $var ) ?>

// vs.

<?php echo esc_html( $var ) ?>

Reference:

jrfnl commented 6 years ago

@justintadlock I've just looked into this. 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.

If this would be acceptable to PHPCS, I'd happily create the PR for it.

Would you be willing to write up & open the issue yourself in the PHPCS repo please ?

justintadlock commented 6 years ago

If you can point me to the correct place to post the issue, I'd be happy to create a ticket.

jrfnl commented 6 years ago

@justintadlock https://github.com/squizlabs/PHP_CodeSniffer/issues/ ;-)

jrfnl commented 6 years ago

@justintadlock Just saw the upstream issue & Greg's response. I had looked at the sniff, but must have completely overlooked the different error codes. Oh well... at least that means this can be fixed really easily.

justintadlock commented 6 years ago

Cool. I closed that ticket out.

dingo-d commented 5 years ago

Should this be added in the ruleset? The

<exclude name="Generic.PHP.DisallowShortOpenTag.EchoFound"/>

Or should we leave this out? @justintadlock