Make "root" flag configurable via CPPLINT.CFG

This commit is contained in:
Fabian Guera 2016-05-01 17:36:30 +02:00
parent 175866f6c4
commit 2322e4ffaa
No known key found for this signature in database
GPG Key ID: 0CC5D9EA243B3AEC

13
cpplint/cpplint.py vendored
View File

@ -142,6 +142,7 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
filter=+filter1,-filter2,... filter=+filter1,-filter2,...
exclude_files=regex exclude_files=regex
linelength=80 linelength=80
root=subdir
"set noparent" option prevents cpplint from traversing directory tree "set noparent" option prevents cpplint from traversing directory tree
upwards looking for more .cfg files in parent directories. This option upwards looking for more .cfg files in parent directories. This option
@ -157,6 +158,9 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
"linelength" allows to specify the allowed line length for the project. "linelength" allows to specify the allowed line length for the project.
The "root" option is similar in function to the --root flag (see example
above).
CPPLINT.cfg has an effect on files in the same directory and all CPPLINT.cfg has an effect on files in the same directory and all
sub-directories, unless overridden by a nested configuration file. sub-directories, unless overridden by a nested configuration file.
@ -1666,7 +1670,7 @@ def GetHeaderGuardCPPVariable(filename):
filename = re.sub(r'/\.flymake/([^/]*)$', r'/\1', filename) filename = re.sub(r'/\.flymake/([^/]*)$', r'/\1', filename)
# Replace 'c++' with 'cpp'. # Replace 'c++' with 'cpp'.
filename = filename.replace('C++', 'cpp').replace('c++', 'cpp') filename = filename.replace('C++', 'cpp').replace('c++', 'cpp')
fileinfo = FileInfo(filename) fileinfo = FileInfo(filename)
file_path_from_root = fileinfo.RepositoryName() file_path_from_root = fileinfo.RepositoryName()
if _root: if _root:
@ -4794,7 +4798,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
# Make Windows paths like Unix. # Make Windows paths like Unix.
fullname = os.path.abspath(filename).replace('\\', '/') fullname = os.path.abspath(filename).replace('\\', '/')
# Perform other checks now that we are sure that this is not an include line # Perform other checks now that we are sure that this is not an include line
CheckCasts(filename, clean_lines, linenum, error) CheckCasts(filename, clean_lines, linenum, error)
CheckGlobalStatic(filename, clean_lines, linenum, error) CheckGlobalStatic(filename, clean_lines, linenum, error)
@ -6034,7 +6038,7 @@ def ProcessFileData(filename, file_extension, lines, error,
nesting_state.CheckCompletedBlocks(filename, error) nesting_state.CheckCompletedBlocks(filename, error)
CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error) CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error)
# Check that the .cc file has included its header if it exists. # Check that the .cc file has included its header if it exists.
if file_extension == 'cc': if file_extension == 'cc':
CheckHeaderFileIncluded(filename, include_state, error) CheckHeaderFileIncluded(filename, include_state, error)
@ -6103,6 +6107,9 @@ def ProcessConfigOverrides(filename):
_line_length = int(val) _line_length = int(val)
except ValueError: except ValueError:
sys.stderr.write('Line length must be numeric.') sys.stderr.write('Line length must be numeric.')
elif name == 'root':
global _root
_root = val
else: else:
sys.stderr.write( sys.stderr.write(
'Invalid configuration option (%s) in file %s\n' % 'Invalid configuration option (%s) in file %s\n' %