@@ 6201-6286 (lines=86) @@ | ||
6198 | return True |
|
6199 | ||
6200 | ||
6201 | def ProcessFile(filename, vlevel, extra_check_functions=None): |
|
6202 | """Does google-lint on a single file. |
|
6203 | ||
6204 | Args: |
|
6205 | filename: The name of the file to parse. |
|
6206 | ||
6207 | vlevel: The level of errors to report. Every error of confidence |
|
6208 | >= verbose_level will be reported. 0 is a good default. |
|
6209 | ||
6210 | extra_check_functions: An array of additional check functions that will be |
|
6211 | run on each source line. Each function takes 4 |
|
6212 | arguments: filename, clean_lines, line, error |
|
6213 | """ |
|
6214 | ||
6215 | _SetVerboseLevel(vlevel) |
|
6216 | _BackupFilters() |
|
6217 | ||
6218 | if not ProcessConfigOverrides(filename): |
|
6219 | _RestoreFilters() |
|
6220 | return |
|
6221 | ||
6222 | lf_lines = [] |
|
6223 | crlf_lines = [] |
|
6224 | try: |
|
6225 | # Support the UNIX convention of using "-" for stdin. Note that |
|
6226 | # we are not opening the file with universal newline support |
|
6227 | # (which codecs doesn't support anyway), so the resulting lines do |
|
6228 | # contain trailing '\r' characters if we are reading a file that |
|
6229 | # has CRLF endings. |
|
6230 | # If after the split a trailing '\r' is present, it is removed |
|
6231 | # below. |
|
6232 | if filename == '-': |
|
6233 | lines = codecs.StreamReaderWriter(sys.stdin, |
|
6234 | codecs.getreader('utf8'), |
|
6235 | codecs.getwriter('utf8'), |
|
6236 | 'replace').read().split('\n') |
|
6237 | else: |
|
6238 | lines = codecs.open(filename, 'r', 'utf8', 'replace').read().split('\n') |
|
6239 | ||
6240 | # Remove trailing '\r'. |
|
6241 | # The -1 accounts for the extra trailing blank line we get from split() |
|
6242 | for linenum in range(len(lines) - 1): |
|
6243 | if lines[linenum].endswith('\r'): |
|
6244 | lines[linenum] = lines[linenum].rstrip('\r') |
|
6245 | crlf_lines.append(linenum + 1) |
|
6246 | else: |
|
6247 | lf_lines.append(linenum + 1) |
|
6248 | ||
6249 | except IOError: |
|
6250 | _cpplint_state.PrintError( |
|
6251 | "Skipping input '%s': Can't open for reading\n" % filename) |
|
6252 | _RestoreFilters() |
|
6253 | return |
|
6254 | ||
6255 | # Note, if no dot is found, this will give the entire filename as the ext. |
|
6256 | file_extension = filename[filename.rfind('.') + 1:] |
|
6257 | ||
6258 | # When reading from stdin, the extension is unknown, so no cpplint tests |
|
6259 | # should rely on the extension. |
|
6260 | if filename != '-' and file_extension not in GetAllExtensions(): |
|
6261 | _cpplint_state.PrintError('Ignoring %s; not a valid file name ' |
|
6262 | '(%s)\n' % (filename, ', '.join(GetAllExtensions()))) |
|
6263 | else: |
|
6264 | ProcessFileData(filename, file_extension, lines, Error, |
|
6265 | extra_check_functions) |
|
6266 | ||
6267 | # If end-of-line sequences are a mix of LF and CR-LF, issue |
|
6268 | # warnings on the lines with CR. |
|
6269 | # |
|
6270 | # Don't issue any warnings if all lines are uniformly LF or CR-LF, |
|
6271 | # since critique can handle these just fine, and the style guide |
|
6272 | # doesn't dictate a particular end of line sequence. |
|
6273 | # |
|
6274 | # We can't depend on os.linesep to determine what the desired |
|
6275 | # end-of-line sequence should be, since that will return the |
|
6276 | # server-side end-of-line sequence. |
|
6277 | if lf_lines and crlf_lines: |
|
6278 | # Warn on every line with CR. An alternative approach might be to |
|
6279 | # check whether the file is mostly CRLF or just LF, and warn on the |
|
6280 | # minority, we bias toward LF here since most tools prefer LF. |
|
6281 | for linenum in crlf_lines: |
|
6282 | Error(filename, linenum, 'whitespace/newline', 1, |
|
6283 | 'Unexpected \\r (^M) found; better to use only \\n') |
|
6284 | ||
6285 | _cpplint_state.PrintInfo('Done processing %s\n' % filename) |
|
6286 | _RestoreFilters() |
|
6287 | ||
6288 | ||
6289 | def PrintUsage(message): |
@@ 6201-6286 (lines=86) @@ | ||
6198 | return True |
|
6199 | ||
6200 | ||
6201 | def ProcessFile(filename, vlevel, extra_check_functions=None): |
|
6202 | """Does google-lint on a single file. |
|
6203 | ||
6204 | Args: |
|
6205 | filename: The name of the file to parse. |
|
6206 | ||
6207 | vlevel: The level of errors to report. Every error of confidence |
|
6208 | >= verbose_level will be reported. 0 is a good default. |
|
6209 | ||
6210 | extra_check_functions: An array of additional check functions that will be |
|
6211 | run on each source line. Each function takes 4 |
|
6212 | arguments: filename, clean_lines, line, error |
|
6213 | """ |
|
6214 | ||
6215 | _SetVerboseLevel(vlevel) |
|
6216 | _BackupFilters() |
|
6217 | ||
6218 | if not ProcessConfigOverrides(filename): |
|
6219 | _RestoreFilters() |
|
6220 | return |
|
6221 | ||
6222 | lf_lines = [] |
|
6223 | crlf_lines = [] |
|
6224 | try: |
|
6225 | # Support the UNIX convention of using "-" for stdin. Note that |
|
6226 | # we are not opening the file with universal newline support |
|
6227 | # (which codecs doesn't support anyway), so the resulting lines do |
|
6228 | # contain trailing '\r' characters if we are reading a file that |
|
6229 | # has CRLF endings. |
|
6230 | # If after the split a trailing '\r' is present, it is removed |
|
6231 | # below. |
|
6232 | if filename == '-': |
|
6233 | lines = codecs.StreamReaderWriter(sys.stdin, |
|
6234 | codecs.getreader('utf8'), |
|
6235 | codecs.getwriter('utf8'), |
|
6236 | 'replace').read().split('\n') |
|
6237 | else: |
|
6238 | lines = codecs.open(filename, 'r', 'utf8', 'replace').read().split('\n') |
|
6239 | ||
6240 | # Remove trailing '\r'. |
|
6241 | # The -1 accounts for the extra trailing blank line we get from split() |
|
6242 | for linenum in range(len(lines) - 1): |
|
6243 | if lines[linenum].endswith('\r'): |
|
6244 | lines[linenum] = lines[linenum].rstrip('\r') |
|
6245 | crlf_lines.append(linenum + 1) |
|
6246 | else: |
|
6247 | lf_lines.append(linenum + 1) |
|
6248 | ||
6249 | except IOError: |
|
6250 | _cpplint_state.PrintError( |
|
6251 | "Skipping input '%s': Can't open for reading\n" % filename) |
|
6252 | _RestoreFilters() |
|
6253 | return |
|
6254 | ||
6255 | # Note, if no dot is found, this will give the entire filename as the ext. |
|
6256 | file_extension = filename[filename.rfind('.') + 1:] |
|
6257 | ||
6258 | # When reading from stdin, the extension is unknown, so no cpplint tests |
|
6259 | # should rely on the extension. |
|
6260 | if filename != '-' and file_extension not in GetAllExtensions(): |
|
6261 | _cpplint_state.PrintError('Ignoring %s; not a valid file name ' |
|
6262 | '(%s)\n' % (filename, ', '.join(GetAllExtensions()))) |
|
6263 | else: |
|
6264 | ProcessFileData(filename, file_extension, lines, Error, |
|
6265 | extra_check_functions) |
|
6266 | ||
6267 | # If end-of-line sequences are a mix of LF and CR-LF, issue |
|
6268 | # warnings on the lines with CR. |
|
6269 | # |
|
6270 | # Don't issue any warnings if all lines are uniformly LF or CR-LF, |
|
6271 | # since critique can handle these just fine, and the style guide |
|
6272 | # doesn't dictate a particular end of line sequence. |
|
6273 | # |
|
6274 | # We can't depend on os.linesep to determine what the desired |
|
6275 | # end-of-line sequence should be, since that will return the |
|
6276 | # server-side end-of-line sequence. |
|
6277 | if lf_lines and crlf_lines: |
|
6278 | # Warn on every line with CR. An alternative approach might be to |
|
6279 | # check whether the file is mostly CRLF or just LF, and warn on the |
|
6280 | # minority, we bias toward LF here since most tools prefer LF. |
|
6281 | for linenum in crlf_lines: |
|
6282 | Error(filename, linenum, 'whitespace/newline', 1, |
|
6283 | 'Unexpected \\r (^M) found; better to use only \\n') |
|
6284 | ||
6285 | _cpplint_state.PrintInfo('Done processing %s\n' % filename) |
|
6286 | _RestoreFilters() |
|
6287 | ||
6288 | ||
6289 | def PrintUsage(message): |