|
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 | if sys.version_info < (3,): |
506 | 512 | def u(x): |
507 | 513 | return codecs.unicode_escape_decode(x)[0] |
@@ -2217,7 +2223,8 @@ def __init__(self, stack_before_if): |
2217 | 2223 | class NestingState(object): |
2218 | 2224 | """Holds states related to parsing braces.""" |
2219 | 2225 |
|
2220 | | - def __init__(self): |
| 2226 | + def __init__(self, access_keyword_indent=1): |
| 2227 | + self.access_keyword_indent = access_keyword_indent |
2221 | 2228 | # Stack for tracking all braces. An object is pushed whenever we |
2222 | 2229 | # see a "{", and popped when we see a "}". Only 3 types of |
2223 | 2230 | # objects are possible: |
@@ -2502,8 +2509,8 @@ def Update(self, filename, clean_lines, linenum, error): |
2502 | 2509 | # Check that access keywords are indented +1 space. Skip this |
2503 | 2510 | # check if the keywords are not preceded by whitespaces. |
2504 | 2511 | 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))): |
2507 | 2514 | if classinfo.is_struct: |
2508 | 2515 | parent = 'struct ' + classinfo.name |
2509 | 2516 | else: |
@@ -6039,7 +6046,7 @@ def ProcessFileData(filename, file_extension, lines, error, |
6039 | 6046 |
|
6040 | 6047 | include_state = _IncludeState() |
6041 | 6048 | function_state = _FunctionState() |
6042 | | - nesting_state = NestingState() |
| 6049 | + nesting_state = NestingState(access_keyword_indent=_access_keyword_indent) |
6043 | 6050 |
|
6044 | 6051 | ResetNolintSuppressions() |
6045 | 6052 |
|
@@ -6128,6 +6135,12 @@ def ProcessConfigOverrides(filename): |
6128 | 6135 | _line_length = int(val) |
6129 | 6136 | except ValueError: |
6130 | 6137 | 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.') |
6131 | 6144 | else: |
6132 | 6145 | sys.stderr.write( |
6133 | 6146 | 'Invalid configuration option (%s) in file %s\n' % |
@@ -6315,6 +6328,12 @@ def ParseArguments(args): |
6315 | 6328 | _valid_extensions = set(val.split(',')) |
6316 | 6329 | except ValueError: |
6317 | 6330 | 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.') |
6318 | 6337 |
|
6319 | 6338 | if not filenames: |
6320 | 6339 | PrintUsage('No files were specified.') |
|
0 commit comments