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

PEAR/ScopeClosingBrace: prevent fixer conflict with itself #423

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/Standards/PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,19 @@ public function process(File $phpcsFile, $stackPtr)
}

// Check that the closing brace is on it's own line.
$lastContent = $phpcsFile->findPrevious(
[
T_WHITESPACE,
T_INLINE_HTML,
T_OPEN_TAG,
],
($scopeEnd - 1),
$scopeStart,
true
);
for ($lastContent = ($scopeEnd - 1); $lastContent > $scopeStart; $lastContent--) {
if ($tokens[$lastContent]['code'] === T_WHITESPACE || $tokens[$lastContent]['code'] === T_OPEN_TAG) {
continue;
}

if ($tokens[$lastContent]['code'] === T_INLINE_HTML
&& ltrim($tokens[$lastContent]['content']) === ''
) {
continue;
}

break;
}

if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) {
$error = 'Closing brace must be on a line by itself';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,9 @@ enum Suits {}
enum Cards
{
}

?>
<!-- Prevent fixer conflict with itself when the scope closer is preceded by non-empty/non-indentation inline HTML. -->
<?php if ($someConditional) : ?>
<div class="container">
</div> <?php endif;
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,10 @@ enum Suits {
enum Cards
{
}

?>
<!-- Prevent fixer conflict with itself when the scope closer is preceded by non-empty/non-indentation inline HTML. -->
<?php if ($someConditional) : ?>
<div class="container">
</div> <?php
endif;
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function getErrorList()
154 => 1,
160 => 1,
164 => 1,
170 => 1,
];

}//end getErrorList()
Expand Down