Commit e6b2531
authored
Read config file, parallel file processing, exit codes, check mode, exclude files (#69)
Hi everyone,
There are a lot of new features in this PR. Sorry it will be a lot to
review, it would have probably been better to make multiple smaller PRs,
but I got excited, so I did way more than I expected in the first place.
Of course, don't hesitate to test it on your side too!
So thanks in advance to all reviewers.
Again, I'm fairly new to rust, so any suggestion to improve the code or
make it more idiomatic are very welcome :)
# Issue
No linked issues.
# Description of changes
### Reading configuration file now supported (was todo)
After those changes, nufmt will take the configuration this order:
1. The one provided by the CLI, if --config is used
2. Look for a file called "nufmt.nuon" in the current directory or any
of the parent directory
3. If nothing is found, use the default
### New "check mode"
Inspired by the ruff formatter, you can now run nufmt with --check, and
will just tell you if files need formatting, but will not write the
fixes.
### Possibility to exclude some files
You can now add some patterns to exclude in the configuration file and
the file discovery is handled by the ``ignore`` crate, which uses
``walkdir``.
### Exit codes
Inspired by the ruff formatter again, the exit codes are
- 0 if files were already good, or if all were successfully formatted
- 1 only in check mode and if at least one file needs reformatting
- 2 a failure occurred: config file can't be parsed, cannot write to
file (not found...), or **found garbage in any of the .nu files**
### Improved what was printed in stdout and stderr
See below for screenshots
### Docs and tests
I did not cover 100%, but I added in:
- README
- docstrings
- unit and integration tests
### Performance improvement
Used ``rayon`` to format files in parallel.
### Dependencies
- upgraded nu to 0.104.0
- Added quite some dependencies:
- nuon to read the config file
- ignore for file discovery
- colored for terminal output
- thiserror for error handling, but removed anyhow as it wasn't used
- rayon for parallel processing
- rstest and tmpfile for tests
### How does it look?
Various use cases demo:

Demo of excluding files:
1 parent feafe69 commit e6b2531
File tree
14 files changed
+1538
-752
lines changed- .github/workflows
- benches
- scripts
- src
- tests
14 files changed
+1538
-752
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | 38 | | |
47 | 39 | | |
48 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
0 commit comments