Issue #15985: Expand Default Value of constantWaiverParentToken in MagicNumberCheck with All Operators#15957
Conversation
|
Github, generate report for MagicNumber/Example1 |
|
Failed to download or process the specified configuration(s).
|
|
Github, generate report for MagicNumber/Example1 |
|
@mahfouz72, please try to trigger report one more time, not clear why your execution failed. |
|
Github, generate report for MagicNumber/Example1 |
I am not sure that removal of this violation is good. but in the same time if there would be kind of magic number, but it is field, so should be ignored if it will be kind of impossible to persuade users to put all this numbers in separate variables/constants, as 5 in one expression and in another expression can means different. And naming all digits is too much. |
This is ignored because the field is constant, the same as we ignore I agree with extending the allow list to make the check less strict. Users can still customize the list if needed. please let me know your final decision. |
romani
left a comment
There was a problem hiding this comment.
Do you know what other operators are not this waiver?
I just try to formulate some reasons of this property and tokens presence in it.
To make it clear what is default and what users should do themselves.
Items:
| ignoreAnnotation = (default)false | ||
| ignoreFieldDeclaration = true | ||
| ignoreAnnotationElementDefaults = (default)true | ||
| constantWaiverParentToken = (default)TYPECAST, METHOD_CALL, EXPR, ARRAY_INIT, UNARY_MINUS, \ |
There was a problem hiding this comment.
We changed default, but we didn't change all other Inputs with "(default)".
Please do.
I am not sure in what issue we will do validation of default, I will investigate later on.
There was a problem hiding this comment.
@mahfouz72 , please update other Inputs with default on this property to have such tokens.
There was a problem hiding this comment.
This will be a huge update we have many inputs for this check :)
There was a problem hiding this comment.
We need it, I hope it is just copy paste
There was a problem hiding this comment.
Done. It was painful because I had to change row numbers in every unit test
There was a problem hiding this comment.
Hm, we always keep 2 empty lines in config comment to avoid line shift.
There was a problem hiding this comment.
The addition is 2 lines, and I can't remove the 2 empty lines in the config comment because there will be no empty lines at all and we have a test for this.
It will be good if we had 3 empty lines not 2
There was a problem hiding this comment.
Ok, next time try to reuse empty line in header comment, if post.
|
Can we suggest user in issue a workaround by setting of this property with required tokens? |
There are a bunch of other operators that are not on the list such as mod operation, comparison operators, and conditional operators Example:
I still can't formulate reasons why we add some operators and not others. I don't think of any use case when we could violate magic numbers with one operator but not others. The thing here is consistency. If one operator triggers a magic number violation, why should others (like addition or subtraction) not? Can we say that some operators (like arithmetic ones) are more commonly used with numbers That is why we added them in default list but others are not commonly used so we leave the option for users to add them to the list. |
|
We can make any rule we think is reasonable. Let's drop few ideas/reasons and choose by vote what is more clear to active maintainers. I did big post at #15950 (comment) to investigate problem. |
moved to #15985 |
2cad2ad to
b5bd248
Compare
b5bd248 to
13bd2ce
Compare
|
@mahfouz72 , see #15957 (comment) |
13bd2ce to
344621a
Compare
…oken in MagicNumberCheck with All Operators
344621a to
5c2bb9c
Compare
closes #15985