MCPcopy Create free account
hub / github.com/BVLC/caffe / CheckStyle

Function CheckStyle

scripts/cpp_lint.py:3463–3567  ·  view source on GitHub ↗

Checks rules from the 'C++ style rules' section of cppguide.html. Most of these rules are hard to test (naming, comment style), but we do what we can. In particular we check for 2-space indents, line lengths, tab usage, spaces inside code, etc. Args: filename: The name of the current

(filename, clean_lines, linenum, file_extension, nesting_state,
               error)

Source from the content-addressed store, hash-verified

3461
3462
3463def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
3464 error):
3465 """Checks rules from the 'C++ style rules' section of cppguide.html.
3466
3467 Most of these rules are hard to test (naming, comment style), but we
3468 do what we can. In particular we check for 2-space indents, line lengths,
3469 tab usage, spaces inside code, etc.
3470
3471 Args:
3472 filename: The name of the current file.
3473 clean_lines: A CleansedLines instance containing the file.
3474 linenum: The number of the line to check.
3475 file_extension: The extension (without the dot) of the filename.
3476 nesting_state: A _NestingState instance which maintains information about
3477 the current stack of nested blocks being parsed.
3478 error: The function to call with any errors found.
3479 """
3480
3481 # Don't use "elided" lines here, otherwise we can't check commented lines.
3482 # Don't want to use "raw" either, because we don't want to check inside C++11
3483 # raw strings,
3484 raw_lines = clean_lines.lines_without_raw_strings
3485 line = raw_lines[linenum]
3486
3487 if line.find('\t') != -1:
3488 error(filename, linenum, 'whitespace/tab', 1,
3489 'Tab found; better to use spaces')
3490
3491 # One or three blank spaces at the beginning of the line is weird; it's
3492 # hard to reconcile that with 2-space indents.
3493 # NOTE: here are the conditions rob pike used for his tests. Mine aren't
3494 # as sophisticated, but it may be worth becoming so: RLENGTH==initial_spaces
3495 # if(RLENGTH > 20) complain = 0;
3496 # if(match($0, " +(error|private|public|protected):")) complain = 0;
3497 # if(match(prev, "&& *$")) complain = 0;
3498 # if(match(prev, "\\|\\| *$")) complain = 0;
3499 # if(match(prev, "[\",=><] *$")) complain = 0;
3500 # if(match($0, " <<")) complain = 0;
3501 # if(match(prev, " +for \\(")) complain = 0;
3502 # if(prevodd && match(prevprev, " +for \\(")) complain = 0;
3503 initial_spaces = 0
3504 cleansed_line = clean_lines.elided[linenum]
3505 while initial_spaces < len(line) and line[initial_spaces] == ' ':
3506 initial_spaces += 1
3507 if line and line[-1].isspace():
3508 error(filename, linenum, 'whitespace/end_of_line', 4,
3509 'Line ends in whitespace. Consider deleting these extra spaces.')
3510 # There are certain situations we allow one space, notably for section labels
3511 elif ((initial_spaces == 1 or initial_spaces == 3) and
3512 not Match(r'\s*\w+\s*:\s*$', cleansed_line)):
3513 error(filename, linenum, 'whitespace/indent', 3,
3514 'Weird number of spaces at line-start. '
3515 'Are you using a 2-space indent?')
3516
3517 # Check if the line is a header guard.
3518 is_header_guard = False
3519 if file_extension == 'h':
3520 cppvar = GetHeaderGuardCPPVariable(filename)

Callers 1

ProcessLineFunction · 0.85

Calls 13

MatchFunction · 0.85
GetLineWidthFunction · 0.85
GetPreviousNonBlankLineFunction · 0.85
CheckBracesFunction · 0.85
CheckEmptyBlockBodyFunction · 0.85
CheckAccessFunction · 0.85
CheckSpacingFunction · 0.85
CheckCheckFunction · 0.85
CheckAltTokensFunction · 0.85
CheckSectionSpacingFunction · 0.85
countMethod · 0.80

Tested by

no test coverage detected