From 4032f7d16fdeb16bd0dafc1d9613e82d8f521c47 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 25 Apr 2019 13:14:26 +0200 Subject: [PATCH 1/2] :bug: Fix the way comment before return is handled --- .../Sniffs/Formatting/BlankLineBeforeReturnSniff.php | 6 ++++-- .../Tests/Formatting/BlankLineBeforeReturnUnitTest.inc | 6 ++++++ .../Formatting/BlankLineBeforeReturnUnitTest.inc.fixed | 6 ++++++ .../Tests/Formatting/BlankLineBeforeReturnUnitTest.php | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php b/SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php index 462d012..54b9181 100644 --- a/SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php +++ b/SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php @@ -37,12 +37,14 @@ public function process(File $phpcsFile, $stackPtr) $tokens = $phpcsFile->getTokens(); $current = $stackPtr; $previousLine = $tokens[$stackPtr]['line'] - 1; - $prevLineTokens = array(); + $prevLineTokens = array(); while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) { if ($tokens[$current]['line'] === $previousLine && 'T_WHITESPACE' !== $tokens[$current]['type'] && 'T_COMMENT' !== $tokens[$current]['type'] + && 'T_DOC_COMMENT_STRING' !== $tokens[$current]['type'] + && 'T_DOC_COMMENT_OPEN_TAG' !== $tokens[$current]['type'] && 'T_DOC_COMMENT_CLOSE_TAG' !== $tokens[$current]['type'] && 'T_DOC_COMMENT_WHITESPACE' !== $tokens[$current]['type'] ) { @@ -62,7 +64,7 @@ public function process(File $phpcsFile, $stackPtr) $fix = $phpcsFile->addFixableError( 'Missing blank line before return statement', $stackPtr, - 'MissedBlankLineBeforeRetrun' + 'MissedBlankLineBeforeReturn' ); if (true === $fix) { diff --git a/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc b/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc index 90dd845..eb803bf 100644 --- a/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc +++ b/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc @@ -31,6 +31,12 @@ function validFunctionReturnFive() return; } +function validFunctionReturnSix() +{ + /** comment */ + return; +} + function invalidFunctionReturnOne() { echo ""; diff --git a/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc.fixed b/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc.fixed index a581405..3cd4606 100644 --- a/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc.fixed +++ b/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc.fixed @@ -31,6 +31,12 @@ function validFunctionReturnFive() return; } +function validFunctionReturnSix() +{ + /** comment */ + return; +} + function invalidFunctionReturnOne() { echo ""; diff --git a/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.php b/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.php index 4e70da5..48bc1bb 100644 --- a/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.php +++ b/SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.php @@ -22,7 +22,7 @@ class BlankLineBeforeReturnUnitTest extends AbstractSniffUnitTest public function getErrorList() { return array( - 37 => 1, + 43 => 1, ); } From 46f04a41a89153d569910377a2908d58f66eb84f Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 25 Apr 2019 13:15:25 +0200 Subject: [PATCH 2/2] :books: Fix doc --- docs/installation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index 8d79559..602b594 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -5,7 +5,7 @@ This standard can be installed with the [Composer](https://getcomposer.org/) dep 1. Add the coding standard as a dependency of your project ``` -composer require --dev vincentlanglet/symfony3-custom-coding-standard +composer require --dev vincentlanglet/symfony-custom-coding-standard ``` 2. Add the coding standard to the PHP_CodeSniffer install path @@ -14,7 +14,7 @@ The path is relative to the php_codesniffer install path. This is important to make it work both in your vagrant, local machine and PHPStorm ``` -bin/phpcs --config-set installed_paths ../../vincentlanglet/symfony3-custom-coding-standard +bin/phpcs --config-set installed_paths ../../vincentlanglet/symfony-custom-coding-standard ``` 3. Check the installed coding standards