Skip to content

Commit

Permalink
Setup global cargo lint configuration (nushell#13691)
Browse files Browse the repository at this point in the history
# Description
`cargo` somewhat recently gained the capability to store `lints`
settings for the crate and workspace, that can override the defaults
from `rustc` and `clippy` lints. This means we can enforce some lints
without having to actively pass them to clippy via `cargo clippy -- -W
...`. So users just forking the repo have an easier time to follow
similar requirements like our CI.

## Limitation

An exception that remains is that those lints apply to both the primary
code base and the tests. Thus we can't include e.g. `unwrap_used`
without generating noise in the tests. Here the setup in the CI remains
the most helpful.

## Included lints

- Add `clippy::unchecked_duration_subtraction` (added by nushell#12549)
# User-Facing Changes
Running `cargo clippy --workspace` should be closer to the CI. This has
benefits for editor configured runs of clippy and saves you from having
to use `toolkit` to be close to CI in more cases.
  • Loading branch information
sholderbach authored Aug 28, 2024
1 parent 644bebf commit 84e1ac2
Show file tree
Hide file tree
Showing 31 changed files with 126 additions and 30 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ windows = "0.54"
windows-sys = "0.48"
winreg = "0.52"

[workspace.lints.clippy]
# Warning: workspace lints affect library code as well as tests, so don't enable lints that would be too noisy in tests like that.
# todo = "warn"
unchecked_duration_subtraction = "warn"

[lints]
workspace = true

[dependencies]
nu-cli = { path = "./crates/nu-cli", version = "0.97.2" }
nu-cmd-base = { path = "./crates/nu-cmd-base", version = "0.97.2" }
Expand Down
5 changes: 4 additions & 1 deletion crates/nu-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ which = { workspace = true }

[features]
plugin = ["nu-plugin-engine"]
system-clipboard = ["reedline/system_clipboard"]
system-clipboard = ["reedline/system_clipboard"]

[lints]
workspace = true
5 changes: 4 additions & 1 deletion crates/nu-cmd-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ version = "0.97.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lints]
workspace = true

[dependencies]
nu-engine = { path = "../nu-engine", version = "0.97.2" }
nu-parser = { path = "../nu-parser", version = "0.97.2" }
Expand All @@ -18,4 +21,4 @@ nu-protocol = { path = "../nu-protocol", version = "0.97.2" }
indexmap = { workspace = true }
miette = { workspace = true }

[dev-dependencies]
[dev-dependencies]
5 changes: 4 additions & 1 deletion crates/nu-cmd-extra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-cmd-base = { path = "../nu-cmd-base", version = "0.97.2" }
nu-engine = { path = "../nu-engine", version = "0.97.2" }
Expand All @@ -35,4 +38,4 @@ itertools = { workspace = true }
[dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.97.2" }
nu-command = { path = "../nu-command", version = "0.97.2" }
nu-test-support = { path = "../nu-test-support", version = "0.97.2" }
nu-test-support = { path = "../nu-test-support", version = "0.97.2" }
5 changes: 4 additions & 1 deletion crates/nu-cmd-lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-engine = { path = "../nu-engine", version = "0.97.2" }
nu-parser = { path = "../nu-parser", version = "0.97.2" }
Expand All @@ -28,4 +31,4 @@ mimalloc = []
trash-support = []
sqlite = []
static-link-openssl = []
system-clipboard = []
system-clipboard = []
5 changes: 4 additions & 1 deletion crates/nu-cmd-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ version = "0.97.2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lints]
workspace = true

[dependencies]
nu-engine = { path = "../nu-engine", version = "0.97.2" }
nu-path = { path = "../nu-path", version = "0.97.2" }
Expand All @@ -17,4 +20,4 @@ nu-plugin-engine = { path = "../nu-plugin-engine", version = "0.97.2" }

itertools = { workspace = true }

[dev-dependencies]
[dev-dependencies]
5 changes: 4 additions & 1 deletion crates/nu-color-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-protocol = { path = "../nu-protocol", version = "0.97.2" }
nu-engine = { path = "../nu-engine", version = "0.97.2" }
Expand All @@ -19,4 +22,4 @@ nu-ansi-term = { workspace = true }
serde = { workspace = true, features = ["derive"] }

[dev-dependencies]
nu-test-support = { path = "../nu-test-support", version = "0.97.2" }
nu-test-support = { path = "../nu-test-support", version = "0.97.2" }
3 changes: 3 additions & 0 deletions crates/nu-command/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-cmd-base = { path = "../nu-cmd-base", version = "0.97.2" }
nu-color-config = { path = "../nu-color-config", version = "0.97.2" }
Expand Down
5 changes: 4 additions & 1 deletion crates/nu-derive-value/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ proc-macro = true
# so we cannot test anything useful in a doctest
doctest = false

[lints]
workspace = true

[dependencies]
proc-macro2 = { workspace = true }
syn = { workspace = true }
quote = { workspace = true }
proc-macro-error = { workspace = true }
heck = { workspace = true }
heck = { workspace = true }
5 changes: 4 additions & 1 deletion crates/nu-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-protocol = { path = "../nu-protocol", features = ["plugin"], version = "0.97.2" }
nu-path = { path = "../nu-path", version = "0.97.2" }
Expand All @@ -19,4 +22,4 @@ log = { workspace = true }
terminal_size = { workspace = true }

[features]
plugin = []
plugin = []
5 changes: 4 additions & 1 deletion crates/nu-explore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-protocol = { path = "../nu-protocol", version = "0.97.2" }
nu-parser = { path = "../nu-parser", version = "0.97.2" }
Expand All @@ -32,4 +35,4 @@ ansi-str = { workspace = true }
unicode-width = { workspace = true }
lscolors = { workspace = true, default-features = false, features = [
"nu-ansi-term",
] }
] }
5 changes: 4 additions & 1 deletion crates/nu-glob/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ categories = ["filesystem"]
bench = false

[dev-dependencies]
doc-comment = "0.3"
doc-comment = "0.3"

[lints]
workspace = true
5 changes: 4 additions & 1 deletion crates/nu-json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ serde_json = { workspace = true }
nu-test-support = { path = "../nu-test-support", version = "0.97.2" }
nu-path = { path = "../nu-path", version = "0.97.2" }
serde_json = "1.0"
fancy-regex = "0.13.0"
fancy-regex = "0.13.0"

[lints]
workspace = true
5 changes: 4 additions & 1 deletion crates/nu-lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.97.2" }
nu-command = { path = "../nu-command", version = "0.97.2" }
nu-test-support = { path = "../nu-test-support", version = "0.97.2" }

assert-json-diff = "2.0"
assert-json-diff = "2.0"

[lints]
workspace = true
5 changes: 4 additions & 1 deletion crates/nu-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ exclude = ["/fuzz"]
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-engine = { path = "../nu-engine", version = "0.97.2" }
nu-path = { path = "../nu-path", version = "0.97.2" }
Expand All @@ -27,4 +30,4 @@ serde_json = { workspace = true }
rstest = { workspace = true, default-features = false }

[features]
plugin = ["nu-plugin-engine"]
plugin = ["nu-plugin-engine"]
5 changes: 4 additions & 1 deletion crates/nu-path/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ dirs = { workspace = true }
omnipath = { workspace = true }

[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "android")))'.dependencies]
pwd = { workspace = true }
pwd = { workspace = true }

