Skip to content

Commit 03e893f

Browse files
authored
fix(PROW-124): Some tweaks for backend linting (#4)
* fix(PROW-124): Some tweaks for backend linting * fix(PROW-124): Some tweaks for backend linting * fix(PROW-124): Some tweaks for backend linting
1 parent 27f37a2 commit 03e893f

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ It contains the following linting tools at the moment:
2020

2121
## 1. Require the composer package
2222
```bash
23-
composer require --dev programic/php-backend-linting
23+
composer require --dev programic/php-linting-rules
2424
```
2525

2626
## 2. Run the setup command
@@ -44,6 +44,7 @@ composer lint:tlint
4444
composer lint:phpmd
4545
composer lint:phpstan
4646
composer lint:ecs
47+
composer lint:fix
4748
```
4849

4950
## Editor Setup

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configs/ecs.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,36 @@
3333
->withConfiguredRule(PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer::class, ['sort_algorithm' => 'none', 'null_adjustment' => 'always_last', 'case_sensitive' => false])
3434
->withConfiguredRule(PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer::class, ['tokens' => ['use']])
3535
->withConfiguredRule(PhpCsFixer\Fixer\Whitespace\TypesSpacesFixer::class, ['space' => 'single', 'space_multiple_catch' => 'single'])
36-
->withConfiguredRule(PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff::class, ['forbiddenFunctions' => ['compact' => null , 'dd' => null, 'dump' => null, 'var_dump' => null, 'ray' => null, 'only' => null]])
36+
->withConfiguredRule(PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff::class, ['forbiddenFunctions' => ['compact' => null, 'dd' => null, 'dump' => null, 'var_dump' => null, 'ray' => null, 'only' => null]])
3737
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Attributes\AttributeAndTargetSpacingSniff::class, ['linesCount' => 0])
3838
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\BackedEnumTypeSpacingSniff::class, ['spacesCountBeforeColon' => 0, 'spacesCountBeforeType' => 1])
3939
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\ClassMemberSpacingSniff::class, ['linesCountBetweenMembers' => 1])
4040
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\ConstantSpacingSniff::class, ['minLinesCountBeforeWithComment' => 1, 'maxLinesCountBeforeWithComment' => 1, 'minLinesCountBeforeWithoutComment' => 0, 'maxLinesCountBeforeWithoutComment' => 0])
41-
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\EmptyLinesAroundClassBracesSniff::class, ['linesCountAfterOpeningBrace' => 0, 'linesCountBeforeClosingBrace' => 0])
41+
// ->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\EmptyLinesAroundClassBracesSniff::class, ['linesCountAfterOpeningBrace' => 0, 'linesCountBeforeClosingBrace' => 0])
4242
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\EnumCaseSpacingSniff::class, ['minLinesCountBeforeWithComment' => 1, 'maxLinesCountBeforeWithComment' => 1, 'minLinesCountBeforeWithoutComment' => 0, 'maxLinesCountBeforeWithoutComment' => 0])
4343
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\MethodSpacingSniff::class, ['minLinesCount' => 1, 'maxLinesCount' => 1])
4444
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\ParentCallSpacingSniff::class, ['linesCountBefore' => 0, 'linesCountAfter' => 1])
4545
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\PropertySpacingSniff::class, ['minLinesCountBeforeWithComment' => 1, 'maxLinesCountBeforeWithComment' => 1, 'minLinesCountBeforeWithoutComment' => 0, 'maxLinesCountBeforeWithoutComment' => 0])
46-
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\TraitUseSpacingSniff::class, ['linesCountBeforeFirstUse' => 0, 'linesCountBeforeFirstUseWhenFirstInClass' => 0, 'linesCountBetweenUses' => 0, 'linesCountAfterLastUse' => 1, 'linesCountAfterLastUseWhenLastInClass' => 1])
46+
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Classes\TraitUseSpacingSniff::class, ['linesCountBeforeFirstUse' => 0, 'linesCountBeforeFirstUseWhenFirstInClass' => 0, 'linesCountBetweenUses' => 0, 'linesCountAfterLastUse' => 1, 'linesCountAfterLastUseWhenLastInClass' => 0])
4747
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff::class, ['linesCountBeforeFirstContent' => 0, 'linesCountBetweenDescriptionAndAnnotations' => 1, 'linesCountBetweenDifferentAnnotationsTypes' => 0, 'linesCountAfterLastContent' => 0])
48-
->withConfiguredRule(SlevomatCodingStandard\Sniffs\ControlStructures\BlockControlStructureSpacingSniff::class, ['linesCountBefore' => 1, 'linesCountBeforeFirst' => 1, 'linesCountAfter' => 1, 'linesCountAfterLast' => 1, 'controlStructures' => ['if', 'switch', 'for', 'foreach', 'while', 'do']])
49-
->withConfiguredRule(SlevomatCodingStandard\Sniffs\ControlStructures\JumpStatementsSpacingSniff::class, ['linesCountBefore' => 1, 'linesCountBeforeFirst' => 1, 'linesCountBeforeWhenFirstInCaseOrDefault' => 1, 'linesCountAfter' => 0, 'linesCountAfterLast' => 0, 'linesCountAfterWhenLastInCaseOrDefault' => 0, 'linesCountAfterWhenLastInLastCaseOrDefault' => 0, 'jumpStatements' => ['continue', 'break', 'yield', 'return', 'goto']])
48+
// ->withConfiguredRule(SlevomatCodingStandard\Sniffs\ControlStructures\BlockControlStructureSpacingSniff::class, ['linesCountBefore' => 1, 'linesCountBeforeFirst' => 1, 'linesCountAfter' => 1, 'linesCountAfterLast' => 1, 'controlStructures' => ['if', 'switch', 'for', 'foreach', 'while', 'do']])
49+
->withConfiguredRule(SlevomatCodingStandard\Sniffs\ControlStructures\JumpStatementsSpacingSniff::class, ['linesCountBefore' => 1, 'linesCountBeforeFirst' => 0, 'linesCountBeforeWhenFirstInCaseOrDefault' => 1, 'linesCountAfter' => 0, 'linesCountAfterLast' => 0, 'linesCountAfterWhenLastInCaseOrDefault' => 0, 'linesCountAfterWhenLastInLastCaseOrDefault' => 0, 'jumpStatements' => ['continue', 'break', 'yield', 'return', 'goto']])
5050
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Files\LineLengthSniff::class, ['lineLengthLimit' => 140])
5151
// ->withConfiguredRule(SlevomatCodingStandard\Sniffs\Files\TypeNameMatchesFileNameSniff::class, ['rootNamespaces' => ['app' => 'App'], 'skipDirs' => ['database/seeders', 'database/factories', 'tests'] ])
5252
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Functions\ArrowFunctionDeclarationSniff::class, ['spacesCountAfterKeyword' => 1, 'spacesCountBeforeArrow' => 1, 'spacesCountAfterArrow' => 1, 'allowMultiLine' => true])
5353
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Functions\DisallowTrailingCommaInCallSniff::class, ['onlySingleLine' => true])
5454
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Functions\DisallowTrailingCommaInClosureUseSniff::class, ['onlySingleLine' => true])
5555
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Functions\DisallowTrailingCommaInDeclarationSniff::class, ['onlySingleLine' => true])
5656
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Namespaces\AlphabeticallySortedUsesSniff::class, ['caseSensitive' => true, 'psr12Compatible' => true])
57-
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Namespaces\NamespaceSpacingSniff::class, ['linesCountBeforeNamespace' => 0, 'linesCountAfterNamespace' => 1])
57+
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Namespaces\NamespaceSpacingSniff::class, ['linesCountBeforeNamespace' => 1, 'linesCountAfterNamespace' => 1])
5858
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff::class, ['allowFullyQualifiedExceptions' => false, 'searchAnnotations' => true, 'allowFullyQualifiedNameForCollidingClasses' => false, 'allowFullyQualifiedNameForCollidingFunctions' => false, 'allowFullyQualifiedNameForCollidingConstants' => false, 'allowFullyQualifiedGlobalClasses' => false, 'allowFullyQualifiedGlobalFunctions' => false, 'allowFullyQualifiedGlobalConstants' => false, 'allowFallbackGlobalFunctions' => true, 'allowFallbackGlobalConstants' => true, 'allowPartialUses' => true])
5959
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Namespaces\UnusedUsesSniff::class, ['searchAnnotations' => true])
6060
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff::class, ['linesCountBeforeFirstUse' => 1, 'linesCountBetweenUseTypes' => 1, 'linesCountAfterLastUse' => 1])
6161
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Numbers\RequireNumericLiteralSeparatorSniff::class, ['minDigitsBeforeDecimalPoint' => 4, 'minDigitsAfterDecimalPoint' => 3])
6262
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Operators\NegationOperatorSpacingSniff::class, ['spacesCount' => 0])
6363
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Operators\SpreadOperatorSpacingSniff::class, ['spacesCountAfterOperator' => 0])
6464
->withConfiguredRule(SlevomatCodingStandard\Sniffs\PHP\ReferenceSpacingSniff::class, ['spacesCountAfterReference' => 0])
65-
->withConfiguredRule(SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff::class, [])
65+
// ->withConfiguredRule(SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff::class, [])
6666
->withConfiguredRule(SlevomatCodingStandard\Sniffs\Whitespaces\DuplicateSpacesSniff::class, ['ignoreSpacesInComment' => true])
6767
->withRules([
6868
// PHPCS fixer rules
@@ -270,7 +270,7 @@
270270
SlevomatCodingStandard\Sniffs\Commenting\EmptyCommentSniff::class,
271271
SlevomatCodingStandard\Sniffs\Commenting\ForbiddenCommentsSniff::class,
272272
SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff::class,
273-
SlevomatCodingStandard\Sniffs\Commenting\RequireOneLineDocCommentSniff::class,
273+
// SlevomatCodingStandard\Sniffs\Commenting\RequireOneLineDocCommentSniff::class,
274274
SlevomatCodingStandard\Sniffs\Commenting\UselessFunctionDocCommentSniff::class,
275275
SlevomatCodingStandard\Sniffs\Commenting\UselessInheritDocCommentSniff::class,
276276
SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff::class,
@@ -282,7 +282,7 @@
282282
SlevomatCodingStandard\Sniffs\ControlStructures\RequireNullCoalesceOperatorSniff::class,
283283
SlevomatCodingStandard\Sniffs\ControlStructures\RequireNullSafeObjectOperatorSniff::class,
284284
SlevomatCodingStandard\Sniffs\ControlStructures\RequireShortTernaryOperatorSniff::class,
285-
SlevomatCodingStandard\Sniffs\ControlStructures\RequireYodaComparisonSniff::class,
285+
// SlevomatCodingStandard\Sniffs\ControlStructures\RequireYodaComparisonSniff::class,
286286
SlevomatCodingStandard\Sniffs\ControlStructures\UselessIfConditionWithReturnSniff::class,
287287
SlevomatCodingStandard\Sniffs\ControlStructures\UselessTernaryOperatorSniff::class,
288288
SlevomatCodingStandard\Sniffs\Exceptions\DeadCatchSniff::class,
@@ -327,4 +327,29 @@
327327
SlevomatCodingStandard\Sniffs\Variables\DisallowSuperGlobalVariableSniff::class,
328328
SlevomatCodingStandard\Sniffs\Variables\DuplicateAssignmentToVariableSniff::class,
329329
SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff::class,
330+
])->withSkip([
331+
SlevomatCodingStandard\Sniffs\Functions\UnusedParameterSniff::class => [
332+
getcwd() . '/app/Traits',
333+
getcwd() . '/app/Policies',
334+
getcwd() . '/app/Models',
335+
],
336+
SlevomatCodingStandard\Sniffs\Functions\DisallowEmptyFunctionSniff::class => [
337+
getcwd() . '/app/Providers',
338+
],
339+
SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff::class => [
340+
getcwd() . '/app/Models',
341+
],
342+
SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff::class => [
343+
getcwd() . '/app/Models',
344+
],
345+
PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer::class => [
346+
getcwd() . '/app/Models',
347+
],
348+
SlevomatCodingStandard\Sniffs\Classes\ClassStructureSniff::class => [
349+
getcwd() . '/app/Models',
350+
],
351+
SlevomatCodingStandard\Sniffs\Files\LineLengthSniff::class => [
352+
getcwd() . '/database/seeders',
353+
getcwd() . '/database/migrations',
354+
],
330355
]);

configs/phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ parameters:
5151
- '/Generic type .* in PHPDoc tag @return does not specify all template types of class Illuminate\\Database\\Eloquent\\Relations.*: TRelatedModel, TDeclaringModel/'
5252
- '#Cannot access property \$[a-zA-Z0-9\\_]+ on App\\Models\\User\|null#'
5353
- '#Cannot call method [a-zA-Z0-9\\_]+\(\) on App\\Models\\User\|null#'
54+
- message: '/Undefined variable: \$this/'
55+
path: tests/
56+
- identifier: method.childReturnType
57+
path: database/factories/

stubs/ecs.php.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ return ECSConfig::configure()
66
->withPaths([
77
__DIR__ . '/app',
88
__DIR__ . '/tests',
9+
__DIR__ . '/routes',
10+
__DIR__ . '/database',
11+
__DIR__ . '/config',
912
])
1013
->withSets([
1114
__DIR__ . '/vendor/programic/php-linting-rules/configs/ecs.php',

0 commit comments

Comments
 (0)