Check if line contains a redundant "override" or "final" virt-specifier. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. error: The function to call with any errors found.
(filename, clean_lines, linenum, error)
| 6253 | |
| 6254 | |
| 6255 | def CheckRedundantOverrideOrFinal(filename, clean_lines, linenum, error): |
| 6256 | """Check if line contains a redundant "override" or "final" virt-specifier. |
| 6257 | |
| 6258 | Args: |
| 6259 | filename: The name of the current file. |
| 6260 | clean_lines: A CleansedLines instance containing the file. |
| 6261 | linenum: The number of the line to check. |
| 6262 | error: The function to call with any errors found. |
| 6263 | """ |
| 6264 | # Look for closing parenthesis nearby. We need one to confirm where |
| 6265 | # the declarator ends and where the virt-specifier starts to avoid |
| 6266 | # false positives. |
| 6267 | line = clean_lines.elided[linenum] |
| 6268 | declarator_end = line.rfind(')') |
| 6269 | if declarator_end >= 0: |
| 6270 | fragment = line[declarator_end:] |
| 6271 | else: |
| 6272 | if linenum > 1 and clean_lines.elided[linenum - 1].rfind(')') >= 0: |
| 6273 | fragment = line |
| 6274 | else: |
| 6275 | return |
| 6276 | |
| 6277 | # Check that at most one of "override" or "final" is present, not both |
| 6278 | if Search(r'\boverride\b', fragment) and Search(r'\bfinal\b', fragment): |
| 6279 | error(filename, linenum, 'readability/inheritance', 4, |
| 6280 | ('"override" is redundant since function is ' |
| 6281 | 'already declared as "final"')) |
| 6282 | |
| 6283 | |
| 6284 |