[lints]
workspace = true
5 changes: 4 additions & 1 deletion crates/nu-plugin-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-protocol = { path = "../nu-protocol", version = "0.97.2" }
nu-plugin-protocol = { path = "../nu-plugin-protocol", version = "0.97.2", default-features = false }
Expand All @@ -25,4 +28,4 @@ default = ["local-socket"]
local-socket = ["interprocess", "nu-plugin-protocol/local-socket"]

[target.'cfg(target_os = "windows")'.dependencies]
windows = { workspace = true }
windows = { workspace = true }
5 changes: 4 additions & 1 deletion crates/nu-plugin-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-engine = { path = "../nu-engine", version = "0.97.2" }
nu-protocol = { path = "../nu-protocol", version = "0.97.2" }
Expand All @@ -32,4 +35,4 @@ local-socket = ["nu-plugin-core/local-socket"]
windows = { workspace = true, features = [
# For setting process creation flags
"Win32_System_Threading",
] }
] }
5 changes: 3 additions & 2 deletions crates/nu-plugin-engine/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ mod tests {
let mut state = test_state();
state.config.enabled = true;
state.config.stop_after = Duration::from_secs(1).as_nanos() as i64;
state.last_update = Some(now - Duration::from_secs(2));
state.last_update = Some(now.checked_sub(Duration::from_secs(2)).unwrap());

assert_eq!(Some(Duration::ZERO), state.next_timeout(now));
}
Expand Down Expand Up @@ -295,7 +295,8 @@ mod tests {
#[test]
fn adding_locks_changes_last_update() {
let mut state = test_state();
let original_last_update = Some(Instant::now() - Duration::from_secs(1));
let original_last_update =
Some(Instant::now().checked_sub(Duration::from_secs(1)).unwrap());
state.last_update = original_last_update;
state.handle_message(PluginGcMsg::AddLocks(1));
assert_ne!(original_last_update, state.last_update, "not updated");
Expand Down
5 changes: 4 additions & 1 deletion crates/nu-plugin-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-protocol = { path = "../nu-protocol", version = "0.97.2", features = ["plugin"] }
nu-utils = { path = "../nu-utils", version = "0.97.2" }
Expand All @@ -21,4 +24,4 @@ typetag = "0.2"

[features]
default = ["local-socket"]
local-socket = []
local-socket = []
5 changes: 4 additions & 1 deletion crates/nu-plugin-test-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ repository = "https://github.com/nushell/nushell/tree/main/crates/nu-plugin-test
[lib]
bench = false

[lints]
workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -25,4 +28,4 @@ similar = "2.6"

[dev-dependencies]
typetag = "0.2"
serde = "1.0"
serde = "1.0"
5 changes: 4 additions & 1 deletion crates/nu-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-engine = { path = "../nu-engine", version = "0.97.2" }
nu-protocol = { path = "../nu-protocol", version = "0.97.2" }
Expand All @@ -30,4 +33,4 @@ local-socket = ["nu-plugin-core/local-socket"]

[target.'cfg(target_family = "unix")'.dependencies]
# For setting the process group ID (EnterForeground / LeaveForeground)
nix = { workspace = true, default-features = false, features = ["process"] }
nix = { workspace = true, default-features = false, features = ["process"] }
5 changes: 4 additions & 1 deletion crates/nu-pretty-hex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ name = "nu_pretty_hex"
path = "src/lib.rs"
bench = false

[lints]
workspace = true

[dependencies]
nu-ansi-term = { workspace = true }

[dev-dependencies]
heapless = { version = "0.8", default-features = false }
rand = "0.8"
rand = "0.8"
5 changes: 4 additions & 1 deletion crates/nu-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ version = "0.97.2"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
nu-utils = { path = "../nu-utils", version = "0.97.2" }
nu-path = { path = "../nu-path", version = "0.97.2" }
Expand Down Expand Up @@ -61,4 +64,4 @@ tempfile = { workspace = true }
os_pipe = { workspace = true }

[package.metadata.docs.rs]
all-features = true
all-features = true
5 changes: 4 additions & 1 deletion crates/nu-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ nu-protocol = { version = "0.97.2", path = "../nu-protocol" }
nu-engine = { version = "0.97.2", path = "../nu-engine" }
miette = { workspace = true, features = ["fancy-no-backtrace"] }

log = "0.4"
log = "0.4"

[lints]
workspace = true
5 changes: 4 additions & 1 deletion crates/nu-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ license = "MIT"
[lib]
bench = false

[lints]
workspace = true

[dependencies]
libc = { workspace = true }
log = { workspace = true }
Expand Down Expand Up @@ -45,4 +48,4 @@ windows = { workspace = true, features = [
"Win32_System_SystemInformation",
"Win32_System_Threading",
"Win32_UI_Shell",
]}
]}
Loading

0 comments on commit 84e1ac2

Please sign in to comment.