Repository navigation
fix(check): match bean-check on close-with-balance; move advisory to lint - #1446
Merged
Merged
Conversation
…lint
Closing an account that still holds a non-zero balance produced E1004
(AccountCloseNotEmpty), which Python beancount's bean-check never emits:
close records that an account is inactive from a date, it does not
require a zero balance. This made `rledger check` stricter than beancount
on valid input, including our own valid-ledger.beancount fixture.
Per the Python Compatibility Policy, `check` mirrors bean-check. This
moves the diagnostic from check to a dedicated lint rather than dropping
it outright:
- ErrorCode::is_advisory_only() marks E1004 as advisory-only.
- `check` filters advisory-only codes from its report and its warning
count (is_advisory_only_code), so valid-ledger.beancount now checks
clean, matching bean-check.
- The detection is unchanged in validate, so the LSP/editor still warns.
- New `rledger lint closed-nonempty` reuses the canonical
process(validate:true) pipeline and keeps only E1004, with text and
JSON output.
Snapshots for check_clean_{text,json} updated (now "No errors found").
Regression tests: the lint reports a balance-bearing close and stays
silent on a zero-balance close.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns rledger check behavior with Python beancount’s bean-check by treating E1004 / AccountCloseNotEmpty as advisory-only (not reported by check), while preserving the advisory via a dedicated rledger lint closed-nonempty subcommand.
Changes:
- Mark
ErrorCode::AccountCloseNotEmptyas advisory-only inrustledger-validateand filter advisory-only diagnostics fromrledger checkoutput + warning counts. - Add new
rledger lint closed-nonemptycommand that reports onlyE1004findings in text or JSON. - Update
check_cleanCLI snapshots to expect no warnings/diagnostics.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger/tests/snapshots/cli_snapshot_test__check_clean_text.snap | Updates snapshot to expect clean check output (no E1004 warning). |
| crates/rustledger/tests/snapshots/cli_snapshot_test__check_clean_json.snap | Updates JSON snapshot to expect empty diagnostics and warning_count: 0. |
| crates/rustledger/src/cmd/lint/mod.rs | Registers the new closed-nonempty lint subcommand and dispatch. |
| crates/rustledger/src/cmd/lint/closed_nonempty.rs | Implements rledger lint closed-nonempty (text/JSON reporting + tests). |
| crates/rustledger/src/cmd/check.rs | Filters advisory-only codes from check diagnostics and warning count. |
| crates/rustledger-validate/src/error.rs | Adds ErrorCode::is_advisory_only() and marks E1004 as advisory-only. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-06-20)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…rrors Addresses Copilot review on #1446: - Replace the hard-coded "E1004" literals in check.rs and closed_nonempty.rs with the canonical source: a new rustledger_validate::is_advisory_only_code() (string-keyed counterpart to ErrorCode::is_advisory_only) and ErrorCode::AccountCloseNotEmpty .code(). No more code-string drift if the code is ever renumbered. - lint closed-nonempty now bails on a file with load errors instead of silently clearing them and reporting "no accounts" for input that didn't parse. The Loader surfaces parse/include errors in `errors` (not as Err), so the lint checks that list and fails loudly. Adds a regression test (missing include -> hard error). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Member
Author
|
Addressed all three Copilot findings in e1d5bc8:
|
robcohen
added a commit
that referenced
this pull request
Oct 9, 2026
…2534) * fix(query): skip advisory-only diagnostics on stderr, as check does Closing an account that still holds a balance is E1004, which is advisory-only: beancount does not flag it, so bean-check and bean-query print nothing, and `rledger check` already skips it (#1446). #2238 turned validation on in `query` (for `#balances.discrepancy`) without that skip, so `rledger query` printed "E1004: Cannot close account ... with non-zero balance" on ledgers `rledger check` called clean. `query` now filters with the same `is_advisory_only_code` predicate as `check`. Other diagnostics on the same load are still printed. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr * fix(query): print option diagnostics, as check and bean-query do `query` printed `ledger.errors` only. Option diagnostics (E7001 unknown option, E7002 invalid value, the rest of E7xxx) are kept on `options.warnings`, so a misspelled option was reported by `rledger check` and bean-query and went unreported here. They are now printed first, as bean-query does, ahead of the validation errors, through the same `--no-errors` switch. Neither kind of diagnostic changes query's exit status (bean-query also exits 0). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.
What
rledger checkemitted E1004 / AccountCloseNotEmpty when an account was closed while still holding a non-zero balance. Python beancount'sbean-check(3.2.3) never emits this —closerecords that an account is inactive from a date; it does not require a zero balance. Socheckwas stricter than beancount on valid input, including our ownvalid-ledger.beancountfixture (which thecheck_cleansnapshot test was asserting with a warning).Per the Python Compatibility Policy (
checkmirrorsbean-check), this moves the advisory out ofcheckinto a dedicated lint rather than dropping it — the "you closed an account with money still in it" nudge is genuinely useful, just not acheck-level concern.How
ErrorCode::is_advisory_only()marks E1004 as advisory-only.checkskips advisory-only codes in both its rendered report and its warning count (is_advisory_only_code), sovalid-ledger.beancountnow checks clean — matchingbean-check.rustledger-validate, so the LSP/editor still surfaces the advisory.rledger lint closed-nonemptyreuses the canonicalprocess(validate: true)pipeline and keeps only E1004, with text and JSON output.Verify
check_clean_{text,json}snapshots updated → "✓ No errors found",warning_count: 0.closed_nonempty.rs: reports a balance-bearing close; silent on a zero-balance close.cargo test -p rustledger -p rustledger-validate, clippy, and fmt all green.🤖 Generated with Claude Code