Skip to content

Commit e6b2531

Browse files
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: ![image](https://github.com/user-attachments/assets/6d2eab3e-bfbf-461e-99a9-fa2a11099a3e) Demo of excluding files: ![image](https://github.com/user-attachments/assets/ba3aa242-d14f-466b-b2df-485c5d602d31)
1 parent feafe69 commit e6b2531

File tree

14 files changed

+1538
-752
lines changed

14 files changed

+1538
-752
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ jobs:
3535
--all-targets \
3636
--no-deps \
3737
--workspace \
38-
-- \
39-
-D warnings \
40-
-D rustdoc::broken_intra_doc_links \
41-
-W clippy::explicit_iter_loop \
42-
-W clippy::explicit_into_iter_loop \
43-
-W clippy::semicolon_if_nothing_returned \
44-
-W clippy::doc_markdown \
45-
-W clippy::manual_let_else
4638
4739
test:
4840
name: test rust files

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ result
1010
# editors
1111
.idea/
1212
.vscode/
13+
14+
# Everyone their own
15+
tmp/

0 commit comments

Comments
 (0)