From 382cfe2aa723e1adfdce0fd2fe265bb56372e3d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Thu, 16 May 2024 11:08:51 +0200 Subject: [PATCH] Docs: Add another suggested fixer to README --- README.md | 20 ++++++++++++++++---- ecs-internal.php | 5 +++++ src/Sniffs/Naming/AbstractClassNameSniff.php | 1 - 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 62e17be..17a6a7b 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,9 @@ Now you will be able to run the fix using `composer analyze` and execute automat ### Add custom checks or override default settings On top of the default code-style rules, you are free to add any rules from [PHP-CS-Fixer] or [PHP_CodeSniffer]. -If needed, you can also override some default settings. +If needed, you can also override any default settings. + +Below find examples of some more opinionated checks you may want to add depending on your needs: ```php withRules( + [ + // PHPUnit attributes must be used over their respective PHPDoc-based annotations. (Use with PHPUnit 10+.) + PhpUnitAttributesFixer::class, + // Single-line comments must have proper spacing. + SingleLineCommentSpacingFixer::class, + ] + ) + // Enforce line-length to 120 characters. ->withConfiguredRule(LineLengthSniff::class, ['absoluteLineLimit' => 120]) - // Tests must have @test annotation - ->withConfiguredRule(PhpUnitTestAnnotationFixer::class, ['style' => 'annotation']); + // Tests must have @test annotation. + ->withConfiguredRule(PhpUnitTestAnnotationFixer::class, ['style' => 'annotation']) + // Specify elements separation. + ->withConfiguredRule(ClassAttributesSeparationFixer::class, ['elements' => ['const' => 'none', 'method' => 'one', 'property' => 'none']]) /* (...) */ ``` diff --git a/ecs-internal.php b/ecs-internal.php index ac83458..10faf9b 100644 --- a/ecs-internal.php +++ b/ecs-internal.php @@ -1,6 +1,7 @@ 120, 'break_long_lines' => true, 'inline_short_lines' => false], ) + ->withConfiguredRule( + ClassAttributesSeparationFixer::class, + ['elements' => ['const' => 'none', 'method' => 'one', 'property' => 'none']] + ) ->withSkip( [ ForbiddenFunctionsSniff::class => ['tests/Integration/CodingStandardTest.php'], diff --git a/src/Sniffs/Naming/AbstractClassNameSniff.php b/src/Sniffs/Naming/AbstractClassNameSniff.php index 54a1503..a237777 100644 --- a/src/Sniffs/Naming/AbstractClassNameSniff.php +++ b/src/Sniffs/Naming/AbstractClassNameSniff.php @@ -48,7 +48,6 @@ public function register(): array { return [T_CLASS]; } - public function process(File $phpcsFile, $stackPtr): void { $this->file = $phpcsFile;