squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

Squiz/EmbeddedPhp doesn't examine code using short open echo tag #3705

Closed jrfnl closed 9 months ago

jrfnl commented 1 year ago

Given this code:

<?php   echo $var   ?>

Running the Squiz.PHP.EmbeddedPhp sniff over it results in:

-------------------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] Expected 1 space after opening PHP tag; 3 found
   |       |     (Squiz.PHP.EmbeddedPhp.SpacingAfterOpen)
 1 | ERROR | [x] Inline PHP statement must end with a semicolon (Squiz.PHP.EmbeddedPhp.NoSemicolon)
 1 | ERROR | [x] Expected 1 space before closing PHP tag; 3 found
   |       |     (Squiz.PHP.EmbeddedPhp.SpacingBeforeClose)
-------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------

... while running the same sniff over the below code doesn't yield any errors:

<?=   $var   ?>

Questions

  1. Should the T_OPEN_TAG_WITH_ECHO token be added to the sniff ?
  2. If so and as the sniff would now start acting on more files, should the error codes for issues found in embedded PHP statements using short open echo tags be different ?
jrfnl commented 9 months ago

Closing as replaced by PHPCSStandards/PHP_CodeSniffer#27

jrfnl commented 6 months ago

FYI: a fix for this issue is included in today's PHP_CodeSniffer 3.9.0 release.