MCPcopy Create free account
hub / github.com/alibaba/libgrape-lite / CheckForMultilineCommentsAndStrings

Function CheckForMultilineCommentsAndStrings

misc/cpplint.py:2542–2577  ·  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 continuatio

(filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

2540
2541
2542def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error):
2543 """Logs an error if we see /* ... */ or "..." that extend past one line.
2544
2545 /* ... */ comments are legit inside macros, for one line.
2546 Otherwise, we prefer // comments, so it's ok to warn about the
2547 other. Likewise, it's ok for strings to extend across multiple
2548 lines, as long as a line continuation character (backslash)
2549 terminates each line. Although not currently prohibited by the C++
2550 style guide, it's ugly and unnecessary. We don't do well with either
2551 in this lint program, so we warn about both.
2552
2553 Args:
2554 filename: The name of the current file.
2555 clean_lines: A CleansedLines instance containing the file.
2556 linenum: The number of the line to check.
2557 error: The function to call with any errors found.
2558 """
2559 line = clean_lines.elided[linenum]
2560
2561 # Remove all \\ (escaped backslashes) from the line. They are OK, and the
2562 # second (escaped) slash may trigger later \" detection erroneously.
2563 line = line.replace('\\\\', '')
2564
2565 if line.count('/*') > line.count('*/'):
2566 error(filename, linenum, 'readability/multiline_comment', 5,
2567 'Complex multi-line /*...*/-style comment found. '
2568 'Lint may give bogus warnings. '
2569 'Consider replacing these with //-style comments, '
2570 'with #if 0...#endif, '
2571 'or with more clearly structured multi-line comments.')
2572
2573 if (line.count('"') - line.count('\\"')) % 2:
2574 error(filename, linenum, 'readability/multiline_string', 5,
2575 'Multi-line string ("...") found. This lint script doesn\'t '
2576 'do well with such strings, and may give bogus warnings. '
2577 'Use C++11 raw strings or concatenation instead.')
2578
2579
2580# (non-threadsafe name, thread-safe alternative, validation pattern)

Callers 1

ProcessLineFunction · 0.85

Calls 1

countMethod · 0.80

Tested by

no test coverage detected