2828# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2929# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
31- # https://github.com/cpplint/cpplint/blob/6b1d29874dc5d7c3c9201b70e760b3eb9468a60d /cpplint.py
31+ # https://github.com/cpplint/cpplint/blob/1.6.1 /cpplint.py
3232
3333"""Does google-lint on c++ files.
3434
4343same line, but it is far from perfect (in either direction).
4444"""
4545
46+ # cpplint predates fstrings
47+ # pylint: disable=consider-using-f-string
48+
49+ # pylint: disable=invalid-name
50+
4651import codecs
4752import copy
4853import getopt
6166# if empty, use defaults
6267_valid_extensions = set ([])
6368
64- __VERSION__ = '1.5.5 '
69+ __VERSION__ = '1.6.1 '
6570
6671try :
72+ # -- pylint: disable=used-before-assignment
6773 xrange # Python 2
6874except NameError :
6975 # -- pylint: disable=redefined-builtin
7076 xrange = range # Python 3
7177
78+
7279_USAGE = """
7380Syntax: cpplint.py [--verbose=#] [--output=emacs|eclipse|vs7|junit|sed|gsed]
7481 [--filter=-x,+y,...]
879886_include_order = "default"
880887
881888try :
889+ # -- pylint: disable=used-before-assignment
882890 unicode
883891except NameError :
884892 # -- pylint: disable=redefined-builtin
885893 basestring = unicode = str
886894
887895try :
896+ # -- pylint: disable=used-before-assignment
888897 long
889898except NameError :
890899 # -- pylint: disable=redefined-builtin
@@ -1620,7 +1629,6 @@ def RepositoryName(self):
16201629 os .path .exists (os .path .join (current_dir , ".hg" )) or
16211630 os .path .exists (os .path .join (current_dir , ".svn" ))):
16221631 root_dir = current_dir
1623- break
16241632 current_dir = os .path .dirname (current_dir )
16251633
16261634 if (os .path .exists (os .path .join (root_dir , ".git" )) or
@@ -1926,6 +1934,7 @@ def __init__(self, lines):
19261934 self .raw_lines = lines
19271935 self .num_lines = len (lines )
19281936 self .lines_without_raw_strings = CleanseRawStrings (lines )
1937+ # # pylint: disable=consider-using-enumerate
19291938 for linenum in range (len (self .lines_without_raw_strings )):
19301939 self .lines .append (CleanseComments (
19311940 self .lines_without_raw_strings [linenum ]))
@@ -2854,7 +2863,7 @@ def CheckEnd(self, filename, clean_lines, linenum, error):
28542863 # deciding what these nontrivial things are, so this check is
28552864 # triggered by namespace size only, which works most of the time.
28562865 if (linenum - self .starting_linenum < 10
2857- and not Match (r'^\s*};*\s*(//).*\bnamespace\b' , line )):
2866+ and not Match (r'^\s*};*\s*(//|/\* ).*\bnamespace\b' , line )):
28582867 return
28592868
28602869 # Look for matching comment at end of namespace.
@@ -2871,7 +2880,7 @@ def CheckEnd(self, filename, clean_lines, linenum, error):
28712880 # expected namespace.
28722881 if self .name :
28732882 # Named namespace
2874- if not Match ((r'^\s*};*\s*(//).*\bnamespace\s+' +
2883+ if not Match ((r'^\s*};*\s*(//|/\* ).*\bnamespace\s+' +
28752884 re .escape (self .name ) + r'[\*/\.\\\s]*$' ),
28762885 line ):
28772886 error (filename , linenum , 'readability/namespace' , 5 ,
@@ -5080,10 +5089,12 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
50805089 #
50815090 # We also make an exception for Lua headers, which follow google
50825091 # naming convention but not the include convention.
5083- match = Match (r'#include\s*"([^/]+\.h)"' , line )
5084- if match and not _THIRD_PARTY_HEADERS_PATTERN .match (match .group (1 )):
5085- error (filename , linenum , 'build/include_subdir' , 4 ,
5086- 'Include the directory when naming .h files' )
5092+ match = Match (r'#include\s*"([^/]+\.(.*))"' , line )
5093+ if match :
5094+ if (IsHeaderExtension (match .group (2 )) and
5095+ not _THIRD_PARTY_HEADERS_PATTERN .match (match .group (1 ))):
5096+ error (filename , linenum , 'build/include_subdir' , 4 ,
5097+ 'Include the directory when naming header files' )
50875098
50885099 # we shouldn't include a file more than once. actually, there are a
50895100 # handful of instances where doing so is okay, but in general it's
@@ -5332,28 +5343,12 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
53325343 'Did you mean "memset(%s, 0, %s)"?'
53335344 % (match .group (1 ), match .group (2 )))
53345345
5335- # Check for 'using namespace' which pollutes namespaces.
5336- # This is tricky. Although in general 'using namespace' is a Bad Thing,
5337- # an exception is made for certain standard namespaces, like std::*literals
5338- # and std::placeholders, which are intended to be used in this fashion.
5339- # This whitelist may grow over time as needed if/when shiny new libraries
5340- # come along that are well-behaved in a 'using namespace' context.
5341- # For example, 'using namespace std::chrono_literals;' is allowed, but
5342- # 'using namespace foo;' is not allowed.
5343- # Note that headers are not permitted to use this exception.
5344- match = Search (r'\busing namespace\s+((\w|::)+)' , line )
5345- if match :
5346- whitelist = [
5347- 'std::chrono_literals' ,
5348- 'std::complex_literals' ,
5349- 'std::literals' ,
5350- 'std::literals::chrono_literals' ,
5351- 'std::literals::complex_literals' ,
5352- 'std::literals::string_literals' ,
5353- 'std::placeholders' ,
5354- 'std::string_literals' ,
5355- ]
5356- if IsHeaderExtension (file_extension ) or match .group (1 ) not in whitelist :
5346+ if Search (r'\busing namespace\b' , line ):
5347+ if Search (r'\bliterals\b' , line ):
5348+ error (filename , linenum , 'build/namespaces_literals' , 5 ,
5349+ 'Do not use namespace using-directives. '
5350+ 'Use using-declarations instead.' )
5351+ else :
53575352 error (filename , linenum , 'build/namespaces' , 5 ,
53585353 'Do not use namespace using-directives. '
53595354 'Use using-declarations instead.' )
@@ -5872,7 +5867,8 @@ def CheckCStyleCast(filename, clean_lines, linenum, cast_type, pattern, error):
58725867 return False
58735868
58745869 # operator++(int) and operator--(int)
5875- if context .endswith (' operator++' ) or context .endswith (' operator--' ):
5870+ if (context .endswith (' operator++' ) or context .endswith (' operator--' ) or
5871+ context .endswith ('::operator++' ) or context .endswith ('::operator--' )):
58765872 return False
58775873
58785874 # A single unnamed argument for a function tends to look like old style cast.
@@ -5882,10 +5878,6 @@ def CheckCStyleCast(filename, clean_lines, linenum, cast_type, pattern, error):
58825878 remainder ):
58835879 return False
58845880
5885- # Don't warn in C files about C-style casts
5886- if os .path .splitext (filename )[1 ] in ['.c' , '.h' ]:
5887- return False
5888-
58895881 # At this point, all that should be left is actual casts.
58905882 error (filename , linenum , 'readability/casting' , 4 ,
58915883 'Using C-style cast. Use %s<%s>(...) instead' %
@@ -6555,7 +6547,7 @@ def ProcessConfigOverrides(filename):
65556547 continue
65566548
65576549 try :
6558- with open (cfg_file ) as file_handle :
6550+ with codecs . open (cfg_file , 'r' , 'utf8' , 'replace' ) as file_handle :
65596551 for line in file_handle :
65606552 line , _ , _ = line .partition ('#' ) # Remove comments.
65616553 if not line .strip ():
@@ -6930,4 +6922,4 @@ def main():
69306922
69316923
69326924if __name__ == '__main__' :
6933- main ()
6925+ main ()
0 commit comments