From 6e9d815a1f95aa2e1e505d0bfa4dde0febee5b92 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 22 Mar 2023 20:41:04 +0100 Subject: [PATCH] Fixes #9. Add space before next meaningful line of code and skip comments --- CHANGELOG.md | 1 + src/Fixer/Whitespace/LineBreakAfterStatementsFixer.php | 4 ++-- .../Whitespace/LineBreakAfterStatementsFixerTest.php | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cafea6..e24325b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Fixed - Bug #10: `Ely/blank_line_before_return` don't treat interpolation curly bracket as beginning of the scope. +- Bug #9: `Ely/line_break_after_statements` add space before next meaningful line of code and skip comments. ## [0.4.0] - 2022-12-06 ### Added diff --git a/src/Fixer/Whitespace/LineBreakAfterStatementsFixer.php b/src/Fixer/Whitespace/LineBreakAfterStatementsFixer.php index 0bcc605..db75d0b 100644 --- a/src/Fixer/Whitespace/LineBreakAfterStatementsFixer.php +++ b/src/Fixer/Whitespace/LineBreakAfterStatementsFixer.php @@ -26,7 +26,7 @@ final class LineBreakAfterStatementsFixer extends AbstractFixer implements White /** * There is no 'do', 'cause the processing of the 'while' also includes do {} while (); construction */ - public const STATEMENTS = [ + private const STATEMENTS = [ T_IF, T_SWITCH, T_FOR, @@ -93,7 +93,7 @@ class Foo } $endStatementIndex = $this->findStatementEnd($tokens, $index); - $nextStatementIndex = $tokens->getNextNonWhitespace($endStatementIndex); + $nextStatementIndex = $tokens->getNextMeaningfulToken($endStatementIndex); if ($nextStatementIndex === null) { continue; } diff --git a/tests/Fixer/Whitespace/LineBreakAfterStatementsFixerTest.php b/tests/Fixer/Whitespace/LineBreakAfterStatementsFixerTest.php index 35c2036..e23d142 100644 --- a/tests/Fixer/Whitespace/LineBreakAfterStatementsFixerTest.php +++ b/tests/Fixer/Whitespace/LineBreakAfterStatementsFixerTest.php @@ -575,6 +575,14 @@ class Foo } }', ]; + + yield [ + ' 10); // comment here + ', + ]; } protected function createFixer(): AbstractFixer {