From 63bcf638686ea70ecf6b69f2ea67b8bbdacbad5c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 17 Jul 2024 13:31:07 -0400 Subject: [PATCH] build: Use workspace global lints In relatively recent rust there's a nice way to globally configure clippy lints for the whole workspace. We can kill the `custom-lints` target because relatively recently clippy has a lint for `todo!` and `dbg!` itself. Signed-off-by: Colin Walters --- .github/workflows/ci.yml | 2 -- Cargo.toml | 11 +++++++++++ cli/Cargo.toml | 3 +++ cli/src/main.rs | 4 ---- lib/Cargo.toml | 2 ++ lib/src/lib.rs | 4 ---- tests-integration/Cargo.toml | 3 +++ xtask/Cargo.toml | 3 +++ xtask/src/xtask.rs | 15 +-------------- 9 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d81bae17c..9fda0f2ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,8 +41,6 @@ jobs: run: cd lib && cargo check --no-default-features - name: Individual checks run: (cd cli && cargo check) && (cd lib && cargo check) - - name: Lints - run: cargo xtask custom-lints - name: Run tests run: cargo test -- --nocapture --quiet - name: Manpage generation diff --git a/Cargo.toml b/Cargo.toml index 192c9960f..16bc920bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,3 +47,14 @@ exclude-crate-paths = [ { name = "libz-sys", exclude = "src/zlib" }, { name = "k8s-openapi", exclude = "src/v1_25" }, { name = "k8s-openapi", exclude = "src/v1_27" }, ] + +[workspace.lints.rust] +# Require an extra opt-in for unsafe +unsafe_code = "deny" +# Absolutely must handle errors +unused_must_use = "forbid" + +[workspace.lints.clippy] +# These should only be in local code +dbg_macro = "deny" +todo = "deny" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 5d7072100..ff2af2411 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -24,3 +24,6 @@ tokio = { workspace = true, features = ["macros"] } log = "0.4.21" tracing = { workspace = true } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } + +[lints] +workspace = true diff --git a/cli/src/main.rs b/cli/src/main.rs index 4a4d423d4..a8fc7a824 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,7 +1,3 @@ -// Good defaults -#![forbid(unused_must_use)] -#![deny(unsafe_code)] - use anyhow::Result; async fn run() -> Result<()> { diff --git a/lib/Cargo.toml b/lib/Cargo.toml index e47ea0fe0..62fb4f00b 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -58,3 +58,5 @@ install = [] # Implementation detail of man page generation. docgen = ["clap_mangen"] +[lints] +workspace = true diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 600856f9d..ed3a82d73 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -7,11 +7,7 @@ // See https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html #![deny(missing_docs)] #![deny(missing_debug_implementations)] -#![forbid(unused_must_use)] -#![deny(unsafe_code)] #![cfg_attr(feature = "dox", feature(doc_cfg))] -#![deny(clippy::dbg_macro)] -#![deny(clippy::todo)] // These two are in my experience the lints which are most likely // to trigger, and among the least valuable to fix. #![allow(clippy::needless_borrow)] diff --git a/tests-integration/Cargo.toml b/tests-integration/Cargo.toml index 62ffdcaa7..7a07fdc55 100644 --- a/tests-integration/Cargo.toml +++ b/tests-integration/Cargo.toml @@ -24,3 +24,6 @@ serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } tempfile = { workspace = true } xshell = { version = "0.2.6" } + +[lints] +workspace = true diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index b856ac42f..724e17d15 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -19,3 +19,6 @@ fn-error-context = { workspace = true } tempfile = { workspace = true } mandown = "0.1.3" xshell = { version = "0.2.6" } + +[lints] +workspace = true diff --git a/xtask/src/xtask.rs b/xtask/src/xtask.rs index 549ece541..b1eb004d7 100644 --- a/xtask/src/xtask.rs +++ b/xtask/src/xtask.rs @@ -1,5 +1,5 @@ use std::fs::File; -use std::io::{BufRead, BufReader, BufWriter, Cursor, Write}; +use std::io::{BufRead, BufReader, BufWriter, Write}; use std::process::{Command, Stdio}; use anyhow::{anyhow, Context, Result}; @@ -23,7 +23,6 @@ const TASKS: &[(&str, fn(&Shell) -> Result<()>)] = &[ ("package", package), ("package-srpm", package_srpm), ("spec", spec), - ("custom-lints", custom_lints), ("test-tmt", test_tmt), ]; @@ -356,18 +355,6 @@ fn package_srpm(sh: &Shell) -> Result<()> { Ok(()) } -fn custom_lints(sh: &Shell) -> Result<()> { - // Verify there are no invocations of the dbg macro. - let o = cmd!(sh, "git grep dbg\x21 *.rs").ignore_status().read()?; - if !o.is_empty() { - let mut stderr = std::io::stderr().lock(); - std::io::copy(&mut Cursor::new(o.as_bytes()), &mut stderr)?; - eprintln!(); - anyhow::bail!("Found dbg\x21 macro"); - } - Ok(()) -} - fn print_help(_sh: &Shell) -> Result<()> { println!("Tasks:"); for (name, _) in TASKS {