Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Differentiate namespace headers #93

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
'build/include_alpha',
'build/include_order',
'build/include_what_you_use',
'build/namespaces_headers',
'build/namespaces_literals',
'build/namespaces',
'build/printf_format',
Expand Down Expand Up @@ -5084,7 +5085,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
if (IsHeaderExtension(file_extension)
and Search(r'\bnamespace\s*{', line)
and line[-1] != '\\'):
error(filename, linenum, 'build/namespaces', 4,
error(filename, linenum, 'build/namespaces_headers', 4,
'Do not use unnamed namespaces in header files. See '
'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
' for more information.')
Expand Down
4 changes: 3 additions & 1 deletion cpplint_clitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class TemporaryFolderClassSetup(object):
lines at end).
"""

maxDiff = None

@classmethod
def setUpClass(cls):
"""setup tmp folder for testing with samples and custom additions by subclasses"""
Expand Down Expand Up @@ -160,7 +162,7 @@ def testSillySample(self):
self.checkAllInFolder('./samples/silly-sample', 2)

def testBoostSample(self):
self.checkAllInFolder('./samples/boost-sample', 2)
self.checkAllInFolder('./samples/boost-sample', 3)

def testProtobufSample(self):
self.checkAllInFolder('./samples/protobuf-sample', 1)
Expand Down
2 changes: 1 addition & 1 deletion cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4255,7 +4255,7 @@ def doTestUnnamedNamespacesInHeaders(self, extension):
'foo.' + extension, 'namespace {',
'Do not use unnamed namespaces in header files. See'
' https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
' for more information. [build/namespaces] [4]')
' for more information. [build/namespaces_headers] [4]')
# namespace registration macros are OK.
self.TestLanguageRulesCheck('foo.' + extension, 'namespace { \\', '')
# named namespaces are OK.
Expand Down
47 changes: 47 additions & 0 deletions samples/boost-sample/headers_inspect.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
src/inspect/*
1
3
Done processing src/inspect/unnamed_namespace_check.hpp
Total errors found: 40

src/inspect/unnamed_namespace_check.hpp:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_BOOST_SAMPLE_SRC_INSPECT_UNNAMED_NAMESPACE_CHECK_HPP_ [build/header_guard] [5]
src/inspect/unnamed_namespace_check.hpp:14: Do not use unnamed namespaces in header files. See https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces for more information. [build/namespaces_headers] [4]
src/inspect/unnamed_namespace_check.hpp:18: At least two spaces is best between code and comments [whitespace/comments] [2]
src/inspect/unnamed_namespace_check.hpp:19: Closing ) should be moved to the previous line [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:21: Anonymous namespace should be terminated with "// namespace" [readability/namespace] [5]
src/inspect/unnamed_namespace_check.hpp:21: At least two spaces is best between code and comments [whitespace/comments] [2]
src/inspect/unnamed_namespace_check.hpp:26: { should almost always be at the end of the previous line [whitespace/braces] [4]
src/inspect/unnamed_namespace_check.hpp:27: Do not indent within a namespace [runtime/indentation_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:28: { should almost always be at the end of the previous line [whitespace/braces] [4]
src/inspect/unnamed_namespace_check.hpp:29: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
src/inspect/unnamed_namespace_check.hpp:30: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
src/inspect/unnamed_namespace_check.hpp:30: { should almost always be at the end of the previous line [whitespace/braces] [4]
src/inspect/unnamed_namespace_check.hpp:31: Extra space after ( in function call [whitespace/parens] [4]
src/inspect/unnamed_namespace_check.hpp:31: Extra space before ) [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:32: At least two spaces is best between code and comments [whitespace/comments] [2]
src/inspect/unnamed_namespace_check.hpp:32: Extra space after ( in function call [whitespace/parens] [4]
src/inspect/unnamed_namespace_check.hpp:32: Extra space before ) [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:33: Extra space after ( in function call [whitespace/parens] [4]
src/inspect/unnamed_namespace_check.hpp:33: Extra space before ) [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:34: At least two spaces is best between code and comments [whitespace/comments] [2]
src/inspect/unnamed_namespace_check.hpp:34: Extra space after ( in function call [whitespace/parens] [4]
src/inspect/unnamed_namespace_check.hpp:34: Extra space before ) [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:35: Extra space after ( in function call [whitespace/parens] [4]
src/inspect/unnamed_namespace_check.hpp:35: Extra space before ) [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:36: Extra space after ( in function call [whitespace/parens] [4]
src/inspect/unnamed_namespace_check.hpp:36: Extra space before ) [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:37: Extra space after ( in function call [whitespace/parens] [4]
src/inspect/unnamed_namespace_check.hpp:37: Extra space before ) [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:38: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
src/inspect/unnamed_namespace_check.hpp:40: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
src/inspect/unnamed_namespace_check.hpp:44: { should almost always be at the end of the previous line [whitespace/braces] [4]
src/inspect/unnamed_namespace_check.hpp:48: Lines should be <= 80 characters long [whitespace/line_length] [2]
src/inspect/unnamed_namespace_check.hpp:49: Missing space before ( in for( [whitespace/parens] [5]
src/inspect/unnamed_namespace_check.hpp:50: { should almost always be at the end of the previous line [whitespace/braces] [4]
src/inspect/unnamed_namespace_check.hpp:54: Extra space after ( in function call [whitespace/parens] [4]
src/inspect/unnamed_namespace_check.hpp:54: Extra space before ) [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:57: Redundant blank line at the end of a code block should be deleted. [whitespace/blank_line] [3]
src/inspect/unnamed_namespace_check.hpp:59: At least two spaces is best between code and comments [whitespace/comments] [2]
src/inspect/unnamed_namespace_check.hpp:60: At least two spaces is best between code and comments [whitespace/comments] [2]
src/inspect/unnamed_namespace_check.hpp:51: Add #include <string> for string [build/include_what_you_use] [4]

62 changes: 62 additions & 0 deletions samples/boost-sample/src/inspect/unnamed_namespace_check.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// unnamed_namespace_check -----------------------------------------//

// Copyright Gennaro Prota 2006.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include "boost/regex.hpp"
#include "boost/lexical_cast.hpp"
#include "unnamed_namespace_check.hpp"


namespace {


boost::regex unnamed_namespace_regex(
"\\<namespace\\s*(\\?\\?<|\\{)" // trigraph ??< or {
);

} // unnamed namespace (ironical? :-)



namespace boost
{
namespace inspect
{
unnamed_namespace_check::unnamed_namespace_check() : m_errors(0)
{
register_signature( ".h" );
register_signature( ".hh" ); // just in case
register_signature( ".hpp" );
register_signature( ".hxx" ); // just in case
register_signature( ".inc" );
register_signature( ".ipp" );
register_signature( ".inl" );
}

void unnamed_namespace_check::inspect(
const string & library_name,
const path & full_path, // example: c:/foo/boost/filesystem/path.hpp
const string & contents ) // contents of file to be inspected
{
if (contents.find( "boostinspect:" "nounnamed" ) != string::npos) return;


boost::sregex_iterator cur(contents.begin(), contents.end(), unnamed_namespace_regex), end;
for( ; cur != end; ++cur, ++m_errors )
{
const string::size_type
ln = std::count( contents.begin(), (*cur)[0].first, '\n' ) + 1;

error( library_name, full_path, "Unnamed namespace", ln );
}


}
} // namespace inspect
} // namespace boost