MCPcopy Create free account
hub / github.com/apache/mesos / CheckTrailingSemicolon

Function CheckTrailingSemicolon

support/cpplint.py:3855–3999  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

3853
3854
3855def CheckTrailingSemicolon(filename, clean_lines, linenum, error):
3856 """Looks for redundant trailing semicolon.
3857
3858 Args:
3859 filename: The name of the current file.
3860 clean_lines: A CleansedLines instance containing the file.
3861 linenum: The number of the line to check.
3862 error: The function to call with any errors found.
3863 """
3864
3865 line = clean_lines.elided[linenum]
3866
3867 # Block bodies should not be followed by a semicolon. Due to C++11
3868 # brace initialization, there are more places where semicolons are
3869 # required than not, so we use a whitelist approach to check these
3870 # rather than a blacklist. These are the places where "};" should
3871 # be replaced by just "}":
3872 # 1. Some flavor of block following closing parenthesis:
3873 # for (;;) {};
3874 # while (...) {};
3875 # switch (...) {};
3876 # Function(...) {};
3877 # if (...) {};
3878 # if (...) else if (...) {};
3879 #
3880 # 2. else block:
3881 # if (...) else {};
3882 #
3883 # 3. const member function:
3884 # Function(...) const {};
3885 #
3886 # 4. Block following some statement:
3887 # x = 42;
3888 # {};
3889 #
3890 # 5. Block at the beginning of a function:
3891 # Function(...) {
3892 # {};
3893 # }
3894 #
3895 # Note that naively checking for the preceding "{" will also match
3896 # braces inside multi-dimensional arrays, but this is fine since
3897 # that expression will not contain semicolons.
3898 #
3899 # 6. Block following another block:
3900 # while (true) {}
3901 # {};
3902 #
3903 # 7. End of namespaces:
3904 # namespace {};
3905 #
3906 # These semicolons seems far more common than other kinds of
3907 # redundant semicolons, possibly due to people converting classes
3908 # to namespaces. For now we do not warn for this case.
3909 #
3910 # Try matching case 1 first.
3911 match = Match(r'^(.*\)\s*)\{', line)
3912 if match:

Callers 1

CheckStyleFunction · 0.85

Calls 7

MatchFunction · 0.85
ReverseCloseExpressionFunction · 0.85
SearchFunction · 0.85
GetPreviousNonBlankLineFunction · 0.85
CloseExpressionFunction · 0.85
ParseNolintSuppressionsFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected