TomasVotruba / class-leak

Find leaking classes that you never use... and get rid of them.
https://tomasvotruba.com/blog/how-to-avoid-maintaining-classes-you-dont-use
MIT License
75 stars 6 forks source link

Latest class-leak version 0.2.12 - 0.2.13 cause error in rector-src #43

Closed samsonasik closed 5 months ago

samsonasik commented 5 months ago

see https://github.com/rectorphp/rector-src/actions/runs/8854029950/job/24316165596?pr=5845#step:5:1

Before => 0.2.11

➜  rector-src git:(cache-classname) vendor/bin/class-leak check bin config src rules \
                                --skip-type="Rector\\NodeTypeResolver\\PHPStan\\Scope\\Contract\\NodeVisitor\\ScopeResolverNodeVisitorInterface" \
                                --skip-type="Rector\\BetterPhpDocParser\\Contract\\BasePhpDocNodeVisitorInterface" \
                                --skip-type="Rector\\BetterPhpDocParser\\Contract\\PhpDocParser\\PhpDocNodeDecoratorInterface" \
                                --skip-type="Rector\\BetterPhpDocParser\\ValueObject\\Type\\FullyQualifiedIdentifierTypeNode"
    0/1142 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
 1142/1142 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 [OK] All the 508 services are used. Great job!                                                                         

After => 0.2.13

rector-src git:(cache-classname) vendor/bin/class-leak check bin config src rules \
                                --skip-type="Rector\\NodeTypeResolver\\PHPStan\\Scope\\Contract\\NodeVisitor\\ScopeResolverNodeVisitorInterface" \
                                --skip-type="Rector\\BetterPhpDocParser\\Contract\\BasePhpDocNodeVisitorInterface" \
                                --skip-type="Rector\\BetterPhpDocParser\\Contract\\PhpDocParser\\PhpDocNodeDecoratorInterface" \
                                --skip-type="Rector\\BetterPhpDocParser\\ValueObject\\Type\\FullyQualifiedIdentifierTypeNode"
    0/1142 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
 1142/1142 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

Classes with a parent/interface - possibly used by type
=======================================================

 * Rector\Arguments\Rector\MethodCall\RemoveMethodCallParamRector
rules/Arguments/Rector/MethodCall/RemoveMethodCallParamRector.php

 * Rector\CodeQuality\Rector\FuncCall\BoolvalToTypeCastRector
rules/CodeQuality/Rector/FuncCall/BoolvalToTypeCastRector.php

 * Rector\CodeQuality\Rector\FuncCall\FloatvalToTypeCastRector
rules/CodeQuality/Rector/FuncCall/FloatvalToTypeCastRector.php

 * Rector\CodeQuality\Rector\FuncCall\IntvalToTypeCastRector
rules/CodeQuality/Rector/FuncCall/IntvalToTypeCastRector.php

 * Rector\CodeQuality\Rector\FuncCall\StrvalToTypeCastRector
rules/CodeQuality/Rector/FuncCall/StrvalToTypeCastRector.php

 * Rector\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector
rules/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php

 * Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector
rules/DeadCode/Rector/ClassLike/RemoveAnnotationRector.php

 * Rector\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector
rules/DeadCode/Rector/ClassMethod/RemoveNullTagValueNodeRector.php

 * Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector
rules/Php73/Rector/FuncCall/JsonThrowOnErrorRector.php

 * Rector\Php80\Rector\Class_\AnnotationToAttributeRector
rules/Php80/Rector/Class_/AnnotationToAttributeRector.php

 * Rector\Php80\Rector\Property\NestedAnnotationToAttributeRector
rules/Php80/Rector/Property/NestedAnnotationToAttributeRector.php

 * Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector
rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php

 * Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector
rules/Privatization/Rector/Class_/FinalizeClassesWithoutChildrenRector.php

 * Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector
rules/Privatization/Rector/Class_/FinalizeTestCaseClassRector.php

 * Rector\Removing\Rector\ClassMethod\ArgumentRemoverRector
rules/Removing/Rector/ClassMethod/ArgumentRemoverRector.php

 * Rector\Removing\Rector\Class_\RemoveInterfacesRector
rules/Removing/Rector/Class_/RemoveInterfacesRector.php

 * Rector\Removing\Rector\Class_\RemoveTraitUseRector
rules/Removing/Rector/Class_/RemoveTraitUseRector.php

 * Rector\Removing\Rector\FuncCall\RemoveFuncCallRector
rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php

 * Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector
rules/Renaming/Rector/ClassConstFetch/RenameClassConstFetchRector.php

 * Rector\Renaming\Rector\ClassMethod\RenameAnnotationRector
rules/Renaming/Rector/ClassMethod/RenameAnnotationRector.php

 * Rector\Renaming\Rector\ConstFetch\RenameConstantRector
rules/Renaming/Rector/ConstFetch/RenameConstantRector.php

 * Rector\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector
