Checks for additional blank line issues related to sections. Currently the only thing checked here is blank line before protected/private. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. class_info: A _ClassInfo objects.
(filename, clean_lines, class_info, linenum, error)
| 4165 | return False |
| 4166 | |
| 4167 | def CheckSectionSpacing(filename, clean_lines, class_info, linenum, error): |
| 4168 | """Checks for additional blank line issues related to sections. |
| 4169 | |
| 4170 | Currently the only thing checked here is blank line before protected/private. |
| 4171 | |
| 4172 | Args: |
| 4173 | filename: The name of the current file. |
| 4174 | clean_lines: A CleansedLines instance containing the file. |
| 4175 | class_info: A _ClassInfo objects. |
| 4176 | linenum: The number of the line to check. |
| 4177 | error: The function to call with any errors found. |
| 4178 | """ |
| 4179 | # Skip checks if the class is small, where small means 25 lines or less. |
| 4180 | # 25 lines seems like a good cutoff since that's the usual height of |
| 4181 | # terminals, and any class that can't fit in one screen can't really |
| 4182 | # be considered "small". |
| 4183 | # |
| 4184 | # Also skip checks if we are on the first line. This accounts for |
| 4185 | # classes that look like |
| 4186 | # class Foo { public: ... }; |
| 4187 | # |
| 4188 | # If we didn't find the end of the class, last_line would be zero, |
| 4189 | # and the check will be skipped by the first condition. |
| 4190 | if (class_info.last_line - class_info.starting_linenum <= 24 or |
| 4191 | linenum <= class_info.starting_linenum): |
| 4192 | return |
| 4193 | |
| 4194 | matched = Match(r'\s*(public|protected|private):', clean_lines.lines[linenum]) |
| 4195 | if matched: |
| 4196 | # Issue warning if the line before public/protected/private was |
| 4197 | # not a blank line, but don't do this if the previous line contains |
| 4198 | # "class" or "struct". This can happen two ways: |
| 4199 | # - We are at the beginning of the class. |
| 4200 | # - We are forward-declaring an inner class that is semantically |
| 4201 | # private, but needed to be public for implementation reasons. |
| 4202 | # Also ignores cases where the previous line ends with a backslash as can be |
| 4203 | # common when defining classes in C macros. |
| 4204 | prev_line = clean_lines.lines[linenum - 1] |
| 4205 | if (not IsBlankLine(prev_line) and |
| 4206 | not Search(r'\b(class|struct)\b', prev_line) and |
| 4207 | not Search(r'\\$', prev_line)): |
| 4208 | # Try a bit harder to find the beginning of the class. This is to |
| 4209 | # account for multi-line base-specifier lists, e.g.: |
| 4210 | # class Derived |
| 4211 | # : public Base { |
| 4212 | end_class_head = class_info.starting_linenum |
| 4213 | for i in range(class_info.starting_linenum, linenum): |
| 4214 | if Search(r'\{\s*$', clean_lines.lines[i]): |
| 4215 | end_class_head = i |
| 4216 | break |
| 4217 | if end_class_head < linenum - 1: |
| 4218 | error(filename, linenum, 'whitespace/blank_line', 3, |
| 4219 | '"%s:" should be preceded by a blank line' % matched.group(1)) |
| 4220 | |
| 4221 | |
| 4222 | def GetPreviousNonBlankLine(clean_lines, linenum): |
no test coverage detected