Skip to content

Conversation

@scrouthtv
Copy link

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 v8 sample fails this check, as it defines a namespace v8, which is not allowed. Subsequently, I also changed that test definition.

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.
Copy link
Member

@aaronliu0130 aaronliu0130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to contribute!

Comment on lines +5496 to +5499
'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.')
Copy link
Member

@aaronliu0130 aaronliu0130 Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'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.

Comment on lines +4584 to +4602
'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]')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +5491 to +5494
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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]

@aaronliu0130
Copy link
Member

Stale. Feel free to submit again after making the changes mentioned!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants