| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 67ea8e2 commit 1f850c0
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,11 @@ | |||
| 41 | 41 | same line, but it is far from perfect (in either direction). | |
| 42 | 42 | """ | |
| 43 | 43 | ||
| 44 | + # cpplint predates fstrings | ||
| 45 | + # pylint: disable=consider-using-f-string | ||
| 46 | + | ||
| 47 | + # pylint: disable=invalid-name | ||
| 48 | + | ||
| 44 | 49 | import codecs | |
| 45 | 50 | import copy | |
| 46 | 51 | import getopt | |
@@ -59,7 +64,7 @@ | |||
| 59 | 64 | # if empty, use defaults | |
| 60 | 65 | _valid_extensions = set([]) | |
| 61 | 66 | ||
| 62 | - __VERSION__ = '1.5.5' | ||
| 67 | + __VERSION__ = '1.6.0' | ||
| 63 | 68 | ||
| 64 | 69 | try: | |
| 65 | 70 | xrange # Python 2 | |
@@ -295,7 +300,6 @@ | |||
| 295 | 300 | 'build/include', | |
| 296 | 301 | 'build/include_subdir', | |
| 297 | 302 | 'build/include_alpha', | |
| 298 | - 'build/include_inline', | ||
| 299 | 303 | 'build/include_order', | |
| 300 | 304 | 'build/include_what_you_use', | |
| 301 | 305 | 'build/namespaces_headers', | |
@@ -311,13 +315,11 @@ | |||
| 311 | 315 | 'readability/constructors', | |
| 312 | 316 | 'readability/fn_size', | |
| 313 | 317 | 'readability/inheritance', | |
| 314 | - 'readability/pointer_notation', | ||
| 315 | 318 | 'readability/multiline_comment', | |
| 316 | 319 | 'readability/multiline_string', | |
| 317 | 320 | 'readability/namespace', | |
| 318 | 321 | 'readability/nolint', | |
| 319 | 322 | 'readability/nul', | |
| 320 | - 'readability/null_usage', | ||
| 321 | 323 | 'readability/strings', | |
| 322 | 324 | 'readability/todo', | |
| 323 | 325 | 'readability/utf8', | |
@@ -337,7 +339,6 @@ | |||
| 337 | 339 | 'runtime/string', | |
| 338 | 340 | 'runtime/threadsafe_fn', | |
| 339 | 341 | 'runtime/vlog', | |
| 340 | - 'runtime/v8_persistent', | ||
| 341 | 342 | 'whitespace/blank_line', | |
| 342 | 343 | 'whitespace/braces', | |
| 343 | 344 | 'whitespace/comma', | |
@@ -846,14 +847,6 @@ | |||
| 846 | 847 | 'Missing space after ,': r's/,\([^ ]\)/, \1/g', | |
| 847 | 848 | } | |
| 848 | 849 | ||
| 849 | - _NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b') | ||
| 850 | - | ||
| 851 | - _V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b') | ||
| 852 | - | ||
| 853 | - _RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]' | ||
| 854 | - r'(?<!(sizeof|return))' | ||
| 855 | - r'\s\*[a-zA-Z_][0-9a-zA-Z_]*') | ||
| 856 | - | ||
| 857 | 850 | _regexp_compile_cache = {} | |
| 858 | 851 | ||
| 859 | 852 | # {str, set(int)}: a map from error categories to sets of linenumbers | |
@@ -1094,11 +1087,10 @@ class _IncludeState(object): | |||
| 1094 | 1087 | # needs to move backwards, CheckNextIncludeOrder will raise an error. | |
| 1095 | 1088 | _INITIAL_SECTION = 0 | |
| 1096 | 1089 | _MY_H_SECTION = 1 | |
| 1097 | - _OTHER_H_SECTION = 2 | ||
| 1098 | - _OTHER_SYS_SECTION = 3 | ||
| 1099 | - _C_SECTION = 4 | ||
| 1100 | - _CPP_SECTION = 5 | ||
| 1101 | - | ||
| 1090 | + _C_SECTION = 2 | ||
| 1091 | + _CPP_SECTION = 3 | ||
| 1092 | + _OTHER_SYS_SECTION = 4 | ||
| 1093 | + _OTHER_H_SECTION = 5 | ||
| 1102 | 1094 | ||
| 1103 | 1095 | _TYPE_NAMES = { | |
| 1104 | 1096 | _C_SYS_HEADER: 'C system header', | |
@@ -1928,6 +1920,7 @@ def __init__(self, lines): | |||
| 1928 | 1920 | self.raw_lines = lines | |
| 1929 | 1921 | self.num_lines = len(lines) | |
| 1930 | 1922 | self.lines_without_raw_strings = CleanseRawStrings(lines) | |
| 1923 | + # # pylint: disable=consider-using-enumerate | ||
| 1931 | 1924 | for linenum in range(len(self.lines_without_raw_strings)): | |
| 1932 | 1925 | self.lines.append(CleanseComments( | |
| 1933 | 1926 | self.lines_without_raw_strings[linenum])) | |
@@ -2534,21 +2527,6 @@ def CheckForBadCharacters(filename, lines, error): | |||
| 2534 | 2527 | error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.') | |
| 2535 | 2528 | ||
| 2536 | 2529 | ||
| 2537 | - def CheckInlineHeader(filename, include_state, error): | ||
| 2538 | - """Logs an error if both a header and its inline variant are included.""" | ||
| 2539 | - | ||
| 2540 | - all_headers = dict(item for sublist in include_state.include_list | ||
| 2541 | - for item in sublist) | ||
| 2542 | - bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys() | ||
| 2543 | - if name.endswith('-inl.h')) | ||
| 2544 | - bad_headers &= set(all_headers.keys()) | ||
| 2545 | - | ||
| 2546 | - for name in bad_headers: | ||
| 2547 | - err = '%s includes both %s and %s-inl.h' % (filename, name, name) | ||
| 2548 | - linenum = all_headers[name] | ||
| 2549 | - error(filename, linenum, 'build/include_inline', 5, err) | ||
| 2550 | - | ||
| 2551 | - | ||
| 2552 | 2530 | def CheckForNewlineAtEOF(filename, lines, error): | |
| 2553 | 2531 | """Logs an error if there is no newline char at the end of the file. | |
| 2554 | 2532 | ||
@@ -3572,7 +3550,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum, | |||
| 3572 | 3550 | """Reports for long function bodies. | |
| 3573 | 3551 | ||
| 3574 | 3552 | For an overview why this is done, see: | |
| 3575 | - https://google.github.io/styleguide/cppguide.html#Write_Short_Functions | ||
| 3553 | + https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions | ||
| 3576 | 3554 | ||
| 3577 | 3555 | Uses a simplistic algorithm assuming other style guidelines | |
| 3578 | 3556 | (especially spacing) are followed. | |
@@ -4799,71 +4777,6 @@ def CheckAltTokens(filename, clean_lines, linenum, error): | |||
| 4799 | 4777 | 'Use operator %s instead of %s' % ( | |
| 4800 | 4778 | _ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1))) | |
| 4801 | 4779 | ||
| 4802 | - def CheckNullTokens(filename, clean_lines, linenum, error): | ||
| 4803 | - """Check NULL usage. | ||
| 4804 | - | ||
| 4805 | - Args: | ||
| 4806 | - filename: The name of the current file. | ||
| 4807 | - clean_lines: A CleansedLines instance containing the file. | ||
| 4808 | - linenum: The number of the line to check. | ||
| 4809 | - error: The function to call with any errors found. | ||
| 4810 | - """ | ||
| 4811 | - line = clean_lines.elided[linenum] | ||
| 4812 | - | ||
| 4813 | - # Avoid preprocessor lines | ||
| 4814 | - if Match(r'^\s*#', line): | ||
| 4815 | - return | ||
| 4816 | - | ||
| 4817 | - if line.find('/*') >= 0 or line.find('*/') >= 0: | ||
| 4818 | - return | ||
| 4819 | - | ||
| 4820 | - for match in _NULL_TOKEN_PATTERN.finditer(line): | ||
| 4821 | - error(filename, linenum, 'readability/null_usage', 2, | ||
| 4822 | - 'Use nullptr instead of NULL') | ||
| 4823 | - | ||
| 4824 | - def CheckV8PersistentTokens(filename, clean_lines, linenum, error): | ||
| 4825 | - """Check v8::Persistent usage. | ||
| 4826 | - | ||
| 4827 | - Args: | ||
| 4828 | - filename: The name of the current file. | ||
| 4829 | - clean_lines: A CleansedLines instance containing the file. | ||
| 4830 | - linenum: The number of the line to check. | ||
| 4831 | - error: The function to call with any errors found. | ||
| 4832 | - """ | ||
| 4833 | - line = clean_lines.elided[linenum] | ||
| 4834 | - | ||
| 4835 | - # Avoid preprocessor lines | ||
| 4836 | - if Match(r'^\s*#', line): | ||
| 4837 | - return | ||
| 4838 | - | ||
| 4839 | - if line.find('/*') >= 0 or line.find('*/') >= 0: | ||
| 4840 | - return | ||
| 4841 | - | ||
| 4842 | - for match in _V8_PERSISTENT_PATTERN.finditer(line): | ||
| 4843 | - error(filename, linenum, 'runtime/v8_persistent', 2, | ||
| 4844 | - 'Use v8::Global instead of v8::Persistent') | ||
| 4845 | - | ||
| 4846 | - def CheckLeftLeaningPointer(filename, clean_lines, linenum, error): | ||
| 4847 | - """Check for left-leaning pointer placement. | ||
| 4848 | - | ||
| 4849 | - Args: | ||
| 4850 | - filename: The name of the current file. | ||
| 4851 | - clean_lines: A CleansedLines instance containing the file. | ||
| 4852 | - linenum: The number of the line to check. | ||
| 4853 | - error: The function to call with any errors found. | ||
| 4854 | - """ | ||
| 4855 | - line = clean_lines.elided[linenum] | ||
| 4856 | - | ||
| 4857 | - # Avoid preprocessor lines | ||
| 4858 | - if Match(r'^\s*#', line): | ||
| 4859 | - return | ||
| 4860 | - | ||
| 4861 | - if '/*' in line or '*/' in line: | ||
| 4862 | - return | ||
| 4863 | - | ||
| 4864 | - for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line): | ||
| 4865 | - error(filename, linenum, 'readability/pointer_notation', 2, | ||
| 4866 | - 'Use left leaning pointer instead of right leaning') | ||
| 4867 | 4780 | ||
| 4868 | 4781 | def GetLineWidth(line): | |
| 4869 | 4782 | """Determines the width of the line in column positions. | |
@@ -5018,9 +4931,6 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, | |||
| 5018 | 4931 | CheckSpacingForFunctionCall(filename, clean_lines, linenum, error) | |
| 5019 | 4932 | CheckCheck(filename, clean_lines, linenum, error) | |
| 5020 | 4933 | CheckAltTokens(filename, clean_lines, linenum, error) | |
| 5021 | - CheckNullTokens(filename, clean_lines, linenum, error) | ||
| 5022 | - CheckV8PersistentTokens(filename, clean_lines, linenum, error) | ||
| 5023 | - CheckLeftLeaningPointer(filename, clean_lines, linenum, error) | ||
| 5024 | 4934 | classinfo = nesting_state.InnermostClass() | |
| 5025 | 4935 | if classinfo: | |
| 5026 | 4936 | CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error) | |
@@ -5164,10 +5074,12 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error): | |||
| 5164 | 5074 | # | |
| 5165 | 5075 | # We also make an exception for Lua headers, which follow google | |
| 5166 | 5076 | # naming convention but not the include convention. | |
| 5167 | - match = Match(r'#include\s*"([^/]+\.h)"', line) | ||
| 5168 | - if match and not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(1)): | ||
| 5169 | - error(filename, linenum, 'build/include_subdir', 4, | ||
| 5170 | - 'Include the directory when naming .h files') | ||
| 5077 | + match = Match(r'#include\s*"([^/]+\.(.*))"', line) | ||
| 5078 | + if match: | ||
| 5079 | + if (IsHeaderExtension(match.group(2)) and | ||
| 5080 | + not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(1))): | ||
| 5081 | + error(filename, linenum, 'build/include_subdir', 4, | ||
| 5082 | + 'Include the directory when naming header files') | ||
| 5171 | 5083 | ||
| 5172 | 5084 | # we shouldn't include a file more than once. actually, there are a | |
| 5173 | 5085 | # handful of instances where doing so is okay, but in general it's | |
@@ -5206,10 +5118,11 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error): | |||
| 5206 | 5118 | include_state.include_list[-1].append((include, linenum)) | |
| 5207 | 5119 | ||
| 5208 | 5120 | # We want to ensure that headers appear in the right order: | |
| 5209 | - # 1) for foo.cc, foo.h | ||
| 5210 | - # 2) other project headers | ||
| 5211 | - # 3) c system files | ||
| 5212 | - # 4) cpp system files | ||
| 5121 | + # 1) for foo.cc, foo.h (preferred location) | ||
| 5122 | + # 2) c system files | ||
| 5123 | + # 3) cpp system files | ||
| 5124 | + # 4) for foo.cc, foo.h (deprecated location) | ||
| 5125 | + # 5) other google headers | ||
| 5213 | 5126 | # | |
| 5214 | 5127 | # We classify each include statement as one of those 5 types | |
| 5215 | 5128 | # using a number of techniques. The include_state object keeps | |
@@ -5472,7 +5385,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension, | |||
| 5472 | 5385 | and line[-1] != '\\'): | |
| 5473 | 5386 | error(filename, linenum, 'build/namespaces_headers', 4, | |
| 5474 | 5387 | 'Do not use unnamed namespaces in header files. See ' | |
| 5475 | - 'https://google.github.io/styleguide/cppguide.html#Namespaces' | ||
| 5388 | + 'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces' | ||
| 5476 | 5389 | ' for more information.') | |
| 5477 | 5390 | ||
| 5478 | 5391 | ||
@@ -6594,8 +6507,6 @@ def ProcessFileData(filename, file_extension, lines, error, | |||
| 6594 | 6507 | ||
| 6595 | 6508 | CheckForNewlineAtEOF(filename, lines, error) | |
| 6596 | 6509 | ||
| 6597 | - CheckInlineHeader(filename, include_state, error) | ||
| 6598 | - | ||
| 6599 | 6510 | def ProcessConfigOverrides(filename): | |
| 6600 | 6511 | """ Loads the configuration files and processes the config overrides. | |
| 6601 | 6512 | ||
@@ -6614,13 +6525,13 @@ def ProcessConfigOverrides(filename): | |||
| 6614 | 6525 | if not base_name: | |
| 6615 | 6526 | break # Reached the root directory. | |
| 6616 | 6527 | ||
| 6617 | - cfg_file = os.path.join(abs_path, ".cpplint") | ||
| 6528 | + cfg_file = os.path.join(abs_path, "CPPLINT.cfg") | ||
| 6618 | 6529 | abs_filename = abs_path | |
| 6619 | 6530 | if not os.path.isfile(cfg_file): | |
| 6620 | 6531 | continue | |
| 6621 | 6532 | ||
| 6622 | 6533 | try: | |
| 6623 | - with open(cfg_file) as file_handle: | ||
| 6534 | + with open(cfg_file, encoding='utf-8') as file_handle: | ||
| 6624 | 6535 | for line in file_handle: | |
| 6625 | 6536 | line, _, _ = line.partition('#') # Remove comments. | |
| 6626 | 6537 | if not line.strip(): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments