Logs an error if we see /* ... */ or "..." that extend past one line. /* ... */ comments are legit inside macros, for one line. Otherwise, we prefer // comments, so it's ok to warn about the other. Likewise, it's ok for strings to extend across multiple lines, as long as a line continuatio
(filename, clean_lines, linenum, error)
| 2054 | |
| 2055 | |
| 2056 | def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error): |
| 2057 | """Logs an error if we see /* ... */ or "..." that extend past one line. |
| 2058 | |
| 2059 | /* ... */ comments are legit inside macros, for one line. |
| 2060 | Otherwise, we prefer // comments, so it's ok to warn about the |
| 2061 | other. Likewise, it's ok for strings to extend across multiple |
| 2062 | lines, as long as a line continuation character (backslash) |
| 2063 | terminates each line. Although not currently prohibited by the C++ |
| 2064 | style guide, it's ugly and unnecessary. We don't do well with either |
| 2065 | in this lint program, so we warn about both. |
| 2066 | |
| 2067 | Args: |
| 2068 | filename: The name of the current file. |
| 2069 | clean_lines: A CleansedLines instance containing the file. |
| 2070 | linenum: The number of the line to check. |
| 2071 | error: The function to call with any errors found. |
| 2072 | """ |
| 2073 | line = clean_lines.elided[linenum] |
| 2074 | |
| 2075 | # Remove all \\ (escaped backslashes) from the line. They are OK, and the |
| 2076 | # second (escaped) slash may trigger later \" detection erroneously. |
| 2077 | line = line.replace('\\\\', '') |
| 2078 | |
| 2079 | if line.count('/*') > line.count('*/'): |
| 2080 | error(filename, linenum, 'readability/multiline_comment', 5, |
| 2081 | 'Complex multi-line /*...*/-style comment found. ' |
| 2082 | 'Lint may give bogus warnings. ' |
| 2083 | 'Consider replacing these with //-style comments, ' |
| 2084 | 'with #if 0...#endif, ' |
| 2085 | 'or with more clearly structured multi-line comments.') |
| 2086 | |
| 2087 | if (line.count('"') - line.count('\\"')) % 2: |
| 2088 | error(filename, linenum, 'readability/multiline_string', 5, |
| 2089 | 'Multi-line string ("...") found. This lint script doesn\'t ' |
| 2090 | 'do well with such strings, and may give bogus warnings. ' |
| 2091 | 'Use C++11 raw strings or concatenation instead.') |
| 2092 | |
| 2093 | |
| 2094 | # (non-threadsafe name, thread-safe alternative, validation pattern) |
no test coverage detected