Skip to content

Commit 9f58751

Browse files
committed
refactor: enable more clippy rules
1 parent 0e3bc44 commit 9f58751

37 files changed

+546
-372
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ env:
1212
RUST_BACKTRACE: 1
1313

1414
jobs:
15-
# Code quality checks
16-
quality:
17-
name: Quality Checks
15+
common-quality:
16+
name: Common Quality Checks
1817
runs-on: ubuntu-latest
1918
steps:
2019
- uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
@@ -23,15 +22,8 @@ jobs:
2322
with:
2423
save-cache: ${{ github.ref_name == 'main' }}
2524
cache-key: warm
26-
components: clippy rustfmt
2725
tools: typos-cli,cargo-deny,cargo-shear
2826

29-
- name: Check formatting
30-
run: cargo fmt --all -- --check
31-
32-
- name: Clippy
33-
run: cargo clippy --all-targets --all-features -- -D warnings
34-
3527
- name: Check for typos
3628
run: typos
3729

@@ -41,6 +33,30 @@ jobs:
4133
- name: Run cargo-shear
4234
run: cargo shear
4335

36+
# Code quality checks
37+
quality:
38+
name: Quality Checks ${{ matrix.os }}
39+
runs-on: ${{ matrix.os }}
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
os: [ubuntu-latest, macos-latest, windows-latest]
44+
steps:
45+
- uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
46+
47+
- uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0
48+
with:
49+
save-cache: ${{ github.ref_name == 'main' }}
50+
cache-key: warm
51+
components: clippy rustfmt
52+
tools: typos-cli,cargo-deny,cargo-shear
53+
54+
- name: Check formatting
55+
run: cargo fmt -- --check
56+
57+
- name: Clippy
58+
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
59+
4460
# Test on multiple platforms with different Rust versions
4561
test:
4662
name: Test ${{ matrix.os }} ${{ matrix.features != '' && format('({0})', matrix.features) || '' }}

Cargo.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,64 @@ homepage = "https://github.com/notify-rs/notify"
1818
repository = "https://github.com/notify-rs/notify.git"
1919
edition = "2024"
2020

21+
[workspace.lints.clippy]
22+
# Guidelines
23+
# - We should only disable rules globally if they are either false positives, chaotic, or does not make sense.
24+
# - Group are enabled with priority -1, so we could easily override some specific rules.
25+
# - https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-lints-section
26+
27+
# --- restriction https://doc.rust-lang.org/clippy/usage.html#clippyrestriction
28+
allow_attributes = "deny"
29+
dbg_macro = "deny"
30+
print_stdout = "deny"
31+
32+
# I like the explicitness of this rule as it removes confusion around `clone`.
33+
# This increases readability, avoids `clone` mindlessly and heap allocating on accident.
34+
clone_on_ref_ptr = "deny"
35+
empty_drop = "deny"
36+
exit = "deny"
37+
filetype_is_file = "deny"
38+
get_unwrap = "deny"
39+
rc_buffer = "deny"
40+
rc_mutex = "deny"
41+
rest_pat_in_fully_bound_structs = "deny"
42+
unnecessary_safety_comment = "deny"
43+
44+
# --- pedantic #https://doc.rust-lang.org/clippy/usage.html#clippypedantic
45+
# To write the best rust code, pedantic group is enabled by default.
46+
pedantic = { level = "deny", priority = -1 }
47+
case_sensitive_file_extension_comparisons = "allow"
48+
49+
# Though the following are nursery rules, they’re still useful.
50+
debug_assert_with_mut_call = "warn"
51+
iter_on_single_items = "warn"
52+
needless_pass_by_ref_mut = "warn"
53+
redundant_clone = "warn"
54+
redundant_pub_crate = "warn"
55+
significant_drop_in_scrutinee = "warn"
56+
unused_peekable = "warn"
57+
58+
# Wizards, naming is too hard.
59+
module_inception = "allow"
60+
module_name_repetitions = "allow"
61+
similar_names = "allow"
62+
struct_field_names = "allow"
63+
# Forwarding `Result` is a common pattern, this rule is too pedantic.
64+
missing_errors_doc = "allow"
65+
doc_markdown = "allow"
66+
inline_always = "allow"
67+
wildcard_imports = "allow"
68+
redundant_closure_for_method_calls = "allow"
69+
items_after_statements = "allow"
70+
redundant-pub-crate = "allow"
71+
# Order doesn't really matter https://rust-lang.github.io/rust-clippy/master/index.html#/inconsistent_struct_constructor
72+
inconsistent_struct_constructor = "allow"
73+
# Single match is equally readable as if/else. https://rust-lang.github.io/rust-clippy/master/index.html#/single_match
74+
single_match = "allow"
75+
single_match_else = "allow"
76+
# Rewriting `unwrap_or` to `map_or` requires to annotate type explicitly which is cumbersome
77+
map_unwrap_or = "allow"
78+
2179
[workspace.dependencies]
2280
bitflags = "2.7.0"
2381
crossbeam-channel = "0.5.0"

