Skip to content

Commit

Permalink
build: Use workspace global lints
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cgwalters committed Jul 17, 2024
1 parent 298a336 commit 63bcf63
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 24 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Good defaults
#![forbid(unused_must_use)]
#![deny(unsafe_code)]

use anyhow::Result;

async fn run() -> Result<()> {
Expand Down
2 changes: 2 additions & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ install = []
# Implementation detail of man page generation.
docgen = ["clap_mangen"]

[lints]
workspace = true
4 changes: 0 additions & 4 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 3 additions & 0 deletions tests-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tempfile = { workspace = true }
xshell = { version = "0.2.6" }

[lints]
workspace = true
3 changes: 3 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ fn-error-context = { workspace = true }
tempfile = { workspace = true }
mandown = "0.1.3"
xshell = { version = "0.2.6" }

[lints]
workspace = true
15 changes: 1 addition & 14 deletions xtask/src/xtask.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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),
];

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 63bcf63

Please sign in to comment.