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

Access keyword indent #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,12 @@
# This is set by --linelength flag.
_line_length = 80

# The allowed indent for access keywords.
# Set by default to +1, it can be changed with the
# --access_keywords_indent (and correspondingly, in the CPPLINT.cfg
# file too).
_access_keyword_indent = 1

try:
xrange
except NameError:
Expand Down Expand Up @@ -2224,7 +2230,8 @@ def __init__(self, stack_before_if):
class NestingState(object):
"""Holds states related to parsing braces."""

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

include_state = _IncludeState()
function_state = _FunctionState()
nesting_state = NestingState()
nesting_state = NestingState(access_keyword_indent=_access_keyword_indent)

ResetNolintSuppressions()

Expand Down Expand Up @@ -6136,6 +6143,12 @@ def ProcessConfigOverrides(filename):
_line_length = int(val)
except ValueError:
sys.stderr.write('Line length must be numeric.')
elif name == 'access_keywords_indent':
global _access_keyword_indent
try:
_access_keyword_indent = int(val)
except ValueError:
sys.stderr.write('Access keyword indent must be numeric.')
else:
sys.stderr.write(
'Invalid configuration option (%s) in file %s\n' %
Expand Down Expand Up @@ -6323,6 +6336,12 @@ def ParseArguments(args):
_valid_extensions = set(val.split(','))
except ValueError:
PrintUsage('Extensions must be comma seperated list.')
elif opt == '--access_keywords_indent':
global _access_keyword_indent
try:
_access_keyword_indent = int(val)
except ValueError:
PrintUsage('Access keywords indent values should be an integer value only.')

if not filenames:
PrintUsage('No files were specified.')
Expand Down