MCPcopy Index your code
hub / github.com/cpplint/cpplint / CheckForMultilineCommentsAndStrings

Function CheckForMultilineCommentsAndStrings

cpplint.py:2785–2830  ·  view source on GitHub ↗

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 con

(filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

2783
2784
2785def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error):
2786 """Logs an error if we see /* ... */ or "..." that extend past one line.
2787
2788 /* ... */ comments are legit inside macros, for one line.
2789 Otherwise, we prefer // comments, so it's ok to warn about the
2790 other. Likewise, it's ok for strings to extend across multiple
2791 lines, as long as a line continuation character (backslash)
2792 terminates each line. Although not currently prohibited by the C++
2793 style guide, it's ugly and unnecessary. We don't do well with either
2794 in this lint program, so we warn about both.
2795
2796 Args:
2797 filename: The name of the current file.
2798 clean_lines: A CleansedLines instance containing the file.
2799 linenum: The number of the line to check.
2800 error: The function to call with any errors found.
2801 """
2802 line = clean_lines.elided[linenum]
2803
2804 # Remove all \\ (escaped backslashes) from the line. They are OK, and the
2805 # second (escaped) slash may trigger later \" detection erroneously.
2806 line = line.replace("\\\\", "")
2807
2808 if line.count("/*") > line.count("*/"):
2809 error(
2810 filename,
2811 linenum,
2812 "readability/multiline_comment",
2813 5,
2814 "Complex multi-line /*...*/-style comment found. "
2815 "Lint may give bogus warnings. "
2816 "Consider replacing these with //-style comments, "
2817 "with #if 0...#endif, "
2818 "or with more clearly structured multi-line comments.",
2819 )
2820
2821 if (line.count('"') - line.count('\\"')) % 2:
2822 error(
2823 filename,
2824 linenum,
2825 "readability/multiline_string",
2826 5,
2827 'Multi-line string ("...") found. This lint script doesn\'t '
2828 "do well with such strings, and may give bogus warnings. "
2829 "Use C++11 raw strings or concatenation instead.",
2830 )
2831
2832
2833# (non-threadsafe name, thread-safe alternative, validation pattern)

Callers 1

ProcessLineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected