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

Commit fed5985

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 dcf8a87 commit fed5985

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

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
if sys.version_info < (3,):
506512
def u(x):
507513
return codecs.unicode_escape_decode(x)[0]
@@ -2217,7 +2223,8 @@ def __init__(self, stack_before_if):
22172223
class NestingState(object):
22182224
"""Holds states related to parsing braces."""
22192225

2220-
def __init__(self):
2226+
def __init__(self, access_keyword_indent=1):
2227+
self.access_keyword_indent = access_keyword_indent
22212228
# Stack for tracking all braces. An object is pushed whenever we
22222229
# see a "{", and popped when we see a "}". Only 3 types of
22232230
# objects are possible:
@@ -2502,8 +2509,8 @@ def Update(self, filename, clean_lines, linenum, error):
25022509
# Check that access keywords are indented +1 space. Skip this
25032510
# check if the keywords are not preceded by whitespaces.
25042511
indent = access_match.group(1)
2505-
if (len(indent) != classinfo.class_indent + 1 and
2506-
Match(r'^\s*$', indent)):
2512+
if (len(indent) != classinfo.class_indent + self.access_keyword_indent and
2513+
(self.access_keyword_indent == 0 or Match(r'^\s*$', indent))):
25072514
if classinfo.is_struct:
25082515
parent = 'struct ' + classinfo.name
25092516
else:
@@ -6039,7 +6046,7 @@ def ProcessFileData(filename, file_extension, lines, error,
60396046

60406047
include_state = _IncludeState()
60416048
function_state = _FunctionState()
6042-
nesting_state = NestingState()
6049+
nesting_state = NestingState(access_keyword_indent=_access_keyword_indent)
60436050

60446051
ResetNolintSuppressions()
60456052

@@ -6128,6 +6135,12 @@ def ProcessConfigOverrides(filename):
61286135
_line_length = int(val)
61296136
except ValueError:
61306137
sys.stderr.write('Line length must be numeric.')
6138+
elif name == 'access_keywords_indent':
6139+
global _access_keyword_indent
6140+
try:
6141+
_access_keyword_indent = int(val)
6142+
except ValueError:
6143+
sys.stderr.write('Access keyword indent must be numeric.')
61316144
else:
61326145
sys.stderr.write(
61336146
'Invalid configuration option (%s) in file %s\n' %
@@ -6315,6 +6328,12 @@ def ParseArguments(args):
63156328
_valid_extensions = set(val.split(','))
63166329
except ValueError:
63176330
PrintUsage('Extensions must be comma seperated list.')
6331+
elif opt == '--access_keywords_indent':
6332+
global _access_keyword_indent
6333+
try:
6334+
_access_keyword_indent = int(val)
6335+
except ValueError:
6336+
PrintUsage('Access keywords indent values should be an integer value only.')
63186337

63196338
if not filenames:
63206339
PrintUsage('No files were specified.')

0 commit comments

Comments
 (0)