-
-
Notifications
You must be signed in to change notification settings - Fork 1
Clippy #43
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
Clippy #43
Conversation
@@ -14,7 +14,7 @@ exclude = [".github"] | |||
maintenance = { status = "experimental" } | |||
|
|||
[features] | |||
default = ["embedded-graphics"] | |||
default = ["embedded-graphics", "crossterm"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the best practice / reasoning picking default features? Crossterm support feels (to me) more like a toy at this point, given there are many better choices for std TUIs in Rust. I imagine nearly everyone who will use this will be targeting no_std / embedded and thought it would reduce confusion by having the default features all be no_std.
As an aside, compile times today seem pretty quick, but I also wonder if users will prefer to opt-out of compiling all of character rendering in the future. I still go back and forth on whether this will (probably by accident) turn into a viable option for TUI, and how much effort to put into supporting it. It's certainly useful to have for testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't have been committed, that's my-bad.
My editor doesn't lint or treat the code with the feature disabled.
I didn't look for an actual solution to this yet, to my knowledge a .vscode/settings.json
and equivalents for other editors does the trick. I'll look into it to avoid committing that by mistake again 😓.
As for the feature themselves I'm not an expert, I'd maybe say no features by default (a compile error can be triggered if no feature are enabled if you want).
As someone probably wants one of the 2 strategies, rarely both.
Setting default to embedded-graphics
means that users will also want to use default-features = false
in their Cargo.toml
when wanting only crossterm
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no worries, I've accidentally done the same thing. I think it probably makes sense then for me to leave it as-is.
use buoyant::font::CharacterBufferFont; | ||
use buoyant::layout::{Layout, LayoutDirection}; | ||
use buoyant::layout::{Layout as _, LayoutDirection}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this lint to enforce as _
@@ -1,18 +1,19 @@ | |||
use std::iter::zip; | |||
#![cfg(test)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What effect does this have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clippy is fine without this line, but rust-analyzer isn't.
despite this file being in the tests
folder it's sometimes not recognized as such and thus triggers an error.
I think this issue rust-lang/rust-analyzer#7225 refers to it.
In personal projects I usually put a lib.rs
in the root of tests
and list modules there, it seemed to fix the issue (see: https://github.com/vic1707/nnn/blob/main/tests/lib.rs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I still don't really understand what the issue is after peeking at that issue, maybe because I just have yet to see it in my personal tools/workflow. Is this an actual problem you see now or is it preemptive?
@@ -517,6 +518,7 @@ fn toggle_stack(is_on: bool) -> impl Renderable<char, Renderables: CharacterRend | |||
} | |||
|
|||
#[test] | |||
#[expect(clippy::cognitive_complexity)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clippy is probably right, these animation tests are very difficult to read. Fixing it is probably a good opportunity to play with wrappers that manage the view/layout/tree and cover up some of the boilerplate. No risk of needing breaking API to change later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noted ✅
@@ -1,3 +1,4 @@ | |||
extern crate alloc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming the changes here will all go away when you update with main, but I agree with preferring alloc to std
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I'd suggest doing an alloc
feature for the same reason the std
feature exists
let x = i16::interpolate(source.origin.x, target.origin.x, domain.factor); | ||
let y = i16::interpolate(source.origin.y, target.origin.y, domain.factor); | ||
let diameter = u16::interpolate(source.diameter, target.diameter, domain.factor); | ||
Circle { | ||
Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
let subdomain; | ||
if end_time == Duration::from_secs(0) || domain.app_time >= end_time { | ||
// animation has already completed or there was zero duration | ||
let subdomain = if end_time == Duration::from_secs(0) || domain.app_time >= end_time { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lean more towards this being situational discretion than something that ought to be linted on. This is actually a great example of where the lint doesn't help lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough, clippy is opinionated and this changes most definitely comes from nursery
. I'll disable it globally 👍
#[cfg(test)] | ||
#[cfg(feature = "embedded-graphics")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -0,0 +1,48 @@ | |||
[build] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to configure this with rustflags or in the Cargo.toml? I've used the Cargo.toml option to warn on pedantic as well as disabling a couple temporarily.
I tried enabling the nursery lints in another project and ended up turning it off because a lot ended up just being annoying. I assume a lot of these that have been manually allowed are probably nursery too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if there is an accepted/idiomatic answer.
IMO Cargo.toml
is included in the library publishing process and users read it, I feel like the crate's clippy config isn't of users concern (as in "users don't care", not "should be hidden") so we shouldn't bother them with it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep most of the disabled lints here are from nursery
(each commit deals with a specific group of lints).
it's a pain, some lints contradict others some feel useless (let me do maths already 😡😂) but I don't know, I think I grew into liking them.
I view them as "nice to have" or at least "don't be afraid to disable some", it makes them more bearable
@@ -139,17 +141,17 @@ fn test_match_view_two_variants_invalid_layout() { | |||
let font = CharacterBufferFont; | |||
let make_view = |state| { | |||
match_view!(state => { | |||
0 => Text::str("zero\n!!!", &font), | |||
0i32 => Text::str("zero\n!!!", &font), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undecided on this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it looks weird, a solution would be to inject the #[allow()]
attribute inside the macro
I think we'll stick to defining these in the Cargo.toml, mainly because this has advantages for workspaces which I imagine this will eventually become. It makes importing them into the packages trivial, whereas I believe the rust flags must be duplicated for every package. # package/Cargo.toml
[lints]
workspace = true I think what I want for the lint selection is actually the inverse. The default lints really go a long way and like you said, they're quite powerful. Rather than dealing with random issues that pop up in unstable nursery and restriction lints, I think I'd rather cherry pick what makes the most sense for this project today. I went through, and I think this covers the issues you've fixed. I picked out some others that I think make sense, but probably require more involved changes. [lints.clippy]
pedantic = { level = "deny", priority = -1 }
# You fixed?
needless_pass_by_ref_mut = "deny"
use_self = "deny"
derive_partial_eq_without_eq = "deny"
too_long_first_doc_paragraph = "deny"
type_repetition_in_bounds = "deny"
option_if_let_else = "deny"
useless_let_if_seq = "deny"
# TODO: Disabled for now, desired fix
cast_possible_wrap = "allow"
cast_possible_truncation = "allow"
exhaustive_structs = "allow"
exhaustive_enums = "allow"
missing_panics_doc = "allow"
field_scoped_visibility_modifiers = "allow"
ref_patterns = "allow"
cast_sign_loss = "allow"
string_slice = "allow"
shadow_unrelated = "allow"
renamed_function_params = "allow"
float_arithmetic = "allow"
indexing_slicing = "allow"
as_conversions = "allow"
absolute_paths = "allow" # configure as makes sense |
Thanks for all the effort answering my questions in your PR! I (finally) ended up merging the results of this separately in #60 to avoid the conflicts |
Hi, I'm terribly sorry you ended up doing it yourself 😞 |
Life gets busy, no worries. Running |
Fixes #42 (?)
Had a bit of fun checking lints and all assuming you'd want to at least see what it looks like ^^
As you said enabling
clippy::pedantic
didn't trigger much (only 2 lints about numbers casts).Feel free to checkout the branch and see what lints should be enabled (and thus fixed) or if any actual changes bother you so we can revert and bypass the lint.
Todo: