There are several sniffs which rely on file extension detection in order to execute. One example is Sniffs/ControlStructures/TemplateControlStructureSniff. This fails if you're invoking phpcs via standard input because the filename is STDIN. It's simply never called. I have a template file at https://gist.github.com/mackensen/745578705a5177528f16. Compare the output of cat homebox.tpl.php | phpcs --standard=Drupal and phpcs --standard=Drupal homebox.tpl.php (note the related error documented in #2365271: CodeSniffer end of file whitespace check fails when reading from STDIN). The outputs don't match because the filename isn't detected in stdin.
Comments
Comment #1
klausiAt first I thought we could just check if the file contains T_INLINE_HTML instead, but that also applies to txt README files that contain PHP code snippets. So we would need to come up with an idea how to reliably detect if we are in a template file without knowing the filename.
Comment #2
chasingmaxwell CreditAttribution: chasingmaxwell commentedI'm experiencing an issue that appears to be the same or related. I'm running phpcs against this file: https://gist.githubusercontent.com/chasingmaxwell/5a798f7457056f1438c6/r.... Here's what happens:
When running
phpcs --standard=Drupal test--template.tpl.php
, I do not get any errors.When running
cat test--template.tpl.php | phpcs --standard=Drupal
or using gulp-phpcs, or if I just change the file name to test--template.php I get the following errors:14 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 0
14 | ERROR | [x] Closing brace must be on a line by itself
14 | ERROR | [ ] The final ?> should be omitted from all code files
Comment #3
klausiCoder 7.x is frozen now and will not receive updates. Coder 8.x-2.x can be used to check code for any Drupal version, Coder 8.x-2.x also supports the phpcbf command to automatically fix conding standard errors. Please check if this issue is still relevant and reopen against that version if necessary.