From 9bc91b4019fe9a34dd342dc5cf7f1091f53b4815 Mon Sep 17 00:00:00 2001 From: Kevin Powell Date: Thu, 6 Oct 2016 14:08:46 -0400 Subject: [PATCH] [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. --- cpplint/cpplint.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index 60d7226..97bdc01 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -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.')