MCPcopy Index your code
hub / github.com/cpplint/cpplint / ShouldCheckNamespaceIndentation

Function ShouldCheckNamespaceIndentation

cpplint.py:7206–7255  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

7204
7205
7206def ShouldCheckNamespaceIndentation(
7207 nesting_state: NestingState, is_namespace_indent_item, raw_lines_no_comments, linenum
7208):
7209 """This method determines if we should apply our namespace indentation check.
7210
7211 Args:
7212 nesting_state: The current nesting state.
7213 is_namespace_indent_item: If we just put a new class on the stack, True.
7214 If the top of the stack is not a class, or we did not recently
7215 add the class, False.
7216 raw_lines_no_comments: The lines without the comments.
7217 linenum: The current line number we are processing.
7218
7219 Returns:
7220 True if we should apply our namespace indentation check. Currently, it
7221 only works for classes and namespaces inside of a namespace.
7222 """
7223
7224 # Required by all checks involving nesting_state
7225 if not nesting_state.stack:
7226 return False
7227
7228 is_forward_declaration = IsForwardClassDeclaration(raw_lines_no_comments, linenum)
7229
7230 if not (is_namespace_indent_item or is_forward_declaration):
7231 return False
7232
7233 # If we are in a macro, we do not want to check the namespace indentation.
7234 if IsMacroDefinition(raw_lines_no_comments, linenum):
7235 return False
7236
7237 # Skip if we are inside an open parenthesis block (e.g. function parameters).
7238 if nesting_state.previous_stack_top and nesting_state.previous_open_parentheses > 0:
7239 return False
7240
7241 # Skip if we are extra-indenting a member initializer list.
7242 if (
7243 isinstance(nesting_state.previous_stack_top, _ConstructorInfo) # F/N (A::A() : _a(0) {/{})
7244 and (
7245 isinstance(nesting_state.stack[-1], _MemInitListInfo)
7246 or isinstance(nesting_state.popped_top, _MemInitListInfo)
7247 )
7248 ) or ( # popping constructor after MemInitList on the same line (: _a(a) {})
7249 isinstance(nesting_state.previous_stack_top, _ConstructorInfo)
7250 and isinstance(nesting_state.popped_top, _ConstructorInfo)
7251 and re.search(r"[^:]:[^:]", raw_lines_no_comments[linenum])
7252 ):
7253 return False
7254
7255 return IsBlockInNameSpace(nesting_state, is_forward_declaration)
7256
7257
7258# Call this method if the line is directly inside of a namespace.

Callers 1

Calls 3

IsMacroDefinitionFunction · 0.85
IsBlockInNameSpaceFunction · 0.85

Tested by

no test coverage detected