MCPcopy Create free account
hub / github.com/tensorflow/tfjs / CheckForMultilineCommentsAndStrings

Function CheckForMultilineCommentsAndStrings

tfjs-backend-wasm/tools/cpplint.py:2051–2086  ·  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

2049
2050
2051def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error):
2052 """Logs an error if we see /* ... */ or "..." that extend past one line.
2053
2054 /* ... */ comments are legit inside macros, for one line.
2055 Otherwise, we prefer // comments, so it's ok to warn about the
2056 other. Likewise, it's ok for strings to extend across multiple
2057 lines, as long as a line continuation character (backslash)
2058 terminates each line. Although not currently prohibited by the C++
2059 style guide, it's ugly and unnecessary. We don't do well with either
2060 in this lint program, so we warn about both.
2061
2062 Args:
2063 filename: The name of the current file.
2064 clean_lines: A CleansedLines instance containing the file.
2065 linenum: The number of the line to check.
2066 error: The function to call with any errors found.
2067 """
2068 line = clean_lines.elided[linenum]
2069
2070 # Remove all \\ (escaped backslashes) from the line. They are OK, and the
2071 # second (escaped) slash may trigger later \" detection erroneously.
2072 line = line.replace('\\\\', '')
2073
2074 if line.count('/*') > line.count('*/'):
2075 error(filename, linenum, 'readability/multiline_comment', 5,
2076 'Complex multi-line /*...*/-style comment found. '
2077 'Lint may give bogus warnings. '
2078 'Consider replacing these with //-style comments, '
2079 'with #if 0...#endif, '
2080 'or with more clearly structured multi-line comments.')
2081
2082 if (line.count('"') - line.count('\\"')) % 2:
2083 error(filename, linenum, 'readability/multiline_string', 5,
2084 'Multi-line string ("...") found. This lint script doesn\'t '
2085 'do well with such strings, and may give bogus warnings. '
2086 'Use C++11 raw strings or concatenation instead.')
2087
2088
2089# (non-threadsafe name, thread-safe alternative, validation pattern)

Callers 1

ProcessLineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…