|
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: |
@@ -2224,7 +2230,8 @@ def __init__(self, stack_before_if): |
2224 | 2230 | class NestingState(object): |
2225 | 2231 | """Holds states related to parsing braces.""" |
2226 | 2232 |
|
2227 | | - def __init__(self): |
| 2233 | + def __init__(self, access_keyword_indent=1): |
| 2234 | + self.access_keyword_indent = access_keyword_indent |
2228 | 2235 | # Stack for tracking all braces. An object is pushed whenever we |
2229 | 2236 | # see a "{", and popped when we see a "}". Only 3 types of |
2230 | 2237 | # objects are possible: |
@@ -2509,8 +2516,8 @@ def Update(self, filename, clean_lines, linenum, error): |
2509 | 2516 | # Check that access keywords are indented +1 space. Skip this |
2510 | 2517 | # check if the keywords are not preceded by whitespaces. |
2511 | 2518 | 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))): |
2514 | 2521 | if classinfo.is_struct: |
2515 | 2522 | parent = 'struct ' + classinfo.name |
2516 | 2523 | else: |
@@ -6047,7 +6054,7 @@ def ProcessFileData(filename, file_extension, lines, error, |
6047 | 6054 |
|
6048 | 6055 | include_state = _IncludeState() |
6049 | 6056 | function_state = _FunctionState() |
6050 | | - nesting_state = NestingState() |
| 6057 | + nesting_state = NestingState(access_keyword_indent=_access_keyword_indent) |
6051 | 6058 |
|
6052 | 6059 | ResetNolintSuppressions() |
6053 | 6060 |
|
@@ -6136,6 +6143,12 @@ def ProcessConfigOverrides(filename): |
6136 | 6143 | _line_length = int(val) |
6137 | 6144 | except ValueError: |
6138 | 6145 | 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.') |
6139 | 6152 | else: |
6140 | 6153 | sys.stderr.write( |
6141 | 6154 | 'Invalid configuration option (%s) in file %s\n' % |
@@ -6323,6 +6336,12 @@ def ParseArguments(args): |
6323 | 6336 | _valid_extensions = set(val.split(',')) |
6324 | 6337 | except ValueError: |
6325 | 6338 | 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.') |
6326 | 6345 |
|
6327 | 6346 | if not filenames: |
6328 | 6347 | PrintUsage('No files were specified.') |
|
0 commit comments