ardent
An opinionated code formatter for NSIS scripts
Description
This is a Rust implementation of dent-cli, a NodeJS-based formatting tool for NSIS scripts.
"ar" for Rust, "dent" as for the formatter. Well, nevermind!
It aims to be fully compatible while making distribution easier for people outside the NodeJS ecosystem.
Installation
crates.io
Source
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
# Edit files in-place
See ardent format --help for available options.
Check
Checks whether files are already formatted.
# Check only (reports drift)
# Check and auto-fix (still exits 1 if drift was found)
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_lines |
Option<EndOfLines> |
None (auto-detect) |
Force CRLF or LF line endings |
indent_size |
usize |
2 |
Spaces per indent level (ignored when using tabs) |
trim_empty_lines |
bool |
true |
Collapse consecutive blank lines and strip leading/trailing blanks |
use_tabs |
bool |
true |
Indent with tabs instead of spaces |
:white_check_mark: Why defaulting to tabs is good for accessibility
Benchmark
Benchmark 1: ardent check Examples/bigtest.nsi
Time (mean ± σ): 2.1 ms ± 0.7 ms [User: 1.2 ms, System: 0.6 ms]
Range (min … max): 1.5 ms … 11.8 ms 488 runs
Benchmark 2: dent check Examples/bigtest.nsi
Time (mean ± σ): 62.8 ms ± 3.1 ms [User: 55.5 ms, System: 10.1 ms]
Range (min … max): 61.1 ms … 82.5 ms 45 runs
Summary
ardent check Examples/bigtest.nsi ran
29.22 ± 9.26 times faster than dent check Examples/bigtest.nsi
License
This work is licensed under The MIT License.