MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / CheckForMultilineCommentsAndStrings

Function CheckForMultilineCommentsAndStrings

steps/cpplint.py:2556–2591  ·  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

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

Callers 1

ProcessLineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected