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)
| 2536 | |
| 2537 | |
| 2538 | def CheckForNewlineAtEOF(filename, lines, error): |
| 2539 | """Logs an error if there is no newline char at the end of the file. |
| 2540 | |
| 2541 | Args: |
| 2542 | filename: The name of the current file. |
| 2543 | lines: An array of strings, each representing a line of the file. |
| 2544 | error: The function to call with any errors found. |
| 2545 | """ |
| 2546 | |
| 2547 | # The array lines() was created by adding two newlines to the |
| 2548 | # original file (go figure), then splitting on \n. |
| 2549 | # To verify that the file ends in \n, we just have to make sure the |
| 2550 | # last-but-two element of lines() exists and is empty. |
| 2551 | if len(lines) < 3 or lines[-2]: |
| 2552 | error(filename, len(lines) - 2, 'whitespace/ending_newline', 5, |
| 2553 | 'Could not find a newline character at the end of the file.') |
| 2554 | |
| 2555 | |
| 2556 | def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error): |