Skip to content

Commit

Permalink
PSR2/EndFileNewline: check files using only short open echo tag
Browse files Browse the repository at this point in the history
As per the standard:
> All PHP files MUST end with a single blank line

This does not exclude files which are mixed PHP/HTML.

Includes unit tests.
  • Loading branch information
jrfnl committed Apr 22, 2021
1 parent ae4f33b commit b094c94
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,13 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.9.inc.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.10.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.10.inc.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.11.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.11.inc.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.12.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.12.inc.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.13.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.13.inc.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.14.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="EndFileNewlineUnitTest.php" role="test" />
</dir>
<dir name="Methods">
Expand Down
5 changes: 4 additions & 1 deletion src/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class EndFileNewlineSniff implements Sniff
*/
public function register()
{
return [T_OPEN_TAG];
return [
T_OPEN_TAG,
T_OPEN_TAG_WITH_ECHO,
];

}//end register()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= 'foo';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= 'foo';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= 'foo' ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= 'foo' ?>
5 changes: 5 additions & 0 deletions src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.13.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?= 'foo'




Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= 'foo'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= 'foo' ?>
4 changes: 4 additions & 0 deletions src/Standards/PSR2/Tests/Files/EndFileNewlineUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function getErrorList($testFile='')
case 'EndFileNewlineUnitTest.9.inc':
case 'EndFileNewlineUnitTest.10.inc':
return [2 => 1];
case 'EndFileNewlineUnitTest.11.inc':
case 'EndFileNewlineUnitTest.12.inc':
case 'EndFileNewlineUnitTest.13.inc':
return [1 => 1];
default:
return [];
}//end switch
Expand Down

0 comments on commit b094c94

Please sign in to comment.