Add build/namespaces_names error#286
Conversation
This error category checks whether all namespace names are written in lowercase, with words separated by underscores, as is recommended by the google style guide: https://google.github.io/styleguide/cppguide.html#Namespace_Names This is accomplished by checking every line against a regular expression to find namespace declarations first, and afterwards check the name of that namespace.
This checks some basic good and bad examples for the namespace names convention as established by the google style guide.
The v8 sample defines a namespace `v8`, which is not allowed according to the google style guide.
aaronliu0130
left a comment
There was a problem hiding this comment.
Thanks for taking the time to contribute!
| 'Namespace names must be all lower-case, with words separated ' | ||
| 'by underscores. See ' | ||
| 'https://google.github.io/styleguide/cppguide.html#Namespace_Names' | ||
| ' for more information.') |
There was a problem hiding this comment.
| 'Namespace names must be all lower-case, with words separated ' | |
| 'by underscores. See ' | |
| 'https://google.github.io/styleguide/cppguide.html#Namespace_Names' | |
| ' for more information.') | |
| 'Namespace names must be all lower-case with words separated ' | |
| 'by underscores.') |
We never link to the style guide if it's pretty obvious, and there's a comma splice here.
| 'foo.' + extension, 'namespace CamelCase {}', | ||
| 'Namespace names must be all lower-case, with words separated by underscores. ' | ||
| 'See https://google.github.io/styleguide/cppguide.html#Namespace_Names ' | ||
| 'for more information. [build/namespaces_names] [4]') | ||
| self.TestLanguageRulesCheck( | ||
| 'foo.' + extension, 'inline namespace Uppercase {', | ||
| 'Namespace names must be all lower-case, with words separated by underscores. ' | ||
| 'See https://google.github.io/styleguide/cppguide.html#Namespace_Names ' | ||
| 'for more information. [build/namespaces_names] [4]') | ||
| self.TestLanguageRulesCheck( | ||
| 'foo.' + extension, 'namespace Uppercase = std', | ||
| 'Namespace names must be all lower-case, with words separated by underscores. ' | ||
| 'See https://google.github.io/styleguide/cppguide.html#Namespace_Names ' | ||
| 'for more information. [build/namespaces_names] [4]') | ||
| self.TestLanguageRulesCheck( | ||
| 'foo.' + extension, 'namespace a::inline b::inline C {', | ||
| 'Namespace names must be all lower-case, with words separated by underscores. ' | ||
| 'See https://google.github.io/styleguide/cppguide.html#Namespace_Names ' | ||
| 'for more information. [build/namespaces_names] [4]') |
There was a problem hiding this comment.
| 'foo.' + extension, 'namespace CamelCase {}', | |
| 'Namespace names must be all lower-case, with words separated by underscores. ' | |
| 'See https://google.github.io/styleguide/cppguide.html#Namespace_Names ' | |
| 'for more information. [build/namespaces_names] [4]') | |
| self.TestLanguageRulesCheck( | |
| 'foo.' + extension, 'inline namespace Uppercase {', | |
| 'Namespace names must be all lower-case, with words separated by underscores. ' | |
| 'See https://google.github.io/styleguide/cppguide.html#Namespace_Names ' | |
| 'for more information. [build/namespaces_names] [4]') | |
| self.TestLanguageRulesCheck( | |
| 'foo.' + extension, 'namespace Uppercase = std', | |
| 'Namespace names must be all lower-case, with words separated by underscores. ' | |
| 'See https://google.github.io/styleguide/cppguide.html#Namespace_Names ' | |
| 'for more information. [build/namespaces_names] [4]') | |
| self.TestLanguageRulesCheck( | |
| 'foo.' + extension, 'namespace a::inline b::inline C {', | |
| 'Namespace names must be all lower-case, with words separated by underscores. ' | |
| 'See https://google.github.io/styleguide/cppguide.html#Namespace_Names ' | |
| 'for more information. [build/namespaces_names] [4]') | |
| 'foo.' + extension, 'namespace CamelCase {}', | |
| 'Namespace names must be all lower-case with words separated by underscores. ' | |
| '[naming/namespaces] [4]') | |
| self.TestLanguageRulesCheck( | |
| 'foo.' + extension, 'inline namespace Uppercase {', | |
| 'Namespace names must be all lower-case with words separated by underscores. ' | |
| '[naming/namespaces] [4]') | |
| self.TestLanguageRulesCheck( | |
| 'foo.' + extension, 'namespace Uppercase = std', | |
| 'Namespace names must be all lower-case with words separated by underscores. ' | |
| '[naming/namespaces] [4]') | |
| self.TestLanguageRulesCheck( | |
| 'foo.' + extension, 'namespace a::inline b::inline C {', | |
| 'Namespace names must be all lower-case with words separated by underscores. ' | |
| '[naming/namespaces] [4]') |
Ditto
| if match: | ||
| name = match.group(1) | ||
| if name != "" and not re.match(r'^((inline )?[a-z_]+(::)?)+$', name): | ||
| error(filename, linenum, 'build/namespaces_names', 4, |
There was a problem hiding this comment.
| error(filename, linenum, 'build/namespaces_names', 4, | |
| error(filename, linenum, 'naming/namespaces', 4, |
This is decidedly not a building issue. This entire check is also not suited for the language rules−checking function. (I recommend you move this to a new function, which should also solve the lint errors.
| match = re.match(r'.*namespace\s+([^{=;]+)\s+[{;=]', line) | ||
| if match: | ||
| name = match.group(1) | ||
| if name != "" and not re.match(r'^((inline )?[a-z_]+(::)?)+$', name): |
There was a problem hiding this comment.
It would be much better if the detection was based on nesting_state. The could changed by #235 should provide an example.
|
|
||
| src/interface-descriptors.h:5: #ifndef header guard has wrong style, please use: SAMPLES_V8_SAMPLE_SRC_INTERFACE_DESCRIPTORS_H_ [build/header_guard] [5] | ||
| src/interface-descriptors.h:1255: #endif line should be "#endif // SAMPLES_V8_SAMPLE_SRC_INTERFACE_DESCRIPTORS_H_" [build/header_guard] [5] | ||
| src/interface-descriptors.h:15: Namespace names must be all lower-case, with words separated by underscores. See https://google.github.io/styleguide/cppguide.html#Namespace_Names for more information. [build/namespaces_names] [4] |
There was a problem hiding this comment.
| src/interface-descriptors.h:15: Namespace names must be all lower-case, with words separated by underscores. See https://google.github.io/styleguide/cppguide.html#Namespace_Names for more information. [build/namespaces_names] [4] | |
| src/interface-descriptors.h:15: Namespace names must be all lower-case with words separated by underscores. [naming/namespaces] [4] |
|
Stale. Feel free to submit again after making the changes mentioned! |
This error category checks whether all namespace names are written in lowercase, with words separated by underscores, as is recommended by the google style guide:
https://google.github.io/styleguide/cppguide.html#Namespace_Names
This is accomplished by checking every line against a regular expression to find namespace declarations first, and afterwards check the name of that namespace.
The
v8sample fails this check, as it defines a namespacev8, which is not allowed. Subsequently, I also changed that test definition.