MCPcopy Index your code
hub / github.com/nodejs/node / CheckForMultilineCommentsAndStrings

Function CheckForMultilineCommentsAndStrings

tools/cpplint.py:2845–2890  ·  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

2843
2844
2845def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error):
2846 """Logs an error if we see /* ... */ or "..." that extend past one line.
2847
2848 /* ... */ comments are legit inside macros, for one line.
2849 Otherwise, we prefer // comments, so it's ok to warn about the
2850 other. Likewise, it's ok for strings to extend across multiple
2851 lines, as long as a line continuation character (backslash)
2852 terminates each line. Although not currently prohibited by the C++
2853 style guide, it's ugly and unnecessary. We don't do well with either
2854 in this lint program, so we warn about both.
2855
2856 Args:
2857 filename: The name of the current file.
2858 clean_lines: A CleansedLines instance containing the file.
2859 linenum: The number of the line to check.
2860 error: The function to call with any errors found.
2861 """
2862 line = clean_lines.elided[linenum]
2863
2864 # Remove all \\ (escaped backslashes) from the line. They are OK, and the
2865 # second (escaped) slash may trigger later \" detection erroneously.
2866 line = line.replace("\\\\", "")
2867
2868 if line.count("/*") > line.count("*/"):
2869 error(
2870 filename,
2871 linenum,
2872 "readability/multiline_comment",
2873 5,
2874 "Complex multi-line /*...*/-style comment found. "
2875 "Lint may give bogus warnings. "
2876 "Consider replacing these with //-style comments, "
2877 "with #if 0...#endif, "
2878 "or with more clearly structured multi-line comments.",
2879 )
2880
2881 if (line.count('"') - line.count('\\"')) % 2:
2882 error(
2883 filename,
2884 linenum,
2885 "readability/multiline_string",
2886 5,
2887 'Multi-line string ("...") found. This lint script doesn\'t '
2888 "do well with such strings, and may give bogus warnings. "
2889 "Use C++11 raw strings or concatenation instead.",
2890 )
2891
2892
2893# (non-threadsafe name, thread-safe alternative, validation pattern)

Callers 1

ProcessLineFunction · 0.85

Calls 2

errorFunction · 0.50
countMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…