MCPcopy Create free account
hub / github.com/alibaba/GraphScope / CheckForMultilineCommentsAndStrings

Function CheckForMultilineCommentsAndStrings

analytical_engine/misc/cpplint.py:2545–2580  ·  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

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

Callers 1

ProcessLineFunction · 0.85

Calls 1

countMethod · 0.65

Tested by

no test coverage detected