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

Zend.Files.ClosingTag removes closing tag from end of file without inserting a semicolon #2146

Closed
TysonAndre opened this issue Aug 30, 2018 · 1 comment
Milestone

Comments

@TysonAndre
Copy link
Contributor

TysonAndre commented Aug 30, 2018

Version: I'm able to reproduce this in the latest commit.
Expected: If <?= is used and a semicolon is needed in the fixed file, a semicolon should be inserted at an appropriate place (e.g. not as part of a line comment). (Or skip warning about it and fixing it)
Observed: No semicolon is inserted

The input file

text
<?php include($this->add('arg'))?>

The observed result (results in a parse error):

text
<?php include($this->add('arg'))

An example ruleset.xml:

<?xml version="1.0"?>
<ruleset name="ifwe">
    <description>Example coding standard</description>

    <rule ref="Zend">
    </rule>

</ruleset>

Command: path/to/PHP_CodeSniffer/bin/phpcbf --standard=ruleset.xml src/bug.php


A workaround is to exclude Zend.Files.ClosingTag.NotAllowed and include PSR2.Files.ClosingTag.NotAllowed or PSR2.

@gsherwood gsherwood added this to the 3.3.2 milestone Sep 5, 2018
@gsherwood gsherwood changed the title Bug: Zend.Files.ClosingTag.NotAllowed removes closing tag from end of file without inserting a semicolon Zend.Files.ClosingTag removes closing tag from end of file without inserting a semicolon Sep 5, 2018
gsherwood added a commit that referenced this issue Sep 5, 2018
@gsherwood
Copy link
Member

Thanks for reporting this. The fix will be in 3.3.2.

You may also consider using PSR2.Files.ClosingTag instead of the Zend sniff. It already accounted for this and only enforces no closing tag when the file is PHP-only. In the mixed case (like in your example) the closing tag would be allowed. That's obviously personal preference, but thought I'd point it out in case you wanted the tag kept in these cases.

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