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

Commit 239396d

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 f59a765 commit 239396d

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:
@@ -2224,7 +2230,8 @@ def __init__(self, stack_before_if):
22242230
class NestingState(object):
22252231
"""Holds states related to parsing braces."""
22262232

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

60486055
include_state = _IncludeState()
60496056
function_state = _FunctionState()
6050-
nesting_state = NestingState()
6057+
nesting_state = NestingState(access_keyword_indent=_access_keyword_indent)
60516058

60526059
ResetNolintSuppressions()
60536060

@@ -6136,6 +6143,12 @@ def ProcessConfigOverrides(filename):
61366143
_line_length = int(val)
61376144
except ValueError:
61386145
sys.stderr.write('Line length must be numeric.')
6146+
elif name == 'access_keywords_indent':
6147+
global _access_keyword_indent
6148+
try:
6149+
_access_keyword_indent = int(val)
6150+
except ValueError:
6151+
sys.stderr.write('Access keyword indent must be numeric.')
61396152
else:
61406153
sys.stderr.write(
61416154
'Invalid configuration option (%s) in file %s\n' %
@@ -6323,6 +6336,12 @@ def ParseArguments(args):
63236336
_valid_extensions = set(val.split(','))
63246337
except ValueError:
63256338
PrintUsage('Extensions must be comma seperated list.')
6339+
elif opt == '--access_keywords_indent':
6340+
global _access_keyword_indent
6341+
try:
6342+
_access_keyword_indent = int(val)
6343+
except ValueError:
6344+
PrintUsage('Access keywords indent values should be an integer value only.')
63266345

63276346
if not filenames:
63286347
PrintUsage('No files were specified.')

0 commit comments

Comments
 (0)