Logs an error for each line containing bad characters. Two kinds of bad characters: 1. Unicode replacement characters: These indicate that either the file contained invalid UTF-8 (likely) or Unicode replacement characters (which it shouldn't). Note that it's possible for this to throw off
(filename, lines, error)
| 2511 | |
| 2512 | |
| 2513 | def CheckForBadCharacters(filename, lines, error): |
| 2514 | """Logs an error for each line containing bad characters. |
| 2515 | |
| 2516 | Two kinds of bad characters: |
| 2517 | |
| 2518 | 1. Unicode replacement characters: These indicate that either the file |
| 2519 | contained invalid UTF-8 (likely) or Unicode replacement characters (which |
| 2520 | it shouldn't). Note that it's possible for this to throw off line |
| 2521 | numbering if the invalid UTF-8 occurred adjacent to a newline. |
| 2522 | |
| 2523 | 2. NUL bytes. These are problematic for some tools. |
| 2524 | |
| 2525 | Args: |
| 2526 | filename: The name of the current file. |
| 2527 | lines: An array of strings, each representing a line of the file. |
| 2528 | error: The function to call with any errors found. |
| 2529 | """ |
| 2530 | for linenum, line in enumerate(lines): |
| 2531 | if unicode_escape_decode('\ufffd') in line: |
| 2532 | error(filename, linenum, 'readability/utf8', 5, |
| 2533 | 'Line contains invalid UTF-8 (or Unicode replacement character).') |
| 2534 | if '\0' in line: |
| 2535 | error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.') |
| 2536 | |
| 2537 | |
| 2538 | def CheckForNewlineAtEOF(filename, lines, error): |
no test coverage detected