beanfmt 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- beanfmt-0.1.0/.github/workflows/ci.yml +23 -0
- beanfmt-0.1.0/.github/workflows/release.yml +78 -0
- beanfmt-0.1.0/.gitignore +25 -0
- beanfmt-0.1.0/CLAUDE.md +46 -0
- beanfmt-0.1.0/Cargo.lock +780 -0
- beanfmt-0.1.0/Cargo.toml +63 -0
- beanfmt-0.1.0/PKG-INFO +7 -0
- beanfmt-0.1.0/README.md +149 -0
- beanfmt-0.1.0/README.zh-CN.md +147 -0
- beanfmt-0.1.0/editors/code/.gitignore +5 -0
- beanfmt-0.1.0/editors/code/.vscodeignore +9 -0
- beanfmt-0.1.0/editors/code/package.json +96 -0
- beanfmt-0.1.0/editors/code/src/beanfmt-wasm.d.ts +14 -0
- beanfmt-0.1.0/editors/code/src/extension.ts +94 -0
- beanfmt-0.1.0/editors/code/tsconfig.json +17 -0
- beanfmt-0.1.0/justfile +70 -0
- beanfmt-0.1.0/pyproject.toml +19 -0
- beanfmt-0.1.0/src/align.rs +142 -0
- beanfmt-0.1.0/src/cli/main.rs +109 -0
- beanfmt-0.1.0/src/lib.rs +143 -0
- beanfmt-0.1.0/src/line.rs +250 -0
- beanfmt-0.1.0/src/normalize.rs +143 -0
- beanfmt-0.1.0/src/options.rs +32 -0
- beanfmt-0.1.0/src/python/mod.rs +279 -0
- beanfmt-0.1.0/src/recursive.rs +85 -0
- beanfmt-0.1.0/src/sort.rs +351 -0
- beanfmt-0.1.0/src/wasm.rs +45 -0
- beanfmt-0.1.0/tests/align_test.rs +196 -0
- beanfmt-0.1.0/tests/fixtures/basic.beancount +16 -0
- beanfmt-0.1.0/tests/fixtures/cjk.beancount +7 -0
- beanfmt-0.1.0/tests/fixtures/normalize.beancount +10 -0
- beanfmt-0.1.0/tests/integration_test.rs +345 -0
- beanfmt-0.1.0/tests/line_test.rs +910 -0
- beanfmt-0.1.0/tests/normalize_test.rs +179 -0
- beanfmt-0.1.0/tests/recursive_test.rs +99 -0
- beanfmt-0.1.0/tests/sort_test.rs +314 -0
- beanfmt-0.1.0/uv.lock +7 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
env:
|
|
10
|
+
CARGO_TERM_COLOR: always
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
check:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
18
|
+
with:
|
|
19
|
+
components: rustfmt, clippy
|
|
20
|
+
- uses: Swatinem/rust-cache@v2
|
|
21
|
+
- run: cargo fmt -- --check
|
|
22
|
+
- run: cargo clippy --all-targets --all-features -- -D warnings
|
|
23
|
+
- run: cargo test
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
|
|
10
|
+
env:
|
|
11
|
+
CARGO_TERM_COLOR: always
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
19
|
+
- uses: Swatinem/rust-cache@v2
|
|
20
|
+
- run: cargo test
|
|
21
|
+
|
|
22
|
+
publish-crate:
|
|
23
|
+
needs: test
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v4
|
|
27
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
28
|
+
- uses: Swatinem/rust-cache@v2
|
|
29
|
+
- run: cargo publish
|
|
30
|
+
env:
|
|
31
|
+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
|
32
|
+
|
|
33
|
+
publish-pypi:
|
|
34
|
+
needs: test
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
39
|
+
- uses: Swatinem/rust-cache@v2
|
|
40
|
+
- uses: astral-sh/setup-uv@v4
|
|
41
|
+
- run: uv run maturin publish --features python
|
|
42
|
+
env:
|
|
43
|
+
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
|
|
44
|
+
|
|
45
|
+
publish-vscode:
|
|
46
|
+
needs: test
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/checkout@v4
|
|
50
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
51
|
+
with:
|
|
52
|
+
targets: wasm32-unknown-unknown
|
|
53
|
+
- uses: Swatinem/rust-cache@v2
|
|
54
|
+
- uses: oven-sh/setup-bun@v2
|
|
55
|
+
- run: wasm-pack build --target nodejs --out-dir editors/code/wasm --features wasm --no-default-features
|
|
56
|
+
- run: cd editors/code && bun install && bun run compile
|
|
57
|
+
- run: cd editors/code && bunx @vscode/vsce package --allow-missing-repository
|
|
58
|
+
- run: cd editors/code && bunx @vscode/vsce publish
|
|
59
|
+
env:
|
|
60
|
+
VSCE_PAT: ${{ secrets.VSCE_PAT }}
|
|
61
|
+
- uses: actions/upload-artifact@v4
|
|
62
|
+
with:
|
|
63
|
+
name: vsix
|
|
64
|
+
path: editors/code/*.vsix
|
|
65
|
+
|
|
66
|
+
github-release:
|
|
67
|
+
needs: [publish-crate, publish-pypi, publish-vscode]
|
|
68
|
+
runs-on: ubuntu-latest
|
|
69
|
+
steps:
|
|
70
|
+
- uses: actions/checkout@v4
|
|
71
|
+
- uses: actions/download-artifact@v4
|
|
72
|
+
with:
|
|
73
|
+
name: vsix
|
|
74
|
+
path: artifacts
|
|
75
|
+
- uses: softprops/action-gh-release@v2
|
|
76
|
+
with:
|
|
77
|
+
generate_release_notes: true
|
|
78
|
+
files: artifacts/*.vsix
|
beanfmt-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Project
|
|
2
|
+
external/
|
|
3
|
+
docs/
|
|
4
|
+
|
|
5
|
+
# Generated by Cargo
|
|
6
|
+
# will have compiled files and executables
|
|
7
|
+
debug
|
|
8
|
+
target
|
|
9
|
+
|
|
10
|
+
# These are backup files generated by rustfmt
|
|
11
|
+
**/*.rs.bk
|
|
12
|
+
|
|
13
|
+
# MSVC Windows builds of rustc generate these, which store debugging information
|
|
14
|
+
*.pdb
|
|
15
|
+
|
|
16
|
+
# Generated by cargo mutants
|
|
17
|
+
# Contains mutation testing data
|
|
18
|
+
**/mutants.out*/
|
|
19
|
+
|
|
20
|
+
# RustRover
|
|
21
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
22
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
23
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
24
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
25
|
+
#.idea/
|
beanfmt-0.1.0/CLAUDE.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
Beanfmt is a fast beancount file formatter with CJK double-width character support. It provides a Rust library, CLI binary, Python bindings (via PyO3/maturin, managed by uv), and WASM bindings (via wasm-bindgen). The VSCode extension uses bun for Node package management.
|
|
8
|
+
|
|
9
|
+
## Build & Test Commands
|
|
10
|
+
|
|
11
|
+
All commands are available via `just` (see `justfile` for details):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
just # List all available recipes
|
|
15
|
+
just build # Build library
|
|
16
|
+
just build-cli # Build CLI binary
|
|
17
|
+
just build-python # Build Python extension (uv + maturin)
|
|
18
|
+
just build-wasm # Build WASM module
|
|
19
|
+
just build-vscode # Build VSCode extension (WASM + TypeScript)
|
|
20
|
+
just package-vscode # Package .vsix
|
|
21
|
+
just test # Run all tests
|
|
22
|
+
just test-file name # Run a specific test file
|
|
23
|
+
just clippy # Run clippy lints
|
|
24
|
+
just fmt # Format code
|
|
25
|
+
just fmt-check # Check formatting
|
|
26
|
+
just check # Run all checks (fmt, clippy, test)
|
|
27
|
+
just clean # Clean build artifacts
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Architecture
|
|
31
|
+
|
|
32
|
+
The formatting pipeline in `lib.rs::format()` processes input line-by-line through three stages:
|
|
33
|
+
|
|
34
|
+
1. **Sort** (`sort.rs`) — optionally reorder entries by date
|
|
35
|
+
2. **Parse** (`line.rs`) — regex-based parser classifies each line into a `Line` enum variant (TransactionHeader, Posting, Balance, Open, Close, Price, MetaItem, Comment, etc.)
|
|
36
|
+
3. **Normalize + Align** — per-variant formatting:
|
|
37
|
+
- `normalize.rs` — standardizes indentation, thousands separators, brace spacing, comment formatting
|
|
38
|
+
- `align.rs` — column-aligns currencies and costs using `unicode-width` for CJK-aware display width calculation
|
|
39
|
+
|
|
40
|
+
Key design points:
|
|
41
|
+
|
|
42
|
+
- `Options` struct (`options.rs`) is the single configuration object shared across all targets
|
|
43
|
+
- `recursive.rs` (gated behind `cli`/`python` features) — BFS traversal of `include` directives with glob expansion
|
|
44
|
+
- Features `python` and `wasm` are **mutually exclusive** (enforced by compile_error!)
|
|
45
|
+
- All regex patterns use `LazyLock` for one-time compilation
|
|
46
|
+
- The `line.rs` parser uses zero-copy `&str` slices via the `Line<'a>` enum
|