Open adamcameron opened 7 years ago
Hi @adamcameron
Thank you for your feature request.
I'm not against it, though we have to think this through, first.
Could you do me a favor? Could you add a table of all rules here with three infos: Name, whether the rule already supports an execption white-list and in what way it does or in what way it should do so.
Example:
Rule Name | Supports Exceptions | How |
---|---|---|
ShortVariable | Yes | Full variable name gets ignored. |
This way we can get an overview and do not rush in. 😼
Sure thing. I'm on the clock slightly today, and then out of circulation for a coupla days, but will get onto it as soon as I can.
No problem. Take your time. Thanks!
@adamcameron could you give me hand on this?
Ooh bugger... completely forgot about this. On the case. Sorry about the delay.
Rule Name | Supports Exceptions | How | Note |
---|---|---|---|
BooleanArgumentFlag |
No | - | * |
ElseExpression |
No | - | * |
IfStatementAssignment |
No | - | * |
StaticAccess |
Yes | List of classes to ignore | |
CyclomaticComplexity |
No | - | * |
NPathComplexity |
No | - | * |
ExcessiveMethodLength |
No | - | * |
ExcessiveClassLength |
No | - | * |
ExcessiveParameterList |
No | - | * |
ExcessivePublicCount |
No | - | * |
TooManyFields |
No | - | * |
TooManyMethods |
No | ignorepattern covers same functionality | |
TooManyPublicMethods |
No | ignorepattern covers same functionality | |
ExcessiveClassComplexity |
No | - | * |
Superglobals |
No | Possibly same as with static access? | ** |
CamelCaseClassName |
No | - | * |
CamelCasePropertyName |
No | List of identifiers to ignore | ** |
CamelCaseMethodName |
No | List of identifiers to ignore | ** |
CamelCaseParameterName |
No | List of identifiers to ignore | ** |
CamelCaseVariableName |
No | List of identifiers to ignore | ** |
ExitExpression |
No | - | * |
EvalExpression |
No | - | * |
GotoStatement |
No | - | * |
NumberOfChildren |
No | - | * |
DepthOfInheritance |
No | - | * |
CouplingBetweenObjects |
No | - | Should be coupling between classes, btw |
DevelopmentCodeFragment |
No | - | unwanted-functions covers equivalent functionality |
EmptyCatchBlock |
No | - | * |
ShortVariable |
Yes | List of variable names to ignore | |
LongVariable |
No | List of identifiers to ignore | ** |
ShortMethodName |
Yes | List of method names to ignore | |
ConstructorWithNameAsEnclosingClass |
No | - | * |
ConstantNamingConventions |
No | List of identifiers to ignore | (very edge-case with this one though)** |
BooleanGetMethodName |
No | List of identifiers to ignore | (but so edgy perhaps not worth a config rule?)** |
UnusedPrivateField |
No | - | * |
UnusedLocalVariable |
No | - | * |
UnusedPrivateMethod |
No | - | * |
UnusedFormalParameter |
No | List of identifiers to ignore | (EG: the use of _ in other languages to indicate an argument that won't be used in a callback's signature)** |
* = no sensible way of having an exception list ** = there might be a business case for breaking naming standards
Many thanks, @adamcameron !
So I'm cutting down your list to the relevant ones.
At first all the rules that support some kind of exceptions or vice versa, grouped by how the exceptions work.
Rule Name | How |
---|---|
DevelopmentCodeFragment |
unwanted functions |
TooManyMethods |
ignore pattern |
TooManyPublicMethods |
ignore pattern |
ShortVariable |
List of variable names to ignore |
ShortMethodName |
List of method names to ignore |
StaticAccess |
List of classes to ignore |
I see three ways of exceptions:
Now to the list of rules, which could benefit from having some kind of exceptions.
Some exceptions would only make sense, if you could configure them in a case to case situation (read class/method/funcition). Just like envisioned by https://github.com/phpmd/phpmd/issues/30.
Grouped by how the exceptions work.
Rule Name | How |
---|---|
Superglobals |
Unwanted list (current list = new default) |
ExcessivePublicCount |
Case by case ignore list or pattern only |
TooManyFields |
Case by case ignore list or pattern only |
UnusedLocalVariable |
Case by case ignore list only |
CamelCasePropertyName |
Ignore list or pattern |
CamelCaseMethodName |
Ignore list or pattern |
CamelCaseParameterName |
Ignore list or pattern |
CamelCaseVariableName |
Ignore list or pattern |
LongVariable |
Ignore list |
ConstantNamingConventions |
Ignore list |
BooleanGetMethodName |
Ignore list |
UnusedFormalParameter |
Ignore list |
But I'm not really convinced whether all of them are really a good idea. I'd love to hear @manuelpichler's opinion about it.
Some rules don't support exceptions. A one-off fix for
UnusedLocalVariable
is awaiting merging (https://github.com/phpmd/phpmd/pull/329), but I think rather than dealing on a case-by-case basis, the facility ought to be applied to all rules.A case in point is that we need to whitelist
$_
as anUnusedLocalVariable
too, for the reasons cited in the original (closed) issue (https://github.com/phpmd/phpmd/issues/326), but$_
also trips theCamelCaseParameterName
rule too, and that doesn't allow exceptions either. This means we need to clutter our code with@SuppressWarnings
annotations, which kinda runs counter to the intent of phpmd in the first place.I hasten to add I think this is a great tool, and it's really helped our code quality. And this is just a minor irk :-)
Cheers!