Skip to content

Commit

Permalink
Restore the accidentally deleted extra_check_functions in cpplint.py
Browse files Browse the repository at this point in the history
This extra parameter was used when calling cpplint.ProcessFile
directly from depot_tools/gcl.py and depot_tools/git_cl.py.

Restoring it...

[email protected]

Review URL: https://codereview.appspot.com/105820044
  • Loading branch information
[email protected] committed Jun 4, 2014
1 parent 02af628 commit 4b957b2
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions cpplint/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5289,7 +5289,8 @@ def CheckDefaultLambdaCaptures(filename, clean_lines, linenum, error):


def ProcessLine(filename, file_extension, clean_lines, line,
include_state, function_state, nesting_state, error):
include_state, function_state, nesting_state, error,
extra_check_functions=[]):
"""Processes a single line in the file.
Args:
Expand All @@ -5304,7 +5305,9 @@ def ProcessLine(filename, file_extension, clean_lines, line,
the current stack of nested blocks being parsed.
error: A callable to which errors are reported, which takes 4 arguments:
filename, line number, error level, and message
extra_check_functions: An array of additional check functions that will be
run on each source line. Each function takes 4
arguments: filename, clean_lines, line, error
"""
raw_lines = clean_lines.raw_lines
ParseNolintSuppressions(filename, raw_lines[line], line, error)
Expand All @@ -5323,8 +5326,9 @@ def ProcessLine(filename, file_extension, clean_lines, line,
CheckInvalidIncrement(filename, clean_lines, line, error)
CheckMakePairUsesDeduction(filename, clean_lines, line, error)
CheckDefaultLambdaCaptures(filename, clean_lines, line, error)


for check_fn in extra_check_functions:
check_fn(filename, clean_lines, line, error)

def FlagCxx11Features(filename, clean_lines, linenum, error):
"""Flag those c++11 features that we only allow in certain places.
Expand Down Expand Up @@ -5374,7 +5378,8 @@ def FlagCxx11Features(filename, clean_lines, linenum, error):
'they may let you use it.') % top_name)


def ProcessFileData(filename, file_extension, lines, error):
def ProcessFileData(filename, file_extension, lines, error,
extra_check_functions=[]):
"""Performs lint checks and reports any errors to the given error function.
Args:
Expand All @@ -5383,6 +5388,10 @@ def ProcessFileData(filename, file_extension, lines, error):
lines: An array of strings, each representing a line of the file, with the
last element being empty if the file is terminated with a newline.
error: A callable to which errors are reported, which takes 4 arguments:
filename, line number, error level, and message
extra_check_functions: An array of additional check functions that will be
run on each source line. Each function takes 4
arguments: filename, clean_lines, line, error
"""
lines = (['// marker so line numbers and indices both start at 1'] + lines +
['// marker so line numbers end in a known way'])
Expand All @@ -5402,7 +5411,8 @@ def ProcessFileData(filename, file_extension, lines, error):
clean_lines = CleansedLines(lines)
for line in xrange(clean_lines.NumLines()):
ProcessLine(filename, file_extension, clean_lines, line,
include_state, function_state, nesting_state, error)
include_state, function_state, nesting_state, error,
extra_check_functions)
FlagCxx11Features(filename, clean_lines, line, error)
nesting_state.CheckCompletedBlocks(filename, error)

Expand All @@ -5415,14 +5425,18 @@ def ProcessFileData(filename, file_extension, lines, error):
CheckForNewlineAtEOF(filename, lines, error)


def ProcessFile(filename, vlevel):
def ProcessFile(filename, vlevel, extra_check_functions=[]):
"""Does google-lint on a single file.
Args:
filename: The name of the file to parse.
vlevel: The level of errors to report. Every error of confidence
>= verbose_level will be reported. 0 is a good default.
extra_check_functions: An array of additional check functions that will be
run on each source line. Each function takes 4
arguments: filename, clean_lines, line, error
"""

_SetVerboseLevel(vlevel)
Expand Down Expand Up @@ -5468,7 +5482,8 @@ def ProcessFile(filename, vlevel):
sys.stderr.write('Ignoring %s; not a valid file name '
'(%s)\n' % (filename, ', '.join(_valid_extensions)))
else:
ProcessFileData(filename, file_extension, lines, Error)
ProcessFileData(filename, file_extension, lines, Error,
extra_check_functions)

# If end-of-line sequences are a mix of LF and CR-LF, issue
# warnings on the lines with CR.
Expand Down

0 comments on commit 4b957b2

Please sign in to comment.