This method determines if we should apply our namespace indentation check. Args: nesting_state: The current nesting state. is_namespace_indent_item: If we just put a new class on the stack, True. If the top of the stack is not a class, or we did not recently add the
(
nesting_state: NestingState, is_namespace_indent_item, raw_lines_no_comments, linenum
)
| 7348 | |
| 7349 | |
| 7350 | def ShouldCheckNamespaceIndentation( |
| 7351 | nesting_state: NestingState, is_namespace_indent_item, raw_lines_no_comments, linenum |
| 7352 | ): |
| 7353 | """This method determines if we should apply our namespace indentation check. |
| 7354 | |
| 7355 | Args: |
| 7356 | nesting_state: The current nesting state. |
| 7357 | is_namespace_indent_item: If we just put a new class on the stack, True. |
| 7358 | If the top of the stack is not a class, or we did not recently |
| 7359 | add the class, False. |
| 7360 | raw_lines_no_comments: The lines without the comments. |
| 7361 | linenum: The current line number we are processing. |
| 7362 | |
| 7363 | Returns: |
| 7364 | True if we should apply our namespace indentation check. Currently, it |
| 7365 | only works for classes and namespaces inside of a namespace. |
| 7366 | """ |
| 7367 | |
| 7368 | # Required by all checks involving nesting_state |
| 7369 | if not nesting_state.stack: |
| 7370 | return False |
| 7371 | |
| 7372 | is_forward_declaration = IsForwardClassDeclaration(raw_lines_no_comments, linenum) |
| 7373 | |
| 7374 | if not (is_namespace_indent_item or is_forward_declaration): |
| 7375 | return False |
| 7376 | |
| 7377 | # If we are in a macro, we do not want to check the namespace indentation. |
| 7378 | if IsMacroDefinition(raw_lines_no_comments, linenum): |
| 7379 | return False |
| 7380 | |
| 7381 | # Skip if we are inside an open parenthesis block (e.g. function parameters). |
| 7382 | if nesting_state.previous_stack_top and nesting_state.previous_open_parentheses > 0: |
| 7383 | return False |
| 7384 | |
| 7385 | # Skip if we are extra-indenting a member initializer list. |
| 7386 | if ( |
| 7387 | isinstance(nesting_state.previous_stack_top, _ConstructorInfo) # F/N (A::A() : _a(0) {/{}) |
| 7388 | and ( |
| 7389 | isinstance(nesting_state.stack[-1], _MemInitListInfo) |
| 7390 | or isinstance(nesting_state.popped_top, _MemInitListInfo) |
| 7391 | ) |
| 7392 | ) or ( # popping constructor after MemInitList on the same line (: _a(a) {}) |
| 7393 | isinstance(nesting_state.previous_stack_top, _ConstructorInfo) |
| 7394 | and isinstance(nesting_state.popped_top, _ConstructorInfo) |
| 7395 | and re.search(r"[^:]:[^:]", raw_lines_no_comments[linenum]) |
| 7396 | ): |
| 7397 | return False |
| 7398 | |
| 7399 | return IsBlockInNameSpace(nesting_state, is_forward_declaration) |
| 7400 | |
| 7401 | |
| 7402 | # Call this method if the line is directly inside of a namespace. |
no test coverage detected
searching dependent graphs…