| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1173efc commit adf4f90
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -280,6 +280,7 @@ | |||
| 280 | 280 | 'build/include', | |
| 281 | 281 | 'build/include_subdir', | |
| 282 | 282 | 'build/include_alpha', | |
| 283 | + 'build/include_inline', | ||
| 283 | 284 | 'build/include_order', | |
| 284 | 285 | 'build/include_what_you_use', | |
| 285 | 286 | 'build/namespaces_literals', | |
@@ -294,11 +295,13 @@ | |||
| 294 | 295 | 'readability/constructors', | |
| 295 | 296 | 'readability/fn_size', | |
| 296 | 297 | 'readability/inheritance', | |
| 298 | + 'readability/pointer_notation', | ||
| 297 | 299 | 'readability/multiline_comment', | |
| 298 | 300 | 'readability/multiline_string', | |
| 299 | 301 | 'readability/namespace', | |
| 300 | 302 | 'readability/nolint', | |
| 301 | 303 | 'readability/nul', | |
| 304 | + 'readability/null_usage', | ||
| 302 | 305 | 'readability/strings', | |
| 303 | 306 | 'readability/todo', | |
| 304 | 307 | 'readability/utf8', | |
@@ -318,6 +321,7 @@ | |||
| 318 | 321 | 'runtime/string', | |
| 319 | 322 | 'runtime/threadsafe_fn', | |
| 320 | 323 | 'runtime/vlog', | |
| 324 | + 'runtime/v8_persistent', | ||
| 321 | 325 | 'whitespace/blank_line', | |
| 322 | 326 | 'whitespace/braces', | |
| 323 | 327 | 'whitespace/comma', | |
@@ -622,6 +626,14 @@ | |||
| 622 | 626 | # Match string that indicates we're working on a Linux Kernel file. | |
| 623 | 627 | _SEARCH_KERNEL_FILE = re.compile(r'\b(?:LINT_KERNEL_FILE)') | |
| 624 | 628 | ||
| 629 | + _NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b') | ||
| 630 | + | ||
| 631 | + _V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b') | ||
| 632 | + | ||
| 633 | + _RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]' | ||
| 634 | + r'(?<!(sizeof|return))' | ||
| 635 | + r'\s\*[a-zA-Z_][0-9a-zA-Z_]*') | ||
| 636 | + | ||
| 625 | 637 | _regexp_compile_cache = {} | |
| 626 | 638 | ||
| 627 | 639 | # {str, set(int)}: a map from error categories to sets of linenumbers | |
@@ -641,7 +653,7 @@ | |||
| 641 | 653 | # Files to exclude from linting. This is set by the --exclude flag. | |
| 642 | 654 | _excludes = None | |
| 643 | 655 | ||
| 644 | - # Whether to supress PrintInfo messages | ||
| 656 | + # Whether to suppress PrintInfo messages | ||
| 645 | 657 | _quiet = False | |
| 646 | 658 | ||
| 647 | 659 | # The allowed line length of files. | |
@@ -850,9 +862,9 @@ class _IncludeState(object): | |||
| 850 | 862 | # needs to move backwards, CheckNextIncludeOrder will raise an error. | |
| 851 | 863 | _INITIAL_SECTION = 0 | |
| 852 | 864 | _MY_H_SECTION = 1 | |
| 853 | - _C_SECTION = 2 | ||
| 854 | - _CPP_SECTION = 3 | ||
| 855 | - _OTHER_H_SECTION = 4 | ||
| 865 | + _OTHER_H_SECTION = 2 | ||
| 866 | + _C_SECTION = 3 | ||
| 867 | + _CPP_SECTION = 4 | ||
| 856 | 868 | ||
| 857 | 869 | _TYPE_NAMES = { | |
| 858 | 870 | _C_SYS_HEADER: 'C system header', | |
@@ -864,9 +876,9 @@ class _IncludeState(object): | |||
| 864 | 876 | _SECTION_NAMES = { | |
| 865 | 877 | _INITIAL_SECTION: "... nothing. (This can't be an error.)", | |
| 866 | 878 | _MY_H_SECTION: 'a header this file implements', | |
| 879 | + _OTHER_H_SECTION: 'other header', | ||
| 867 | 880 | _C_SECTION: 'C system header', | |
| 868 | 881 | _CPP_SECTION: 'C++ system header', | |
| 869 | - _OTHER_H_SECTION: 'other header', | ||
| 870 | 882 | } | |
| 871 | 883 | ||
| 872 | 884 | def __init__(self): | |
@@ -2262,6 +2274,21 @@ def CheckForBadCharacters(filename, lines, error): | |||
| 2262 | 2274 | error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.') | |
| 2263 | 2275 | ||
| 2264 | 2276 | ||
| 2277 | + def CheckInlineHeader(filename, include_state, error): | ||
| 2278 | + """Logs an error if both a header and its inline variant are included.""" | ||
| 2279 | + | ||
| 2280 | + all_headers = dict(item for sublist in include_state.include_list | ||
| 2281 | + for item in sublist) | ||
| 2282 | + bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys() | ||
| 2283 | + if name.endswith('-inl.h')) | ||
| 2284 | + bad_headers &= set(all_headers.keys()) | ||
| 2285 | + | ||
| 2286 | + for name in bad_headers: | ||
| 2287 | + err = '%s includes both %s and %s-inl.h' % (filename, name, name) | ||
| 2288 | + linenum = all_headers[name] | ||
| 2289 | + error(filename, linenum, 'build/include_inline', 5, err) | ||
| 2290 | + | ||
| 2291 | + | ||
| 2265 | 2292 | def CheckForNewlineAtEOF(filename, lines, error): | |
| 2266 | 2293 | """Logs an error if there is no newline char at the end of the file. | |
| 2267 | 2294 | ||
@@ -3285,7 +3312,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum, | |||
| 3285 | 3312 | """Reports for long function bodies. | |
| 3286 | 3313 | ||
| 3287 | 3314 | For an overview why this is done, see: | |
| 3288 | - https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions | ||
| 3315 | + https://google.github.io/styleguide/cppguide.html#Write_Short_Functions | ||
| 3289 | 3316 | ||
| 3290 | 3317 | Uses a simplistic algorithm assuming other style guidelines | |
| 3291 | 3318 | (especially spacing) are followed. | |
@@ -4511,6 +4538,71 @@ def CheckAltTokens(filename, clean_lines, linenum, error): | |||
| 4511 | 4538 | 'Use operator %s instead of %s' % ( | |
| 4512 | 4539 | _ALT_TOKEN_REPLACEMENT[match.group(1)], match.group(1))) | |
| 4513 | 4540 | ||
| 4541 | + def CheckNullTokens(filename, clean_lines, linenum, error): | ||
| 4542 | + """Check NULL usage. | ||
| 4543 | + | ||
| 4544 | + Args: | ||
| 4545 | + filename: The name of the current file. | ||
| 4546 | + clean_lines: A CleansedLines instance containing the file. | ||
| 4547 | + linenum: The number of the line to check. | ||
| 4548 | + error: The function to call with any errors found. | ||
| 4549 | + """ | ||
| 4550 | + line = clean_lines.elided[linenum] | ||
| 4551 | + | ||
| 4552 | + # Avoid preprocessor lines | ||
| 4553 | + if Match(r'^\s*#', line): | ||
| 4554 | + return | ||
| 4555 | + | ||
| 4556 | + if line.find('/*') >= 0 or line.find('*/') >= 0: | ||
| 4557 | + return | ||
| 4558 | + | ||
| 4559 | + for match in _NULL_TOKEN_PATTERN.finditer(line): | ||
| 4560 | + error(filename, linenum, 'readability/null_usage', 2, | ||
| 4561 | + 'Use nullptr instead of NULL') | ||
| 4562 | + | ||
| 4563 | + def CheckV8PersistentTokens(filename, clean_lines, linenum, error): | ||
| 4564 | + """Check v8::Persistent usage. | ||
| 4565 | + | ||
| 4566 | + Args: | ||
| 4567 | + filename: The name of the current file. | ||
| 4568 | + clean_lines: A CleansedLines instance containing the file. | ||
| 4569 | + linenum: The number of the line to check. | ||
| 4570 | + error: The function to call with any errors found. | ||
| 4571 | + """ | ||
| 4572 | + line = clean_lines.elided[linenum] | ||
| 4573 | + | ||
| 4574 | + # Avoid preprocessor lines | ||
| 4575 | + if Match(r'^\s*#', line): | ||
| 4576 | + return | ||
| 4577 | + | ||
| 4578 | + if line.find('/*') >= 0 or line.find('*/') >= 0: | ||
| 4579 | + return | ||
| 4580 | + | ||
| 4581 | + for match in _V8_PERSISTENT_PATTERN.finditer(line): | ||
| 4582 | + error(filename, linenum, 'runtime/v8_persistent', 2, | ||
| 4583 | + 'Use v8::Global instead of v8::Persistent') | ||
| 4584 | + | ||
| 4585 | + def CheckLeftLeaningPointer(filename, clean_lines, linenum, error): | ||
| 4586 | + """Check for left-leaning pointer placement. | ||
| 4587 | + | ||
| 4588 | + Args: | ||
| 4589 | + filename: The name of the current file. | ||
| 4590 | + clean_lines: A CleansedLines instance containing the file. | ||
| 4591 | + linenum: The number of the line to check. | ||
| 4592 | + error: The function to call with any errors found. | ||
| 4593 | + """ | ||
| 4594 | + line = clean_lines.elided[linenum] | ||
| 4595 | + | ||
| 4596 | + # Avoid preprocessor lines | ||
| 4597 | + if Match(r'^\s*#', line): | ||
| 4598 | + return | ||
| 4599 | + | ||
| 4600 | + if '/*' in line or '*/' in line: | ||
| 4601 | + return | ||
| 4602 | + | ||
| 4603 | + for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line): | ||
| 4604 | + error(filename, linenum, 'readability/pointer_notation', 2, | ||
| 4605 | + 'Use left leaning pointer instead of right leaning') | ||
| 4514 | 4606 | ||
| 4515 | 4607 | def GetLineWidth(line): | |
| 4516 | 4608 | """Determines the width of the line in column positions. | |
@@ -4665,6 +4757,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, | |||
| 4665 | 4757 | CheckSpacingForFunctionCall(filename, clean_lines, linenum, error) | |
| 4666 | 4758 | CheckCheck(filename, clean_lines, linenum, error) | |
| 4667 | 4759 | CheckAltTokens(filename, clean_lines, linenum, error) | |
| 4760 | + CheckNullTokens(filename, clean_lines, linenum, error) | ||
| 4761 | + CheckV8PersistentTokens(filename, clean_lines, linenum, error) | ||
| 4762 | + CheckLeftLeaningPointer(filename, clean_lines, linenum, error) | ||
| 4668 | 4763 | classinfo = nesting_state.InnermostClass() | |
| 4669 | 4764 | if classinfo: | |
| 4670 | 4765 | CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error) | |
@@ -4841,11 +4936,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error): | |||
| 4841 | 4936 | include_state.include_list[-1].append((include, linenum)) | |
| 4842 | 4937 | ||
| 4843 | 4938 | # We want to ensure that headers appear in the right order: | |
| 4844 | - # 1) for foo.cc, foo.h (preferred location) | ||
| 4845 | - # 2) c system files | ||
| 4846 | - # 3) cpp system files | ||
| 4847 | - # 4) for foo.cc, foo.h (deprecated location) | ||
| 4848 | - # 5) other google headers | ||
| 4939 | + # 1) for foo.cc, foo.h | ||
| 4940 | + # 2) other project headers | ||
| 4941 | + # 3) c system files | ||
| 4942 | + # 4) cpp system files | ||
| 4849 | 4943 | # | |
| 4850 | 4944 | # We classify each include statement as one of those 5 types | |
| 4851 | 4945 | # using a number of techniques. The include_state object keeps | |
@@ -5108,7 +5202,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension, | |||
| 5108 | 5202 | and line[-1] != '\\'): | |
| 5109 | 5203 | error(filename, linenum, 'build/namespaces', 4, | |
| 5110 | 5204 | 'Do not use unnamed namespaces in header files. See ' | |
| 5111 | - 'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces' | ||
| 5205 | + 'https://google.github.io/styleguide/cppguide.html#Namespaces' | ||
| 5112 | 5206 | ' for more information.') | |
| 5113 | 5207 | ||
| 5114 | 5208 | ||
@@ -6230,6 +6324,8 @@ def ProcessFileData(filename, file_extension, lines, error, | |||
| 6230 | 6324 | ||
| 6231 | 6325 | CheckForNewlineAtEOF(filename, lines, error) | |
| 6232 | 6326 | ||
| 6327 | + CheckInlineHeader(filename, include_state, error) | ||
| 6328 | + | ||
| 6233 | 6329 | def ProcessConfigOverrides(filename): | |
| 6234 | 6330 | """ Loads the configuration files and processes the config overrides. | |
| 6235 | 6331 | ||
@@ -6248,7 +6344,7 @@ def ProcessConfigOverrides(filename): | |||
| 6248 | 6344 | if not base_name: | |
| 6249 | 6345 | break # Reached the root directory. | |
| 6250 | 6346 | ||
| 6251 | - cfg_file = os.path.join(abs_path, "CPPLINT.cfg") | ||
| 6347 | + cfg_file = os.path.join(abs_path, ".cpplint") | ||
| 6252 | 6348 | abs_filename = abs_path | |
| 6253 | 6349 | if not os.path.isfile(cfg_file): | |
| 6254 | 6350 | continue | |
| Back | FazBrowse Home | New Git URL |
0 commit comments