| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 193b18e commit 3351910
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -295,6 +295,7 @@ | |||
| 295 | 295 | 'build/include', | |
| 296 | 296 | 'build/include_subdir', | |
| 297 | 297 | 'build/include_alpha', | |
| 298 | + 'build/include_inline', | ||
| 298 | 299 | 'build/include_order', | |
| 299 | 300 | 'build/include_what_you_use', | |
| 300 | 301 | 'build/namespaces_headers', | |
@@ -310,11 +311,13 @@ | |||
| 310 | 311 | 'readability/constructors', | |
| 311 | 312 | 'readability/fn_size', | |
| 312 | 313 | 'readability/inheritance', | |
| 314 | + 'readability/pointer_notation', | ||
| 313 | 315 | 'readability/multiline_comment', | |
| 314 | 316 | 'readability/multiline_string', | |
| 315 | 317 | 'readability/namespace', | |
| 316 | 318 | 'readability/nolint', | |
| 317 | 319 | 'readability/nul', | |
| 320 | + 'readability/null_usage', | ||
| 318 | 321 | 'readability/strings', | |
| 319 | 322 | 'readability/todo', | |
| 320 | 323 | 'readability/utf8', | |
@@ -334,6 +337,7 @@ | |||
| 334 | 337 | 'runtime/string', | |
| 335 | 338 | 'runtime/threadsafe_fn', | |
| 336 | 339 | 'runtime/vlog', | |
| 340 | + 'runtime/v8_persistent', | ||
| 337 | 341 | 'whitespace/blank_line', | |
| 338 | 342 | 'whitespace/braces', | |
| 339 | 343 | 'whitespace/comma', | |
@@ -835,6 +839,14 @@ | |||
| 835 | 839 | 'Missing space after ,': r's/,\([^ ]\)/, \1/g', | |
| 836 | 840 | } | |
| 837 | 841 | ||
| 842 | + _NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b') | ||
| 843 | + | ||
| 844 | + _V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b') | ||
| 845 | + | ||
| 846 | + _RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]' | ||
| 847 | + r'(?<!(sizeof|return))' | ||
| 848 | + r'\s\*[a-zA-Z_][0-9a-zA-Z_]*') | ||
| 849 | + | ||
| 838 | 850 | _regexp_compile_cache = {} | |
| 839 | 851 | ||
| 840 | 852 | # {str, set(int)}: a map from error categories to sets of linenumbers | |
@@ -854,7 +866,7 @@ | |||
| 854 | 866 | # Files to exclude from linting. This is set by the --exclude flag. | |
| 855 | 867 | _excludes = None | |
| 856 | 868 | ||
| 857 | - # Whether to supress PrintInfo messages | ||
| 869 | + # Whether to suppress PrintInfo messages | ||
| 858 | 870 | _quiet = False | |
| 859 | 871 | ||
| 860 | 872 | # The allowed line length of files. | |
@@ -1075,10 +1087,11 @@ class _IncludeState(object): | |||
| 1075 | 1087 | # needs to move backwards, CheckNextIncludeOrder will raise an error. | |
| 1076 | 1088 | _INITIAL_SECTION = 0 | |
| 1077 | 1089 | _MY_H_SECTION = 1 | |
| 1078 | - _C_SECTION = 2 | ||
| 1079 | - _CPP_SECTION = 3 | ||
| 1080 | - _OTHER_SYS_SECTION = 4 | ||
| 1081 | - _OTHER_H_SECTION = 5 | ||
| 1090 | + _OTHER_H_SECTION = 2 | ||
| 1091 | + _OTHER_SYS_SECTION = 3 | ||
| 1092 | + _C_SECTION = 4 | ||
| 1093 | + _CPP_SECTION = 5 | ||
| 1094 | + | ||
| 1082 | 1095 | ||
| 1083 | 1096 | _TYPE_NAMES = { | |
| 1084 | 1097 | _C_SYS_HEADER: 'C system header', | |
@@ -2511,6 +2524,21 @@ def CheckForBadCharacters(filename, lines, error): | |||
| 2511 | 2524 | error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.') | |
| 2512 | 2525 | ||
| 2513 | 2526 | ||
| 2527 | + def CheckInlineHeader(filename, include_state, error): | ||
| 2528 | + """Logs an error if both a header and its inline variant are included.""" | ||
| 2529 | + | ||
| 2530 | + all_headers = dict(item for sublist in include_state.include_list | ||
| 2531 | + for item in sublist) | ||
| 2532 | + bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys() | ||
| 2533 | + if name.endswith('-inl.h')) | ||
| 2534 | + bad_headers &= set(all_headers.keys()) | ||
| 2535 | + | ||
| 2536 | + for name in bad_headers: | ||
| 2537 | + err = '%s includes both %s and %s-inl.h' % (filename, name, name) | ||
| 2538 | + linenum = all_headers[name] | ||
| 2539 | + error(filename, linenum, 'build/include_inline', 5, err) | ||
| 2540 | + | ||
| 2541 | + | ||
| 2514 | 2542 | def CheckForNewlineAtEOF(filename, lines, error): | |
| 2515 | 2543 | """Logs an error if there is no newline char at the end of the file. | |
| 2516 | 2544 | ||
@@ -3534,7 +3562,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum, | |||
| 3534 | 3562 | """Reports for long function bodies. | |
| 3535 | 3563 | ||
| 3536 | 3564 | For an overview why this is done, see: | |
| 3537 | - https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions | ||
| 3565 | + https://google.github.io/styleguide/cppguide.html#Write_Short_Functions | ||
| 3538 | 3566 | ||
| 3539 | 3567 | Uses a simplistic algorithm assuming other style guidelines | |
| 3540 | 3568 | (especially spacing) are followed. | |
@@ -4760,6 +4788,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error): | |||
| 4760 | 4788 | 'Use operator %s instead of %s' % ( | |
| 4761 | 4789 | _ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1))) | |
| 4762 | 4790 | ||
| 4791 | + def CheckNullTokens(filename, clean_lines, linenum, error): | ||
| 4792 | + """Check NULL usage. | ||
| 4793 | + | ||
| 4794 | + Args: | ||
| 4795 | + filename: The name of the current file. | ||
| 4796 | + clean_lines: A CleansedLines instance containing the file. | ||
| 4797 | + linenum: The number of the line to check. | ||
| 4798 | + error: The function to call with any errors found. | ||
| 4799 | + """ | ||
| 4800 | + line = clean_lines.elided[linenum] | ||
| 4801 | + | ||
| 4802 | + # Avoid preprocessor lines | ||
| 4803 | + if Match(r'^\s*#', line): | ||
| 4804 | + return | ||
| 4805 | + | ||
| 4806 | + if line.find('/*') >= 0 or line.find('*/') >= 0: | ||
| 4807 | + return | ||
| 4808 | + | ||
| 4809 | + for match in _NULL_TOKEN_PATTERN.finditer(line): | ||
| 4810 | + error(filename, linenum, 'readability/null_usage', 2, | ||
| 4811 | + 'Use nullptr instead of NULL') | ||
| 4812 | + | ||
| 4813 | + def CheckV8PersistentTokens(filename, clean_lines, linenum, error): | ||
| 4814 | + """Check v8::Persistent usage. | ||
| 4815 | + | ||
| 4816 | + Args: | ||
| 4817 | + filename: The name of the current file. | ||
| 4818 | + clean_lines: A CleansedLines instance containing the file. | ||
| 4819 | + linenum: The number of the line to check. | ||
| 4820 | + error: The function to call with any errors found. | ||
| 4821 | + """ | ||
| 4822 | + line = clean_lines.elided[linenum] | ||
| 4823 | + | ||
| 4824 | + # Avoid preprocessor lines | ||
| 4825 | + if Match(r'^\s*#', line): | ||
| 4826 | + return | ||
| 4827 | + | ||
| 4828 | + if line.find('/*') >= 0 or line.find('*/') >= 0: | ||
| 4829 | + return | ||
| 4830 | + | ||
| 4831 | + for match in _V8_PERSISTENT_PATTERN.finditer(line): | ||
| 4832 | + error(filename, linenum, 'runtime/v8_persistent', 2, | ||
| 4833 | + 'Use v8::Global instead of v8::Persistent') | ||
| 4834 | + | ||
| 4835 | + def CheckLeftLeaningPointer(filename, clean_lines, linenum, error): | ||
| 4836 | + """Check for left-leaning pointer placement. | ||
| 4837 | + | ||
| 4838 | + Args: | ||
| 4839 | + filename: The name of the current file. | ||
| 4840 | + clean_lines: A CleansedLines instance containing the file. | ||
| 4841 | + linenum: The number of the line to check. | ||
| 4842 | + error: The function to call with any errors found. | ||
| 4843 | + """ | ||
| 4844 | + line = clean_lines.elided[linenum] | ||
| 4845 | + | ||
| 4846 | + # Avoid preprocessor lines | ||
| 4847 | + if Match(r'^\s*#', line): | ||
| 4848 | + return | ||
| 4849 | + | ||
| 4850 | + if '/*' in line or '*/' in line: | ||
| 4851 | + return | ||
| 4852 | + | ||
| 4853 | + for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line): | ||
| 4854 | + error(filename, linenum, 'readability/pointer_notation', 2, | ||
| 4855 | + 'Use left leaning pointer instead of right leaning') | ||
| 4763 | 4856 | ||
| 4764 | 4857 | def GetLineWidth(line): | |
| 4765 | 4858 | """Determines the width of the line in column positions. | |
@@ -4914,6 +5007,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, | |||
| 4914 | 5007 | CheckSpacingForFunctionCall(filename, clean_lines, linenum, error) | |
| 4915 | 5008 | CheckCheck(filename, clean_lines, linenum, error) | |
| 4916 | 5009 | CheckAltTokens(filename, clean_lines, linenum, error) | |
| 5010 | + CheckNullTokens(filename, clean_lines, linenum, error) | ||
| 5011 | + CheckV8PersistentTokens(filename, clean_lines, linenum, error) | ||
| 5012 | + CheckLeftLeaningPointer(filename, clean_lines, linenum, error) | ||
| 4917 | 5013 | classinfo = nesting_state.InnermostClass() | |
| 4918 | 5014 | if classinfo: | |
| 4919 | 5015 | CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error) | |
@@ -5099,11 +5195,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error): | |||
| 5099 | 5195 | include_state.include_list[-1].append((include, linenum)) | |
| 5100 | 5196 | ||
| 5101 | 5197 | # We want to ensure that headers appear in the right order: | |
| 5102 | - # 1) for foo.cc, foo.h (preferred location) | ||
| 5103 | - # 2) c system files | ||
| 5104 | - # 3) cpp system files | ||
| 5105 | - # 4) for foo.cc, foo.h (deprecated location) | ||
| 5106 | - # 5) other google headers | ||
| 5198 | + # 1) for foo.cc, foo.h | ||
| 5199 | + # 2) other project headers | ||
| 5200 | + # 3) c system files | ||
| 5201 | + # 4) cpp system files | ||
| 5107 | 5202 | # | |
| 5108 | 5203 | # We classify each include statement as one of those 5 types | |
| 5109 | 5204 | # using a number of techniques. The include_state object keeps | |
@@ -5366,7 +5461,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension, | |||
| 5366 | 5461 | and line[-1] != '\\'): | |
| 5367 | 5462 | error(filename, linenum, 'build/namespaces_headers', 4, | |
| 5368 | 5463 | 'Do not use unnamed namespaces in header files. See ' | |
| 5369 | - 'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces' | ||
| 5464 | + 'https://google.github.io/styleguide/cppguide.html#Namespaces' | ||
| 5370 | 5465 | ' for more information.') | |
| 5371 | 5466 | ||
| 5372 | 5467 | ||
@@ -6488,6 +6583,8 @@ def ProcessFileData(filename, file_extension, lines, error, | |||
| 6488 | 6583 | ||
| 6489 | 6584 | CheckForNewlineAtEOF(filename, lines, error) | |
| 6490 | 6585 | ||
| 6586 | + CheckInlineHeader(filename, include_state, error) | ||
| 6587 | + | ||
| 6491 | 6588 | def ProcessConfigOverrides(filename): | |
| 6492 | 6589 | """ Loads the configuration files and processes the config overrides. | |
| 6493 | 6590 | ||
@@ -6506,7 +6603,7 @@ def ProcessConfigOverrides(filename): | |||
| 6506 | 6603 | if not base_name: | |
| 6507 | 6604 | break # Reached the root directory. | |
| 6508 | 6605 | ||
| 6509 | - cfg_file = os.path.join(abs_path, "CPPLINT.cfg") | ||
| 6606 | + cfg_file = os.path.join(abs_path, ".cpplint") | ||
| 6510 | 6607 | abs_filename = abs_path | |
| 6511 | 6608 | if not os.path.isfile(cfg_file): | |
| 6512 | 6609 | continue | |
| Back | FazBrowse Home | New Git URL |
0 commit comments