rules/Renaming/Rector/FunctionLike/RenameFunctionLikeParamWithinCallLikeArgRector.php

 * Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector
rules/Renaming/Rector/PropertyFetch/RenamePropertyRector.php

 * Rector\Renaming\Rector\StaticCall\RenameStaticMethodRector
rules/Renaming/Rector/StaticCall/RenameStaticMethodRector.php

 * Rector\Renaming\Rector\String_\RenameStringRector
rules/Renaming/Rector/String_/RenameStringRector.php

 * Rector\Transform\Rector\ArrayDimFetch\ArrayDimFetchToMethodCallRector
rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php

 * Rector\Transform\Rector\Assign\PropertyAssignToMethodCallRector
rules/Transform/Rector/Assign/PropertyAssignToMethodCallRector.php

 * Rector\Transform\Rector\Assign\PropertyFetchToMethodCallRector
rules/Transform/Rector/Assign/PropertyFetchToMethodCallRector.php

 * Rector\Transform\Rector\ClassMethod\ReturnTypeWillChangeRector
rules/Transform/Rector/ClassMethod/ReturnTypeWillChangeRector.php

 * Rector\Transform\Rector\ClassMethod\WrapReturnRector
rules/Transform/Rector/ClassMethod/WrapReturnRector.php

 * Rector\Transform\Rector\Class_\AddAllowDynamicPropertiesAttributeRector
rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php

 * Rector\Transform\Rector\Class_\MergeInterfacesRector
rules/Transform/Rector/Class_/MergeInterfacesRector.php

 * Rector\Transform\Rector\Class_\ParentClassToTraitsRector
rules/Transform/Rector/Class_/ParentClassToTraitsRector.php

 * Rector\Transform\Rector\ConstFetch\ConstFetchToClassConstFetchRector
rules/Transform/Rector/ConstFetch/ConstFetchToClassConstFetchRector.php

 * Rector\Transform\Rector\FileWithoutNamespace\RectorConfigBuilderRector
rules/Transform/Rector/FileWithoutNamespace/RectorConfigBuilderRector.php

 * Rector\Transform\Rector\FuncCall\FuncCallToMethodCallRector
rules/Transform/Rector/FuncCall/FuncCallToMethodCallRector.php

 * Rector\Transform\Rector\FuncCall\FuncCallToNewRector
rules/Transform/Rector/FuncCall/FuncCallToNewRector.php

 * Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector
rules/Transform/Rector/FuncCall/FuncCallToStaticCallRector.php

 * Rector\Transform\Rector\MethodCall\MethodCallToFuncCallRector
rules/Transform/Rector/MethodCall/MethodCallToFuncCallRector.php

 * Rector\Transform\Rector\MethodCall\MethodCallToPropertyFetchRector
rules/Transform/Rector/MethodCall/MethodCallToPropertyFetchRector.php

 * Rector\Transform\Rector\MethodCall\MethodCallToStaticCallRector
rules/Transform/Rector/MethodCall/MethodCallToStaticCallRector.php

 * Rector\Transform\Rector\MethodCall\ReplaceParentCallByPropertyCallRector
rules/Transform/Rector/MethodCall/ReplaceParentCallByPropertyCallRector.php

 * Rector\Transform\Rector\New_\NewToStaticCallRector
rules/Transform/Rector/New_/NewToStaticCallRector.php

 * Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector
rules/Transform/Rector/StaticCall/StaticCallToMethodCallRector.php

 * Rector\Transform\Rector\StaticCall\StaticCallToNewRector
rules/Transform/Rector/StaticCall/StaticCallToNewRector.php

 * Rector\Transform\Rector\String_\StringToClassConstantRector
rules/Transform/Rector/String_/StringToClassConstantRector.php

 * Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector
rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php

 * Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector
rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationRector.php

 * Rector\TypeDeclaration\Rector\FunctionLike\AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector
rules/TypeDeclaration/Rector/FunctionLike/AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector.php

 * Rector\TypeDeclaration\Rector\Property\AddPropertyTypeDeclarationRector
rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php

 * Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector
rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php

 * Rector\Visibility\Rector\ClassConst\ChangeConstantVisibilityRector
rules/Visibility/Rector/ClassConst/ChangeConstantVisibilityRector.php

 * Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector
rules/Visibility/Rector/ClassMethod/ChangeMethodVisibilityRector.php

Classes without any parent/interface - easier to remove
=======================================================

 * Rector\PhpDocParser\PhpParser\SmartPhpParserFactory
src/PhpDocParser/PhpParser/SmartPhpParserFactory.php

 [ERROR] Found 54 unused classes. Check and remove them or skip them using "--skip-type" option                         
samsonasik commented 5 months ago

I temporary pin to 0.2.11 at https://github.com/rectorphp/rector-src/pull/5846

staabm commented 5 months ago

I think the reported problem are correct and were not detected before because of a bug in class-leak (classes with comments were always considered used).

Fixed the class-leak config in rector with https://github.com/rectorphp/rector-src/pull/5847