clippy.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ publish = false
55
edition = "2024"
66
license = "MIT OR Apache-2.0"
77

8+
[lints]
9+
workspace = true
10+
811
[dev-dependencies]
912
rolldown-notify = { workspace = true }
1013
rolldown-notify-debouncer-mini = { workspace = true }

examples/async_monitor.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::print_stdout)]
2+
13
use futures::{
24
SinkExt, StreamExt,
35
channel::mpsc::{Receiver, channel},
@@ -10,11 +12,11 @@ fn main() {
1012
let path = std::env::args()
1113
.nth(1)
1214
.expect("Argument 1 needs to be a path");
13-
println!("watching {}", path);
15+
println!("watching {path}");
1416

1517
futures::executor::block_on(async {
1618
if let Err(e) = async_watch(path).await {
17-
println!("error: {:?}", e)
19+
println!("error: {e:?}");
1820
}
1921
});
2022
}
@@ -28,7 +30,7 @@ fn async_watcher() -> notify::Result<(RecommendedWatcher, Receiver<notify::Resul
2830
move |res| {
2931
futures::executor::block_on(async {
3032
tx.send(res).await.unwrap();
31-
})
33+
});
3234
},
3335
Config::default(),
3436
)?;
@@ -45,8 +47,8 @@ async fn async_watch<P: AsRef<Path>>(path: P) -> notify::Result<()> {
4547

4648
while let Some(res) = rx.next().await {
4749
match res {
48-
Ok(event) => println!("changed: {:?}", event),
49-
Err(e) => println!("watch error: {:?}", e),
50+
Ok(event) => println!("changed: {event:?}"),
51+
Err(e) => println!("watch error: {e:?}"),
5052
}
5153
}
5254

examples/debouncer_full.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::print_stdout)]
2+
13
use std::{fs, thread, time::Duration};
24

35
use notify::WatchMode;

examples/debouncer_mini_custom.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::print_stdout)]
2+
13
use std::{path::Path, time::Duration};
24

35
use notify::{self, WatchMode};

examples/poll_sysfs.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![allow(clippy::print_stdout)]
2+
#![cfg_attr(target_os = "windows", expect(clippy::unnecessary_wraps))]
3+
14
/// Example for watching kernel internal filesystems like `/sys` and `/proc`
25
/// These can't be watched by the default backend or unconfigured pollwatcher
36
/// This example can't be demonstrated under windows, it might be relevant for network shares
@@ -17,16 +20,17 @@ fn not_windows_main() -> notify::Result<()> {
1720
eprintln!(
1821
"Must provide path to watch, default system path was not found (probably you're not running on Linux?)"
1922
);
23+
#[expect(clippy::exit)]
2024
std::process::exit(1);
2125
}
2226
println!(
23-
"Trying {:?}, use `ping localhost` to see changes!",
24-
lo_stats
27+
"Trying {}, use `ping localhost` to see changes!",
28+
lo_stats.display()
2529
);
2630
paths.push(lo_stats);
2731
}
2832

29-
println!("watching {:?}...", paths);
33+
println!("watching {paths:?}...");
3034
// configure pollwatcher backend
3135
let config = Config::default()
3236
.with_compare_contents(true) // crucial part for pseudo filesystems
@@ -43,8 +47,8 @@ fn not_windows_main() -> notify::Result<()> {
4347
// print all events, never returns
4448
for res in rx {
4549
match res {
46-
Ok(event) => println!("changed: {:?}", event),
47-
Err(e) => println!("watch error: {:?}", e),
50+
Ok(event) => println!("changed: {event:?}"),
51+
Err(e) => println!("watch error: {e:?}"),
4852
}
4953
}
5054

examples/pollwatcher_manual.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::print_stdout)]
2+
13
use notify::{Config, PollWatcher, WatchMode, Watcher};
24
use std::path::Path;
35
use tracing_subscriber::{EnvFilter, fmt, layer::SubscriberExt, util::SubscriberInitExt};
@@ -34,8 +36,8 @@ fn watch<P: AsRef<Path>>(path: P) -> notify::Result<()> {
3436
std::thread::spawn(move || {
3537
for res in rx {
3638
match res {
37-
Ok(event) => println!("changed: {:?}", event),
38-
Err(e) => println!("watch error: {:?}", e),
39+
Ok(event) => println!("changed: {event:?}"),
40+
Err(e) => println!("watch error: {e:?}"),
3941
}
4042
}
4143
});

examples/pollwatcher_scan.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::print_stdout)]
2+
13
use notify::{Config, PollWatcher, WatchMode, Watcher, poll::ScanEvent};
24
use std::path::Path;
35
use tracing_subscriber::{EnvFilter, fmt, layer::SubscriberExt, util::SubscriberInitExt};

0 commit comments

Comments
 (0)