| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fa90d09 commit 4e442b2
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -306,9 +306,10 @@ | |||
| 306 | 306 | "build/forward_decl", | |
| 307 | 307 | "build/header_guard", | |
| 308 | 308 | "build/include", | |
| 309 | - "build/include_subdir", | ||
| 310 | 309 | "build/include_alpha", | |
| 310 | + "build/include_inline", | ||
| 311 | 311 | "build/include_order", | |
| 312 | + "build/include_subdir", | ||
| 312 | 313 | "build/include_what_you_use", | |
| 313 | 314 | "build/namespaces_headers", | |
| 314 | 315 | "build/namespaces/header/block/literals", | |
@@ -351,6 +352,7 @@ | |||
| 351 | 352 | "runtime/string", | |
| 352 | 353 | "runtime/threadsafe_fn", | |
| 353 | 354 | "runtime/vlog", | |
| 355 | + "runtime/v8_persistent", | ||
| 354 | 356 | "whitespace/blank_line", | |
| 355 | 357 | "whitespace/braces", | |
| 356 | 358 | "whitespace/comma", | |
@@ -920,6 +922,14 @@ | |||
| 920 | 922 | # Match string that indicates we're working on a Linux Kernel file. | |
| 921 | 923 | _SEARCH_KERNEL_FILE = re.compile(r"\b(?:LINT_KERNEL_FILE)") | |
| 922 | 924 | ||
| 925 | + _NULL_TOKEN_PATTERN = re.compile(r'\bNULL\b') | ||
| 926 | + | ||
| 927 | + _V8_PERSISTENT_PATTERN = re.compile(r'\bv8::Persistent\b') | ||
| 928 | + | ||
| 929 | + _RIGHT_LEANING_POINTER_PATTERN = re.compile(r'[^=|(,\s><);&?:}]' | ||
| 930 | + r'(?<!(sizeof|return))' | ||
| 931 | + r'\s\*[a-zA-z_][0-9a-zA-z_]*') | ||
| 932 | + | ||
| 923 | 933 | # Commands for sed to fix the problem | |
| 924 | 934 | _SED_FIXUPS = { | |
| 925 | 935 | "Remove spaces around =": r"s/ = /=/", | |
@@ -970,7 +980,7 @@ | |||
| 970 | 980 | _include_order = "default" | |
| 971 | 981 | ||
| 972 | 982 | # This allows different config files to be used | |
| 973 | - _config_filename = "CPPLINT.cfg" | ||
| 983 | + _config_filename = ".cpplint" | ||
| 974 | 984 | ||
| 975 | 985 | # Treat all headers starting with 'h' equally: .h, .hpp, .hxx etc. | |
| 976 | 986 | # This is set by --headers flag. | |
@@ -1256,10 +1266,10 @@ class _IncludeState: | |||
| 1256 | 1266 | # needs to move backwards, CheckNextIncludeOrder will raise an error. | |
| 1257 | 1267 | _INITIAL_SECTION = 0 | |
| 1258 | 1268 | _MY_H_SECTION = 1 | |
| 1259 | - _C_SECTION = 2 | ||
| 1260 | - _CPP_SECTION = 3 | ||
| 1261 | - _OTHER_SYS_SECTION = 4 | ||
| 1262 | - _OTHER_H_SECTION = 5 | ||
| 1269 | + _OTHER_H_SECTION = 2 | ||
| 1270 | + _C_SECTION = 3 | ||
| 1271 | + _CPP_SECTION = 4 | ||
| 1272 | + _OTHER_SYS_SECTION = 5 | ||
| 1263 | 1273 | ||
| 1264 | 1274 | _TYPE_NAMES = { | |
| 1265 | 1275 | _C_SYS_HEADER: "C system header", | |
@@ -1272,10 +1282,10 @@ class _IncludeState: | |||
| 1272 | 1282 | _SECTION_NAMES = { | |
| 1273 | 1283 | _INITIAL_SECTION: "... nothing. (This can't be an error.)", | |
| 1274 | 1284 | _MY_H_SECTION: "a header this file implements", | |
| 1285 | + _OTHER_H_SECTION: "other header", | ||
| 1275 | 1286 | _C_SECTION: "C system header", | |
| 1276 | 1287 | _CPP_SECTION: "C++ system header", | |
| 1277 | 1288 | _OTHER_SYS_SECTION: "other system header", | |
| 1278 | - _OTHER_H_SECTION: "other header", | ||
| 1279 | 1289 | } | |
| 1280 | 1290 | ||
| 1281 | 1291 | def __init__(self): | |
@@ -2794,6 +2804,21 @@ def CheckForBadCharacters(filename, lines, error): | |||
| 2794 | 2804 | error(filename, linenum, "readability/nul", 5, "Line contains NUL byte.") | |
| 2795 | 2805 | ||
| 2796 | 2806 | ||
| 2807 | + def CheckInlineHeader(filename, include_state, error): | ||
| 2808 | + """Logs an error if both a header and its inline variant are included.""" | ||
| 2809 | + | ||
| 2810 | + all_headers = dict(item for sublist in include_state.include_list | ||
| 2811 | + for item in sublist) | ||
| 2812 | + bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys() | ||
| 2813 | + if name.endswith('-inl.h')) | ||
| 2814 | + bad_headers &= set(all_headers.keys()) | ||
| 2815 | + | ||
| 2816 | + for name in bad_headers: | ||
| 2817 | + err = '%s includes both %s and %s-inl.h' % (filename, name, name) | ||
| 2818 | + linenum = all_headers[name] | ||
| 2819 | + error(filename, linenum, 'build/include_inline', 5, err) | ||
| 2820 | + | ||
| 2821 | + | ||
| 2797 | 2822 | def CheckForNewlineAtEOF(filename, lines, error): | |
| 2798 | 2823 | """Logs an error if there is no newline char at the end of the file. | |
| 2799 | 2824 | ||
@@ -4044,7 +4069,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum, function_state, erro | |||
| 4044 | 4069 | """Reports for long function bodies. | |
| 4045 | 4070 | ||
| 4046 | 4071 | For an overview why this is done, see: | |
| 4047 | - https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions | ||
| 4072 | + https://google.github.io/styleguide/cppguide.html#Write_Short_Functions | ||
| 4048 | 4073 | ||
| 4049 | 4074 | Uses a simplistic algorithm assuming other style guidelines | |
| 4050 | 4075 | (especially spacing) are followed. | |
@@ -5432,6 +5457,75 @@ def CheckAltTokens(filename, clean_lines, linenum, error): | |||
| 5432 | 5457 | ) | |
| 5433 | 5458 | ||
| 5434 | 5459 | ||
| 5460 | + def CheckNullTokens(filename, clean_lines, linenum, error): | ||
| 5461 | + """Check NULL usage. | ||
| 5462 | + | ||
| 5463 | + Args: | ||
| 5464 | + filename: The name of the current file. | ||
| 5465 | + clean_lines: A CleansedLines instance containing the file. | ||
| 5466 | + linenum: The number of the line to check. | ||
| 5467 | + error: The function to call with any errors found. | ||
| 5468 | + """ | ||
| 5469 | + line = clean_lines.elided[linenum] | ||
| 5470 | + | ||
| 5471 | + # Avoid preprocessor lines | ||
| 5472 | + if re.match(r'^\s*#', line): | ||
| 5473 | + return | ||
| 5474 | + | ||
| 5475 | + if line.find('/*') >= 0 or line.find('*/') >= 0: | ||
| 5476 | + return | ||
| 5477 | + | ||
| 5478 | + for match in _NULL_TOKEN_PATTERN.finditer(line): | ||
| 5479 | + error(filename, linenum, 'readability/null_usage', 2, | ||
| 5480 | + 'Use nullptr instead of NULL') | ||
| 5481 | + | ||
| 5482 | + | ||
| 5483 | + def CheckV8PersistentTokens(filename, clean_lines, linenum, error): | ||
| 5484 | + """Check v8::Persistent usage. | ||
| 5485 | + | ||
| 5486 | + Args: | ||
| 5487 | + filename: The name of the current file. | ||
| 5488 | + clean_lines: A CleansedLines instance containing the file. | ||
| 5489 | + linenum: The number of the line to check. | ||
| 5490 | + error: The function to call with any errors found. | ||
| 5491 | + """ | ||
| 5492 | + line = clean_lines.elided[linenum] | ||
| 5493 | + | ||
| 5494 | + # Avoid preprocessor lines | ||
| 5495 | + if re.match(r'^\s*#', line): | ||
| 5496 | + return | ||
| 5497 | + | ||
| 5498 | + if line.find('/*') >= 0 or line.find('*/') >= 0: | ||
| 5499 | + return | ||
| 5500 | + | ||
| 5501 | + for match in _V8_PERSISTENT_PATTERN.finditer(line): | ||
| 5502 | + error(filename, linenum, 'runtime/v8_persistent', 2, | ||
| 5503 | + 'Use v8::Global instead of v8::Persistent') | ||
| 5504 | + | ||
| 5505 | + | ||
| 5506 | + def CheckLeftLeaningPointer(filename, clean_lines, linenum, error): | ||
| 5507 | + """Check for left-leaning pointer placement. | ||
| 5508 | + | ||
| 5509 | + Args: | ||
| 5510 | + filename: The name of the current file. | ||
| 5511 | + clean_lines: A CleansedLines instance containing the file. | ||
| 5512 | + linenum: The number of the line to check. | ||
| 5513 | + error: The function to call with any errors found. | ||
| 5514 | + """ | ||
| 5515 | + line = clean_lines.elided[linenum] | ||
| 5516 | + | ||
| 5517 | + # Avoid preprocessor lines | ||
| 5518 | + if re.match(r'^\s*#', line): | ||
| 5519 | + return | ||
| 5520 | + | ||
| 5521 | + if '/*' in line or '*/' in line: | ||
| 5522 | + return | ||
| 5523 | + | ||
| 5524 | + for match in _RIGHT_LEANING_POINTER_PATTERN.finditer(line): | ||
| 5525 | + error(filename, linenum, 'readability/null_usage', 2, | ||
| 5526 | + 'Use left leaning pointer instead of right leaning') | ||
| 5527 | + | ||
| 5528 | + | ||
| 5435 | 5529 | def GetLineWidth(line): | |
| 5436 | 5530 | """Determines the width of the line in column positions. | |
| 5437 | 5531 | ||
@@ -5603,6 +5697,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, er | |||
| 5603 | 5697 | CheckSpacingForFunctionCall(filename, clean_lines, linenum, error) | |
| 5604 | 5698 | CheckCheck(filename, clean_lines, linenum, error) | |
| 5605 | 5699 | CheckAltTokens(filename, clean_lines, linenum, error) | |
| 5700 | + CheckNullTokens(filename, clean_lines, linenum, error) | ||
| 5701 | + CheckV8PersistentTokens(filename, clean_lines, linenum, error) | ||
| 5702 | + CheckLeftLeaningPointer(filename, clean_lines, linenum, error) | ||
| 5606 | 5703 | classinfo = nesting_state.InnermostClass() | |
| 5607 | 5704 | if classinfo: | |
| 5608 | 5705 | CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error) | |
@@ -6155,7 +6252,7 @@ def CheckLanguage( | |||
| 6155 | 6252 | "build/namespaces_headers", | |
| 6156 | 6253 | 4, | |
| 6157 | 6254 | "Do not use unnamed namespaces in header files. See " | |
| 6158 | - "https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces" | ||
| 6255 | + "https://google.github.io/styleguide/cppguide.html#Namespaces" | ||
| 6159 | 6256 | " for more information.", | |
| 6160 | 6257 | ) | |
| 6161 | 6258 | ||
@@ -7313,6 +7410,42 @@ def CheckItemIndentationInNamespace(filename, raw_lines_no_comments, linenum, er | |||
| 7313 | 7410 | ) | |
| 7314 | 7411 | ||
| 7315 | 7412 | ||
| 7413 | + def CheckLocalVectorUsage(filename, lines, error): | ||
| 7414 | + """Logs an error if std::vector<v8::Local<T>> is used. | ||
| 7415 | + Args: | ||
| 7416 | + filename: The name of the current file. | ||
| 7417 | + lines: An array of strings, each representing a line of the file. | ||
| 7418 | + error: The function to call with any errors found. | ||
| 7419 | + """ | ||
| 7420 | + for linenum, line in enumerate(lines): | ||
| 7421 | + if (re.search(r'\bstd::vector<v8::Local<[^>]+>>', line) or | ||
| 7422 | + re.search(r'\bstd::vector<Local<[^>]+>>', line)): | ||
| 7423 | + error(filename, linenum, 'runtime/local_vector', 5, | ||
| 7424 | + 'Do not use std::vector<v8::Local<T>>. ' | ||
| 7425 | + 'Use v8::LocalVector<T> instead.') | ||
| 7426 | + | ||
| 7427 | + | ||
| 7428 | + def CheckStringValueUsage(filename, lines, error): | ||
| 7429 | + """Logs an error if v8's String::Value/Utf8Value are used. | ||
| 7430 | + Args: | ||
| 7431 | + filename: The name of the current file. | ||
| 7432 | + lines: An array of strings, each representing a line of the file. | ||
| 7433 | + error: The function to call with any errors found. | ||
| 7434 | + """ | ||
| 7435 | + if filename.startswith('test/') or filename.startswith('test\\'): | ||
| 7436 | + return # Skip test files, where Node.js headers may not be available | ||
| 7437 | + | ||
| 7438 | + for linenum, line in enumerate(lines): | ||
| 7439 | + if re.search(r'\bString::Utf8Value\b', line): | ||
| 7440 | + error(filename, linenum, 'runtime/v8_string_value', 5, | ||
| 7441 | + 'Do not use v8::String::Utf8Value. ' | ||
| 7442 | + 'Use node::Utf8Value instead.') | ||
| 7443 | + if re.search(r'\bString::Value\b', line): | ||
| 7444 | + error(filename, linenum, 'runtime/v8_string_value', 5, | ||
| 7445 | + 'Do not use v8::String::Value. ' | ||
| 7446 | + 'Use node::TwoByteValue instead.') | ||
| 7447 | + | ||
| 7448 | + | ||
| 7316 | 7449 | def ProcessLine( | |
| 7317 | 7450 | filename, | |
| 7318 | 7451 | file_extension, | |
@@ -7470,6 +7603,12 @@ def ProcessFileData(filename, file_extension, lines, error, extra_check_function | |||
| 7470 | 7603 | ||
| 7471 | 7604 | CheckForNewlineAtEOF(filename, lines, error) | |
| 7472 | 7605 | ||
| 7606 | + CheckInlineHeader(filename, include_state, error) | ||
| 7607 | + | ||
| 7608 | + CheckLocalVectorUsage(filename, lines, error) | ||
| 7609 | + | ||
| 7610 | + CheckStringValueUsage(filename, lines, error) | ||
| 7611 | + | ||
| 7473 | 7612 | ||
| 7474 | 7613 | def ProcessConfigOverrides(filename): | |
| 7475 | 7614 | """Loads the configuration files and processes the config overrides. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments