|
502 | 502 | # This is set by --linelength flag. |
503 | 503 | _line_length = 80 |
504 | 504 |
|
| 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 | + |
505 | 511 | try: |
506 | 512 | xrange |
507 | 513 | except NameError: |
@@ -2223,7 +2229,8 @@ def __init__(self, stack_before_if): |
2223 | 2229 | class NestingState(object): |
2224 | 2230 | """Holds states related to parsing braces.""" |
2225 | 2231 |
|
2226 | | - def __init__(self): |
| 2232 | + def __init__(self, access_keyword_indent=1): |
| 2233 | + self.access_keyword_indent = access_keyword_indent |
2227 | 2234 | # Stack for tracking all braces. An object is pushed whenever we |
2228 | 2235 | # see a "{", and popped when we see a "}". Only 3 types of |
2229 | 2236 | # objects are possible: |
@@ -2508,8 +2515,8 @@ def Update(self, filename, clean_lines, linenum, error): |
2508 | 2515 | # Check that access keywords are indented +1 space. Skip this |
2509 | 2516 | # check if the keywords are not preceded by whitespaces. |
2510 | 2517 | 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))): |
2513 | 2520 | if classinfo.is_struct: |
2514 | 2521 | parent = 'struct ' + classinfo.name |
2515 | 2522 | else: |
@@ -6042,7 +6049,7 @@ def ProcessFileData(filename, file_extension, lines, error, |
6042 | 6049 |
|
6043 | 6050 | include_state = _IncludeState() |
6044 | 6051 | function_state = _FunctionState() |
6045 | | - nesting_state = NestingState() |
| 6052 | + nesting_state = NestingState(access_keyword_indent=_access_keyword_indent) |
6046 | 6053 |
|
6047 | 6054 | ResetNolintSuppressions() |
6048 | 6055 |
|
@@ -6131,6 +6138,12 @@ def ProcessConfigOverrides(filename): |
6131 | 6138 | _line_length = int(val) |
6132 | 6139 | except ValueError: |
6133 | 6140 | 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.') |
6134 | 6147 | else: |
6135 | 6148 | sys.stderr.write( |
6136 | 6149 | 'Invalid configuration option (%s) in file %s\n' % |
@@ -6318,6 +6331,12 @@ def ParseArguments(args): |
6318 | 6331 | _valid_extensions = set(val.split(',')) |
6319 | 6332 | except ValueError: |
6320 | 6333 | 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.') |
6321 | 6340 |
|
6322 | 6341 | if not filenames: |
6323 | 6342 | PrintUsage('No files were specified.') |
|
0 commit comments