[Feature] Added Override for indent spaces

Added the ability to override the default 2 spaces per indent to allow for flexibility for the end user to allow for something other than the default.
This commit is contained in:
Kevin Powell 2016-10-06 14:08:46 -04:00
parent 95fae366d3
commit 9bc91b4019

28
cpplint/cpplint.py vendored
View File

@ -142,6 +142,13 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
--headers=hpp,hxx
--headers=hpp
indentspaces=digits
This is the allowed number of spaces used for each indent level at the
beginning of a line of code. The default value is 2 spaces.
Examples:
--indentspaces=4
cpplint.py supports per-directory configurations specified in CPPLINT.cfg
files. CPPLINT.cfg file can contain a number of key=value pairs.
Currently the following options are supported:
@ -152,6 +159,7 @@ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
linelength=80
root=subdir
headers=x,y,...
indentspaces=2
"set noparent" option prevents cpplint from traversing directory tree
upwards looking for more .cfg files in parent directories. This option
@ -552,6 +560,10 @@ _valid_extensions = set(['cc', 'h', 'cpp', 'cu', 'cuh'])
# This is set by --headers flag.
_hpp_headers = set(['h'])
# The allowed number of indent spaces for each level of indentation
# This is set by --indentspaces flag.
_indent_spaces = 2
# {str, bool}: a map from error categories to booleans which indicate if the
# category should be suppressed for every line.
_global_error_suppressions = {}
@ -4312,6 +4324,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
Match(r'^\s*""', line))):
error(filename, linenum, 'whitespace/indent', 3,
'Weird number of spaces at line-start. '
'Are you using a %d-space indent?' % (_indent_spaces))
if line and line[-1].isspace():
error(filename, linenum, 'whitespace/end_of_line', 4,
@ -5951,6 +5964,12 @@ def ProcessConfigOverrides(filename):
_root = val
elif name == 'headers':
ProcessHppHeadersOption(val)
elif name == 'indentspaces':
global _indent_spaces
try:
_indent_spaces = int(val)
except ValueError:
sys.stderr.write('Indent spaces must be numeric.')
else:
sys.stderr.write(
'Invalid configuration option (%s) in file %s\n' %
@ -6097,7 +6116,8 @@ def ParseArguments(args):
'root=',
'linelength=',
'extensions=',
'headers='])
'headers=',
'indentspaces'])
except getopt.GetoptError:
PrintUsage('Invalid arguments.')
@ -6140,6 +6160,12 @@ def ParseArguments(args):
PrintUsage('Extensions must be comma seperated list.')
elif opt == '--headers':
ProcessHppHeadersOption(val)
elif opt == '--indentspaces':
global _indent_spaces
try:
_indent_spaces = int(val)
except ValueError:
PrintUsage('Indent spaces must be digits.')
if not filenames:
PrintUsage('No files were specified.')