Check E004 once per file, not once per invocation - #9
Draft
taowang487 wants to merge 1 commit into
Draft
Conversation
The "last line should always end with a newline" check sits at the
same indent level as the `for fname in files` loop, so it runs a
single time after every file has been processed, against the `line`
variable left over from whichever file was scanned last. Files
earlier in the list are never checked.
bashate a.sh b.sh # a.sh missing its newline -> not reported
bashate b.sh a.sh # same a.sh -> reported
This inverts a 2016 regression. Before
I54963cd25efc9f9603fbcc60b8e25bb11ea2d7db the check lived in the
isfirstline() block and, as that commit noted, could not fire unless
you passed two files; the fix moved it out of the loop but dedented
one level too far, so now it cannot fire unless the file is passed
last. The test added at the same time is single-file, so it passes
under both behaviours.
Move the check inside the per-file loop and track the file's last raw
line separately -- `line` is unusable here because it is rewritten by
inline-comment stripping and rebound by the `for line in logical_line`
loop. filename/filelineno are passed explicitly since fileinput is
exhausted by that point.
Callers that batch files into one invocation, such as pre-commit, are
most affected: the same offending file passes or fails depending only
on how the file list happens to be ordered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
last line should always end with a newlinecheck sits at the same indent level as thefor fname in filesloop, so it runs a single time after every file has been processed, against thelinevariable left over from whichever file was scanned last. Files earlier in the list are never checked.This inverts a 2016 regression. Before
I54963cd25efc9f9603fbcc60b8e25bb11ea2d7db the check lived in the isfirstline() block and, as that commit noted, could not fire unless you passed two files; the fix moved it out of the loop but dedented one level too far, so now it cannot fire unless the file is passed last. The test added at the same time is single-file, so it passes under both behaviours.
Move the check inside the per-file loop and track the file's last raw line separately --
lineis unusable here because it is rewritten by inline-comment stripping and rebound by thefor line in logical_lineloop. filename/filelineno are passed explicitly since fileinput is exhausted by that point.Callers that batch files into one invocation, such as pre-commit, are most affected: the same offending file passes or fails depending only on how the file list happens to be ordered.