-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MethodName check fails on constructor of nested class #1557
Comments
Hello @rasmusbonnedal and thank you for reaching out. Do you use some custom regexp to ensure the naming convention? If not: there is probably no relation to the nesting. As you see... public class MethodNameCheck extends SquidCheck<Grammar> {
private static final String DEFAULT = "^[A-Z][A-Za-z0-9]{2,30}$"; ... the underscore is considered to be an undesirable part of methods' names by default (see CamelCase). In case you would like to accept it, please navigate to the rule Regards, |
Hi @ivangalkin, thanks for your quick response! We do have a custom regexp but I still think this is a general issue and indeed related to nesting. In class Outer_Class {
Outer_Class();
class Inner_Class {
Inner_Class();
};
};
Outer_Class::Outer_Class() // This does not give an error
{
}
OuterClass::Inner_Class::Inner_Class() // This gives an error
{
} I think this discrepancy between outer and inner class constructors in MethodName check is not expected. |
Hi @rasmusbonnedal, I double-checked the code.
In any way I confirm the bug. We have to modify the constructor/destructor detection. Thank you |
@ivangalkin: Awesome, thanks! |
* Modify the grammar. Specify the nestedNameSpecifier in terms of `className`s * the naming check is based on extraction of `className`s * grammar of `className` is equivalent to `typeName` and covers both `simpleTemplateId` and `IDENTIFIER` ```JAVA b.rule(typeName).is( b.firstOf( className, // == b.firstOf( simpleTemplateId, IDENTIFIER ) enumName, // == IDENTIFIER typedefName, // == IDENTIFIER simpleTemplateId // ) ); ``` * Modify MethodNameCheck: the scope of the method/ctor/dtor is always represented by the most significant child of type `className` ``` functionDefinition == [namespaces...]::className0::className1::className2::ID ^^^^^^^^^^ ``` closes SonarOpenCommunity#1557
Description
MethodName check misidentifies the constructor of a nested class as a method
Steps to reproduce the problem
Add this to
cxx-checks/src/test/resources/checks/MethodName.cc
and runmvn test
Expected behavior
That
Inner_Class
constructor would not fail MethodName check.Actual behavior
Inner_Class
constructor fails MethodName check.Known workarounds
Please provide a description of any known workarounds.
LOG file
Output from
mvn test
Related information
The text was updated successfully, but these errors were encountered: