-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor and polish the source code of the library #29
refactor and polish the source code of the library #29
Conversation
the goal of this commit is to make a clear distinction between the library which does all the heavy lifting and the binary application which mainly just parses the arguments and calls the library. because i think the application is clearly called `nufmt` i propose here to change the name of the library to `nu_formatter`. i also thought about `nufmt_lib`! this has the huge benefit of making two separate items in the `cargo doc` instead of two with the same `nufmt` name :/ ``` cargo doc --document-private-items --bin nufmt --open ``` directly opens the doc on the application page with the help and the usage, which i find bette :)
this commit is here to make the maintainance of the doc easier: change the README and bam, the doc of the `nufmt` binary is up-to-date!
otherwise, warnings from the documentation and the benchmarks for instance are not seen when running the CI or `toolkit clippy` :o we also make sure we use the same clippy command in the toolkit.
when formatting a string from stdin we need to return the result directly to stdout.
in order to have a slice from `cli.files`, i think `cli.files[..]`, i.e. the whole slice from `cli.files`, is easier to work with than `&*cli.files` and does not require any additional comment.
because on windows we add `\r\n` and only `\n` on linux, we can just conditionally add `\r` when on windows and then always add `\n`.
this commit also removes the `Result` and `Ok` because there is no such error at all in `nu_formatter` for now.
2954fbf
to
98324ec
Compare
cc/ @AucaCoyan some questions remainingClippy missing doc errors (see here)i think these errors are too strong and Rust is expressive enough in these cases 🤔 diff --git a/toolkit.nu b/toolkit.nu
index 5b421e8..6e986f0 100644
--- a/toolkit.nu
+++ b/toolkit.nu
@@ -51,8 +51,6 @@ export def clippy [
--
-D warnings
-D rustdoc::broken_intra_doc_links
- -W missing_docs
- -W clippy::missing_docs_in_private_items
-W clippy::explicit_iter_loop
-W clippy::explicit_into_iter_loop
-W clippy::semicolon_if_nothing_returned to let developer add documentation when it makes the most sense 😌
failing test on windows (see here)in d4bb23a, i've implemented the windows case for adding a newline, which adds a public functionsthere are a bunch of > rg '^\s*pub' | lines | parse "{file}:{match}"
╭────┬───────────────────┬──────────────────────────────────────────────────────────────────────────────╮
│ # │ file │ match │
├────┼───────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ 0 │ src/formatting.rs │ pub fn format_inner(contents: &[u8], _config: &Config) -> Vec<u8> { │
│ 1 │ src/formatting.rs │ pub fn trim_ascii_whitespace(x: &[u8]) -> &[u8] { │
│ 2 │ src/lib.rs │ pub mod config; │
│ 3 │ src/lib.rs │ pub mod formatting; │
│ 4 │ src/lib.rs │ pub fn format_single_file(file: &PathBuf, config: &Config) { │
│ 5 │ src/lib.rs │ pub fn format_string(input_string: &String, config: &Config) -> String { │
│ 6 │ src/config.rs │ pub struct Config { │
│ 7 │ src/config.rs │ pub tab_spaces: usize, │
│ 8 │ src/config.rs │ pub max_width: usize, │
│ 9 │ src/config.rs │ pub margin: usize, │
│ 10 │ src/config.rs │ pub fn new(tab_spaces: usize, max_width: usize, margin: usize) -> Self { │
╰────┴───────────────────┴──────────────────────────────────────────────────────────────────────────────╯ i'm just wondering if we need that many exported things, e.g. we could use |
Hello! Thanks for the time sinked here.
Yeah, clippy can be very annoying sometimes. I'm ok with removing those 2 lints. Especially with the private items.
I'm not sure what is making the test fail, but before
You are correct. That exports were on my 💭 Thanks again for the refactor and suggestions! 🎉 |
- `trim_ascii_whitespaces` is never used outside `formatting` - the `formatting` commands are only used internally
ehe no worries, that was fun 😋
i've disabled the two annoying Clippy items in 13b91dc and made
i've reverted d4bb23a in 3433524, i think
i fixed the visibility in fd032a0 👍
i'm glad you like them 😌 maybe just a last 👍 with the last commits and then let's land this 🥳 |
😆
cooool, thanks for the review, that was fun 😤 |
this PR is all about refactoring the formatting library and executable 😋
details
nu_formatter
nufmt
print
in favor oflog
cli.files
,#[cfg(windows)]
and exit codes)nu_formatter
public