Skip to content

fix: Last line swallowing#95

Open
sirewix wants to merge 2 commits intomainfrom
sirewix/fix-eof-swallow
Open

fix: Last line swallowing#95
sirewix wants to merge 2 commits intomainfrom
sirewix/fix-eof-swallow

Conversation

@sirewix
Copy link
Collaborator

@sirewix sirewix commented Dec 21, 2025

  • fix last line swallow when it doesn't end with newline (parsing and processing bug)
  • fix last char being newline swallow (to be compatible with precommit's end-of-file-fixer hook)

- fix last line swallow when it doesn't end with newline
- fix last char being newline swallow
files: README.md
files: ^README.md$
always_run: true
pass_filenames: false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no changes to README.md with always_run it is run without README.md being passed as the cli arg param

.context("parsing markdown")?;

self.process_piece(MdPiece::RawLine(remaining_input))
.context("processing remaining unparsed input")?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can happen when last character of the input is not newline. We can't add nom::combinator::rest at the end as then iterator will keep matching on it forever.

use anyhow::Context;

/// Trims trailing ASCII whitespace from a byte slice.
/// Stable alternative to the unstable `trim_ascii_end()` method.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is stable since 1.80.0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the CI cargo version is outdated

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bumped nixos to 25.11 but the rustc version there is 1.78. I don't have much experience with nix, is there any quick fix, @zimbatm? It would be nice to have the latest version features available (which is 1.92 as of today)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nixos-unstable is at 1.89.0. Is that enough?

let mut out =
File::create(outf).with_context(|| format!("failed to write file {outf:?}"))?;
out.write(buffer.trim_ascii_end())?;
out.write(b"\n")?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused some parsing failures (that should be fixed). And it's incompatible with the precommit's end-of-file-fixer hook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants