-
Notifications
You must be signed in to change notification settings - Fork 14
fix: Last line swallowing #95
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ pub mod cli; | |
| pub mod executor; | ||
| mod nom_ext; | ||
| pub mod parser; | ||
| #[cfg(test)] | ||
| mod tests; | ||
|
|
||
| use std::io::Write; | ||
|
|
||
|
|
@@ -26,12 +28,15 @@ pub trait Processor<'a> { | |
| .context("processing markdown piece")?; | ||
| } | ||
|
|
||
| let (_input, _) = iter | ||
| let (remaining_input, _) = iter | ||
| .finish() | ||
| .finish() | ||
| .map_err(fmt_nom_error(input, &format!("{input_pipe:?}"))) | ||
| .context("parsing markdown")?; | ||
|
|
||
| self.process_piece(MdPiece::RawLine(remaining_input)) | ||
| .context("processing remaining unparsed input")?; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,16 +4,6 @@ use std::{ | |
| }; | ||
|
|
||
| use anyhow::Context; | ||
|
|
||
| /// Trims trailing ASCII whitespace from a byte slice. | ||
| /// Stable alternative to the unstable `trim_ascii_end()` method. | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is stable since 1.80.0
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the CI cargo version is outdated
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nixos-unstable is at 1.89.0. Is that enough? |
||
| fn trim_ascii_end(bytes: &[u8]) -> &[u8] { | ||
| let mut end = bytes.len(); | ||
| while end > 0 && bytes[end - 1].is_ascii_whitespace() { | ||
| end -= 1; | ||
| } | ||
| &bytes[..end] | ||
| } | ||
| use clap::Parser; | ||
| use mdsh::{ | ||
| cli::{FileArg, Opt, Parent}, | ||
|
|
@@ -81,8 +71,10 @@ fn process_file( | |
| } | ||
| let file_unmodified_check = !frozen || input_content.as_bytes() == buffer; | ||
|
|
||
| std::fs::write(outf, trim_ascii_end(&buffer)) | ||
| .with_context(|| format!("failed to write file {outf:?}"))?; | ||
| let mut out = | ||
| File::create(outf).with_context(|| format!("failed to write file {outf:?}"))?; | ||
| out.write(buffer.trim_ascii_end())?; | ||
| out.write(b"\n")?; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| file_unmodified_check | ||
| .then_some(()) | ||
|
|
||
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.
If there are no changes to README.md with
always_runit is run without README.md being passed as the cli arg param