Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR1/PSR2 not reporting or fixing short open tags #1993

Closed
jondmcelroy opened this issue Apr 16, 2018 · 2 comments
Closed

PSR1/PSR2 not reporting or fixing short open tags #1993

jondmcelroy opened this issue Apr 16, 2018 · 2 comments
Milestone

Comments

@jondmcelroy
Copy link

I noticed that when running the sniffer (PSR2) against a file with short tags, that it does not find the problem.
When Processing the PS1 ruleset it shows that it is ignoring the DisallowShortOpenTag except for the EchoFound check.

.\.vendor\bin\phpcs --standard=PSR2 --exclude=PSR1.Methods.CamelCapsMethodName -vv -- .\ShortTagFile.php
...
Processing rule "Generic.PHP.DisallowShortOpenTag.EchoFound"
                                => .vendor\squizlabs\php_codesniffer\src\Standards\Generic\Sniffs\PHP\DisallowShortOpenTagSniff.php
       Excluding sniff "Generic.PHP.DisallowShortOpenTag" except for "EchoFound"
       => severity set to 0

It does this because the PSR1\ruleset.xml has this line:

 <rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound">
  <severity>0</severity>
 </rule>

If you change that rule to look like this:

 <rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound"/>

Then it works and produces this:

.\.vendor\bin\phpcs --standard=PSR2 -- .\ShortTagFile.php

FILE: .\ShortTagFile.php
-----------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------
 1 | ERROR | [x] Short PHP opening tag used; expected "<?php" but found "<?"
-----------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------

Is this expected behavior?
It seems like anyone trying to enforce PSR1/PSR2 will silently fail on this particular sniff.

I have short_open_tag set to on:

php -i | grep short
short_open_tag => On => On

ShortTagFile.php is this:

<?

$that = "page just has a short tag.";
@gsherwood gsherwood changed the title DisallowShortOpenTagSniff does not show an error or fix short tags (Standard: PSR1/PSR2) PSR1/PSR2 not reporting or fixing short open tags Apr 17, 2018
@gsherwood gsherwood added this to the 3.3.0 milestone Apr 17, 2018
@gsherwood
Copy link
Member

Thanks a lot for reporting this. The standard was not including the sniff properly before muting the error message. It now does what it is supposed to, which is ban short open tags except for short echo tags.

@jondmcelroy
Copy link
Author

Wow, quick turn around 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants