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)
| 1481 | |
| 1482 | |
| 1483 | def CheckForBadCharacters(filename, lines, error): |
| 1484 | """Logs an error for each line containing bad characters. |
| 1485 | |
| 1486 | Two kinds of bad characters: |
| 1487 | |
| 1488 | 1. Unicode replacement characters: These indicate that either the file |
| 1489 | contained invalid UTF-8 (likely) or Unicode replacement characters (which |
| 1490 | it shouldn't). Note that it's possible for this to throw off line |
| 1491 | numbering if the invalid UTF-8 occurred adjacent to a newline. |
| 1492 | |
| 1493 | 2. NUL bytes. These are problematic for some tools. |
| 1494 | |
| 1495 | Args: |
| 1496 | filename: The name of the current file. |
| 1497 | lines: An array of strings, each representing a line of the file. |
| 1498 | error: The function to call with any errors found. |
| 1499 | """ |
| 1500 | for linenum, line in enumerate(lines): |
| 1501 | if u'\ufffd' in line: |
| 1502 | error(filename, linenum, 'readability/utf8', 5, |
| 1503 | 'Line contains invalid UTF-8 (or Unicode replacement character).') |
| 1504 | if '\0' in line: |
| 1505 | error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.') |
| 1506 | |
| 1507 | |
| 1508 | def CheckForNewlineAtEOF(filename, lines, error): |
no test coverage detected