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