Skip to content
This repository was archived by the owner on Jul 13, 2019. It is now read-only.

Commit af6f952

Browse files
Marco Massenziotkruse
authored andcommitted
Added the access keyword indent option
Customize indent for access keywords. Adds the ability to customize the indent for access keywords (private/public/protected) This can be done using either the --access_keywords_indent line option, or in the CPPLINT.cfg file (using the same option).
1 parent b066038 commit af6f952

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

cpplint.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@
502502
# This is set by --linelength flag.
503503
_line_length = 80
504504

505+
# The allowed indent for access keywords.
506+
# Set by default to +1, it can be changed with the
507+
# --access_keywords_indent (and correspondingly, in the CPPLINT.cfg
508+
# file too).
509+
_access_keyword_indent = 1
510+
505511
try:
506512
xrange
507513
except NameError:
@@ -2223,7 +2229,8 @@ def __init__(self, stack_before_if):
22232229
class NestingState(object):
22242230
"""Holds states related to parsing braces."""
22252231

2226-
def __init__(self):
2232+
def __init__(self, access_keyword_indent=1):
2233+
self.access_keyword_indent = access_keyword_indent
22272234
# Stack for tracking all braces. An object is pushed whenever we
22282235
# see a "{", and popped when we see a "}". Only 3 types of
22292236
# objects are possible:
@@ -2508,8 +2515,8 @@ def Update(self, filename, clean_lines, linenum, error):
25082515
# Check that access keywords are indented +1 space. Skip this
25092516
# check if the keywords are not preceded by whitespaces.
25102517
indent = access_match.group(1)
2511-
if (len(indent) != classinfo.class_indent + 1 and
2512-
Match(r'^\s*$', indent)):
2518+
if (len(indent) != classinfo.class_indent + self.access_keyword_indent and
2519+
(self.access_keyword_indent == 0 or Match(r'^\s*$', indent))):
25132520
if classinfo.is_struct:
25142521
parent = 'struct ' + classinfo.name
25152522
else:
@@ -6042,7 +6049,7 @@ def ProcessFileData(filename, file_extension, lines, error,
60426049

60436050
include_state = _IncludeState()
60446051
function_state = _FunctionState()
6045-
nesting_state = NestingState()
6052+
nesting_state = NestingState(access_keyword_indent=_access_keyword_indent)
60466053

60476054
ResetNolintSuppressions()
60486055

@@ -6131,6 +6138,12 @@ def ProcessConfigOverrides(filename):
61316138
_line_length = int(val)
61326139
except ValueError:
61336140
sys.stderr.write('Line length must be numeric.')
6141+
elif name == 'access_keywords_indent':
6142+
global _access_keyword_indent
6143+
try:
6144+
_access_keyword_indent = int(val)
6145+
except ValueError:
6146+
sys.stderr.write('Access keyword indent must be numeric.')
61346147
else:
61356148
sys.stderr.write(
61366149
'Invalid configuration option (%s) in file %s\n' %
@@ -6318,6 +6331,12 @@ def ParseArguments(args):
63186331
_valid_extensions = set(val.split(','))
63196332
except ValueError:
63206333
PrintUsage('Extensions must be comma seperated list.')
6334+
elif opt == '--access_keywords_indent':
6335+
global _access_keyword_indent
6336+
try:
6337+
_access_keyword_indent = int(val)
6338+
except ValueError:
6339+
PrintUsage('Access keywords indent values should be an integer value only.')
63216340

63226341
if not filenames:
63236342
PrintUsage('No files were specified.')

0 commit comments

Comments
 (0)