From c7f260edb77ff5a7f551ab8a04b39c6069380cde Mon Sep 17 00:00:00 2001 From: Asis Pattisahusiwa <79239132+asispts@users.noreply.github.com> Date: Fri, 3 Nov 2023 19:30:10 +0700 Subject: [PATCH] Disallow empty function unless adding a comment (#18) --- ptscs/ruleset.xml | 1 + .../UnnecessaryFinalModifierTest.php | 1 + .../Functions/DisallowEmptyFunctionTest.php | 23 +++++++++++++++++++ .../_data/DisallowEmptyFunction.php.fixed | 10 ++++++++ .../_data/DisallowEmptyFunction.php.inc | 10 ++++++++ .../_data/ParameterTypeHint.php.fixed | 1 + .../TypeHints/_data/ParameterTypeHint.php.inc | 1 + tests/Sniffs/Slevomat/UnusedUseTest.php | 5 +++- tests/Sniffs/Squiz/ClassMethodTest.php | 1 + tests/Sniffs/Squiz/FunctionsTest.php | 1 + 10 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/Sniffs/Slevomat/Functions/DisallowEmptyFunctionTest.php create mode 100644 tests/Sniffs/Slevomat/Functions/_data/DisallowEmptyFunction.php.fixed create mode 100644 tests/Sniffs/Slevomat/Functions/_data/DisallowEmptyFunction.php.inc diff --git a/ptscs/ruleset.xml b/ptscs/ruleset.xml index f28979d..7675c2a 100644 --- a/ptscs/ruleset.xml +++ b/ptscs/ruleset.xml @@ -192,6 +192,7 @@ + diff --git a/tests/Sniffs/CodeAnalysis/UnnecessaryFinalModifierTest.php b/tests/Sniffs/CodeAnalysis/UnnecessaryFinalModifierTest.php index 8ddc6fb..0c31df0 100644 --- a/tests/Sniffs/CodeAnalysis/UnnecessaryFinalModifierTest.php +++ b/tests/Sniffs/CodeAnalysis/UnnecessaryFinalModifierTest.php @@ -15,6 +15,7 @@ protected function setUp(): void 'Squiz.Classes.ClassFileName.NoMatch', 'PSR1.Classes.ClassDeclaration.MultipleClasses', 'SlevomatCodingStandard.Classes.RequireAbstractOrFinal', + 'SlevomatCodingStandard.Functions.DisallowEmptyFunction', ]); } diff --git a/tests/Sniffs/Slevomat/Functions/DisallowEmptyFunctionTest.php b/tests/Sniffs/Slevomat/Functions/DisallowEmptyFunctionTest.php new file mode 100644 index 0000000..d2fc462 --- /dev/null +++ b/tests/Sniffs/Slevomat/Functions/DisallowEmptyFunctionTest.php @@ -0,0 +1,23 @@ +appendExclude('Squiz.Classes.ClassFileName.NoMatch'); + } + + public static function provideTestData(): Iterator + { + yield[ + [new ErrorData(3, 'SlevomatCodingStandard.Functions.DisallowEmptyFunction.EmptyFunction')], + ]; + } +} diff --git a/tests/Sniffs/Slevomat/Functions/_data/DisallowEmptyFunction.php.fixed b/tests/Sniffs/Slevomat/Functions/_data/DisallowEmptyFunction.php.fixed new file mode 100644 index 0000000..2a1d0de --- /dev/null +++ b/tests/Sniffs/Slevomat/Functions/_data/DisallowEmptyFunction.php.fixed @@ -0,0 +1,10 @@ +setExclude(['Squiz.Classes.ClassFileName.NoMatch']); + $this->setExclude([ + 'Squiz.Classes.ClassFileName.NoMatch', + 'SlevomatCodingStandard.Functions.DisallowEmptyFunction', + ]); } public static function provideTestData(): Iterator diff --git a/tests/Sniffs/Squiz/ClassMethodTest.php b/tests/Sniffs/Squiz/ClassMethodTest.php index 7969eef..266b0ed 100644 --- a/tests/Sniffs/Squiz/ClassMethodTest.php +++ b/tests/Sniffs/Squiz/ClassMethodTest.php @@ -14,6 +14,7 @@ protected function setUp(): void $this->appendExclude('Squiz.Classes.ClassFileName'); $this->appendExclude('Generic.PHP.RequireStrictTypes.MissingDeclaration'); $this->appendExclude('SlevomatCodingStandard.Classes.RequireAbstractOrFinal'); + $this->appendExclude('SlevomatCodingStandard.Functions.DisallowEmptyFunction'); } public static function provideTestData(): Iterator diff --git a/tests/Sniffs/Squiz/FunctionsTest.php b/tests/Sniffs/Squiz/FunctionsTest.php index 51f866a..a83f658 100644 --- a/tests/Sniffs/Squiz/FunctionsTest.php +++ b/tests/Sniffs/Squiz/FunctionsTest.php @@ -11,6 +11,7 @@ final class FunctionsTest extends SniffTestCase protected function setUp(): void { $this->appendExclude('PSR1.Files.SideEffects.FoundWithSymbols'); + $this->appendExclude('SlevomatCodingStandard.Functions.DisallowEmptyFunction'); } public static function provideTestData(): Iterator