ardent
An opinionated code formatter for NSIS scripts
Description
This is a Rust implementation of dent, a NodeJS-based formatting tool for NSIS scripts.
It aims to be fully compatible while making distribution easier for people outside the NodeJS ecosystem.
Installation
Cargo
cargo install ardent
Scoop
scoop bucket add nsis https://github.com/NSIS-Dev/scoop-nsis
scoop install nsis/ardent
Homebrew
brew install idleberg/asahi/ardent
Nix
nix profile install github:idleberg/ardent
Source
git clone https://github.com/idleberg/ardent.git
cd ardent
cargo build --release
The binary is at target/release/ardent.
CLI Usage
ardent [OPTIONS] [COMMAND]
Commands:
format Format NSIS scripts
check Check if NSIS scripts are formatted correctly
Options:
-D, --debug Print debug messages
-h, --help Print help
-V, --version Print version
Format
Formats one or more .nsi / .nsh files.
# Print formatted output to stdout
ardent format installer.nsi
# Edit files in-place
ardent format --write src/**/*.nsi
See ardent format --help for available options.
Check
Checks whether files are already formatted.
# Check only (reports drift)
ardent check src/**/*.nsi
# Check and auto-fix (still exits 1 if drift was found)
ardent check --write src/**/*.nsi
See ardent check --help for available options.
Library Usage
Formatting
use ;
let formatter = new.expect;
let input = r#"section "My Section"
detailprint "Hello"
sectionend
"#;
let output = formatter.format.expect;
assert_eq!;
Checking
Returns None if the input is already formatted, or Some(formatted) if it needs changes.
use ;
let formatter = new.unwrap;
match formatter.check.unwrap
Options
| Field | Type | Default | Description |
|---|---|---|---|
end_of_line |
Option<EndOfLine> |
None (auto-detect) |
Force CRLF or LF line endings |
indent_size |
usize |
2 |
Spaces per indent level (ignored when using tabs) |
print_width |
usize |
120 |
Maximum line width before wrapping with \ continuations (0 disables) |
single_quote |
bool |
false |
Prefer single quotes instead of double quotes |
trim_empty_lines |
bool |
true |
Collapse consecutive blank lines and strip leading/trailing blanks |
use_tabs |
bool |
true |
Indent with tabs instead of spaces |
[!TIP] While many follow their personal preferences in the tabs vs spaces discussion, accessibility is probably the strongest argument to prefer tabs. See this discussion for more context.
Benchmark
Benchmark 1: ardent check Examples/bigtest.nsi
Time (mean ± σ): 1.7 ms ± 0.3 ms [User: 1.3 ms, System: 0.4 ms]
Range (min … max): 1.3 ms … 4.8 ms 415 runs
Benchmark 2: dent check Examples/bigtest.nsi
Time (mean ± σ): 101.9 ms ± 4.6 ms [User: 95.5 ms, System: 11.4 ms]
Range (min … max): 97.9 ms … 124.4 ms 29 runs
Summary
ardent check Examples/bigtest.nsi ran
58.70 ± 10.67 times faster than dent check Examples/bigtest.nsi
Related
- setup-ardent - GitHub Action to install ardent
- ardent.nvim - Neovim formatting plugin
License
This work is licensed under The MIT License.