From 20a1d24ff7d137fa02daf1855fdc3239d849c5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Fri, 27 Sep 2024 14:59:13 +0200 Subject: [PATCH] Fix bug and document pre-commit usage --- .github/workflows/ci.yml | 15 ++++++++++++--- .markdownlint-cli2.yaml | 3 +++ CHANGELOG.md | 7 +++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 14 ++++++++++++++ src/main.rs | 3 ++- 7 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 .markdownlint-cli2.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22b3774..4a2b168 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,8 @@ jobs: - name: Setup Rust uses: hecrj/setup-rust-action@v2 with: - rust-version: nightly + rust-version: stable + profile: minimal - name: Set up Python uses: actions/setup-python@v5 with: @@ -54,7 +55,8 @@ jobs: - name: Setup Rust uses: hecrj/setup-rust-action@v2 with: - rust-version: nightly + rust-version: stable + profile: minimal - name: Build run: cargo build --release @@ -73,7 +75,8 @@ jobs: - name: Setup Rust uses: hecrj/setup-rust-action@v2 with: - rust-version: nightly + rust-version: stable + profile: minimal - name: Cache dependencies uses: actions/cache@v4 with: @@ -100,6 +103,9 @@ jobs: - uses: actions/checkout@v4 - name: Setup Rust uses: hecrj/setup-rust-action@v2 + with: + rust-version: stable + profile: minimal - name: Publish run: | cargo login ${{ secrets.CRATES_TOKEN }} @@ -115,6 +121,9 @@ jobs: - uses: actions/checkout@v4 - name: Setup Rust uses: hecrj/setup-rust-action@v2 + with: + rust-version: stable + profile: minimal - name: Publish run: | cargo login ${{ secrets.CRATES_TOKEN }} diff --git a/.markdownlint-cli2.yaml b/.markdownlint-cli2.yaml new file mode 100644 index 0000000..c19fb73 --- /dev/null +++ b/.markdownlint-cli2.yaml @@ -0,0 +1,3 @@ +config: + no-duplicate-heading: false + first-line-heading: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b56f98..63534fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## 2024-09-27 - [0.1.2] + +### Bug fixes + +- Exit code 1 when files formatted. + ## 2024-09-27 - [0.1.1] ### Bug fixes @@ -10,4 +16,5 @@ First beta release +[0.1.2]: https://github.com/mondeja/hledger-fmt/compare/v0.1.1...v0.1.2 [0.1.1]: https://github.com/mondeja/hledger-fmt/compare/v0.1.0...v0.1.1 diff --git a/Cargo.lock b/Cargo.lock index e0e1d65..0888f48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -115,7 +115,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hledger-fmt" -version = "0.1.1" +version = "0.1.2" dependencies = [ "clap", "colored", diff --git a/Cargo.toml b/Cargo.toml index 3aca0d1..95d94d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hledger-fmt" -version = "0.1.1" +version = "0.1.2" edition = "2021" description = "An opinionated hledger's journal files formatter." repository = "https://github.com/mondeja/hledger-fmt" diff --git a/README.md b/README.md index f0d7893..ad68266 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,19 @@ cargo binstall hledger-fmt We don't currently provide standalone pre-built binaries. +### pre-commit + +Use it with [pre-commit] by adding the hook to your _.pre-commit-config.yaml_: + +```yaml +repos: + - repo: https://github.com/mondeja/hledger-fmt + rev: vX.Y.Z + hooks: + # id: hledger-fmt # Use this id to format files in place + - id: hledger-fmt-check # Use this id to check files without formatting +``` + ## Usage When you don't pass files to format, it reads all the files with @@ -61,3 +74,4 @@ accepted to make it more flexible. Send a PR if you want to help. [cargo-binstall]: https://github.com/cargo-bins/cargo-binstall [hledger]: https://hledger.org [cargo]: https://doc.rust-lang.org/cargo/ +[pre-commit]: https://pre-commit.com diff --git a/src/main.rs b/src/main.rs index 5b1bb95..cf1f509 100644 --- a/src/main.rs +++ b/src/main.rs @@ -125,6 +125,8 @@ fn main() { continue; } + exitcode = 1; + if args.fix { match std::fs::write(&file, &formatted) { Ok(_) => {} @@ -135,7 +137,6 @@ fn main() { eprintln!(); } eprintln!("Error writing file {file}: {e}"); - exitcode = 1; } } } else {