Looks for redundant trailing semicolon. 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)
| 4930 | |
| 4931 | |
| 4932 | def CheckTrailingSemicolon(filename, clean_lines, linenum, error): |
| 4933 | """Looks for redundant trailing semicolon. |
| 4934 | |
| 4935 | Args: |
| 4936 | filename: The name of the current file. |
| 4937 | clean_lines: A CleansedLines instance containing the file. |
| 4938 | linenum: The number of the line to check. |
| 4939 | error: The function to call with any errors found. |
| 4940 | """ |
| 4941 | |
| 4942 | line = clean_lines.elided[linenum] |
| 4943 | |
| 4944 | # Block bodies should not be followed by a semicolon. Due to C++11 |
| 4945 | # brace initialization, there are more places where semicolons are |
| 4946 | # required than not, so we explicitly list the allowed rules rather |
| 4947 | # than listing the disallowed ones. These are the places where "};" |
| 4948 | # should be replaced by just "}": |
| 4949 | # 1. Some flavor of block following closing parenthesis: |
| 4950 | # for (;;) {}; |
| 4951 | # while (...) {}; |
| 4952 | # switch (...) {}; |
| 4953 | # Function(...) {}; |
| 4954 | # if (...) {}; |
| 4955 | # if (...) else if (...) {}; |
| 4956 | # |
| 4957 | # 2. else block: |
| 4958 | # if (...) else {}; |
| 4959 | # |
| 4960 | # 3. const member function: |
| 4961 | # Function(...) const {}; |
| 4962 | # |
| 4963 | # 4. Block following some statement: |
| 4964 | # x = 42; |
| 4965 | # {}; |
| 4966 | # |
| 4967 | # 5. Block at the beginning of a function: |
| 4968 | # Function(...) { |
| 4969 | # {}; |
| 4970 | # } |
| 4971 | # |
| 4972 | # Note that naively checking for the preceding "{" will also match |
| 4973 | # braces inside multi-dimensional arrays, but this is fine since |
| 4974 | # that expression will not contain semicolons. |
| 4975 | # |
| 4976 | # 6. Block following another block: |
| 4977 | # while (true) {} |
| 4978 | # {}; |
| 4979 | # |
| 4980 | # 7. End of namespaces: |
| 4981 | # namespace {}; |
| 4982 | # |
| 4983 | # These semicolons seems far more common than other kinds of |
| 4984 | # redundant semicolons, possibly due to people converting classes |
| 4985 | # to namespaces. For now we do not warn for this case. |
| 4986 | # |
| 4987 | # Try matching case 1 first. |
| 4988 | match = re.match(r"^(.*\)\s*)\{", line) |
| 4989 | if match: |
no test coverage detected