Logs an error if there is no newline char at the end of the file. Args: filename: The name of the current file. lines: An array of strings, each representing a line of the file. error: The function to call with any errors found.
(filename, lines, error)
| 1510 | |
| 1511 | |
| 1512 | def CheckForNewlineAtEOF(filename, lines, error): |
| 1513 | """Logs an error if there is no newline char at the end of the file. |
| 1514 | |
| 1515 | Args: |
| 1516 | filename: The name of the current file. |
| 1517 | lines: An array of strings, each representing a line of the file. |
| 1518 | error: The function to call with any errors found. |
| 1519 | """ |
| 1520 | |
| 1521 | # The array lines() was created by adding two newlines to the |
| 1522 | # original file (go figure), then splitting on \n. |
| 1523 | # To verify that the file ends in \n, we just have to make sure the |
| 1524 | # last-but-two element of lines() exists and is empty. |
| 1525 | if len(lines) < 3 or lines[-2]: |
| 1526 | error(filename, len(lines) - 2, 'whitespace/ending_newline', 5, |
| 1527 | 'Could not find a newline character at the end of the file.') |
| 1528 | |
| 1529 | |
| 1530 | def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error): |