-
Notifications
You must be signed in to change notification settings - Fork 6
Better handling of "No newline at end of file" marker #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I just hit this in testing cargo-mutants; it would be nice to merge and release a fix. |
|
@romamik I added a commit to fix a git conflict, hope you don't mind |
…es after the patch.
…rsedLine to LineOrEmptyLine to avoid confusion
|
Just pushed changes that make the resulting code much closer to the current main branch state. Mostly I removed most of the changes in the public API and pushed those flags up the stack while parsing. |
|
"No newline at end of file" marker (the marker) can appear after a removed line, an added line, or a context line. Depending on this, it refers to old content of the file, new content of the file, or both. To support this, while parsing the line, I expect the optional marker after every line: the function When processing each hunk, I check if there was a line with the marker attached, both for old and new content of the file. When processing the whole patch, I check the last hunk if it has these markers. Skipping trailing empty lines Before the changes, when the marker was encountered, the parsing of the lines stopped, and then the empty line was skipped in the |
Ah I see, that makes sense. |
sourcefrog
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #4.
Now the parser checks for every line if it is followed by the "No newline at end of file" line, and saves it with the line. This flag is later used to determine this status for the hunk and then for the file.
Also, I renamed the flag to
missing_newlineas for me, it was hard to wrap my head around the inverted logic of the previous flag. I know that the original marker has negated meaning and that is the main source of confusion, but having variables that are opposite to the marker present in file was an additional source of confusion to me.