Skip to content

Commit

Permalink
Switch to workspace based lint configuration (#747)
Browse files Browse the repository at this point in the history
As of the Cargo included in Rust 1.74, lints can now be configured
in `Cargo.toml` across whole crates/workspaces:
https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html
https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-lints-section
https://doc.rust-lang.org/stable/cargo/reference/workspaces.html#the-lints-table

This reduces the boilerplate, and chance that we forget to enable
lints in some targets. The only thing we need to remember is to
add the `[lints] workspace = true` to any new crates in the future.

Making this switch exposed a few places where lints weren't enabled
and issues had been missed, eg:
#746

Since this feature requires Rust 1.74, the MSRV has also been bumped.
(Though we will have had to do so soon anyway to be able to start
using `Result::inspect_err`, which is due in Rust 1.76, xref:
#723 (comment))

GUS-W-14511805.
  • Loading branch information
edmorley authored Nov 17, 2023
1 parent 335b351 commit 02f241c
Show file tree
Hide file tree
Showing 47 changed files with 109 additions and 121 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Raised Minimum Supported Rust Version (MSRV) to `1.74`. ([#747](https://github.com/heroku/libcnb.rs/pull/747))
- Improved the consistency of all user-facing libcnb.rs error message wordings. ([#722](https://github.com/heroku/libcnb.rs/pull/722))
- The assistance error message shown when the necessary cross-compilation tools are not found now also includes the `rustup target add` step. ([#729](https://github.com/heroku/libcnb.rs/pull/729))
- Updated the documentation for `TestRunner::build` and `TestContext::start_container` to mention when Docker resource teardown occurs. ([#743](https://github.com/heroku/libcnb.rs/pull/743))
Expand Down
14 changes: 13 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@ members = [

[workspace.package]
version = "0.15.0"
rust-version = "1.64"
rust-version = "1.74"
edition = "2021"
license = "BSD-3-Clause"

[workspace.lints.rust]
unused_crate_dependencies = "warn"

[workspace.lints.clippy]
panic_in_result_fn = "warn"
pedantic = "warn"
unwrap_used = "warn"
# In most cases adding error docs provides little value.
missing_errors_doc = "allow"
# This lint is too noisy and enforces a style that reduces readability in many cases.
module_name_repetitions = "allow"

[workspace.dependencies]
libcnb = { version = "=0.15.0", path = "libcnb" }
libcnb-common = { version = "=0.15.0", path = "libcnb-common" }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[docs.rs]: https://docs.rs/libcnb/latest/libcnb/
[Latest Version]: https://img.shields.io/crates/v/libcnb.svg
[crates.io]: https://crates.io/crates/libcnb
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.64+-lightgray.svg
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg
[install-rust]: https://www.rust-lang.org/tools/install

`libcnb.rs` is a framework for writing [Cloud Native Buildpacks](https://buildpacks.io) in Rust.
Expand Down
3 changes: 3 additions & 0 deletions examples/basics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ edition.workspace = true
rust-version.workspace = true
publish = false

[lints]
workspace = true

[dependencies]
libcnb.workspace = true
4 changes: 0 additions & 4 deletions examples/basics/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Enable Clippy lints that are disabled by default.
// https://rust-lang.github.io/rust-clippy/stable/index.html
#![warn(clippy::pedantic)]

use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder};
use libcnb::detect::{DetectContext, DetectResult, DetectResultBuilder};
use libcnb::generic::{GenericError, GenericMetadata, GenericPlatform};
Expand Down
3 changes: 3 additions & 0 deletions examples/execd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ edition.workspace = true
rust-version.workspace = true
publish = false

[lints]
workspace = true

[dependencies]
libcnb.workspace = true
fastrand = "2.0.0"
Expand Down
8 changes: 4 additions & 4 deletions examples/execd/src/bin/dice_roller.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Enable Clippy lints that are disabled by default.
// https://rust-lang.github.io/rust-clippy/stable/index.html
#![warn(clippy::pedantic)]

use libcnb::data::exec_d::ExecDProgramOutputKey;
use libcnb::data::exec_d_program_output_key;
use libcnb::exec_d::write_exec_d_program_output;
use std::collections::HashMap;
use std::iter;

// Suppress warnings due to the `unused_crate_dependencies` lint not handling integration tests well.
#[cfg(test)]
use libcnb_test as _;

fn main() {
write_exec_d_program_output(env_vars());
}
Expand Down
11 changes: 5 additions & 6 deletions examples/execd/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// Enable Clippy lints that are disabled by default.
// https://rust-lang.github.io/rust-clippy/stable/index.html
#![warn(clippy::pedantic)]
// This lint is too noisy and enforces a style that reduces readability in many cases.
#![allow(clippy::module_name_repetitions)]

mod layer;

use crate::layer::ExecDLayer;
Expand All @@ -13,6 +7,11 @@ use libcnb::detect::{DetectContext, DetectResult, DetectResultBuilder};
use libcnb::generic::{GenericError, GenericMetadata, GenericPlatform};
use libcnb::{buildpack_main, Buildpack};

// Suppress warnings due to the `unused_crate_dependencies` lint not handling integration tests well.
use fastrand as _;
#[cfg(test)]
use libcnb_test as _;

pub(crate) struct ExecDBuildpack;

impl Buildpack for ExecDBuildpack {
Expand Down
5 changes: 2 additions & 3 deletions examples/execd/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! All integration tests are skipped by default (using the `ignore` attribute)
//! since performing builds is slow. To run them use: `cargo test -- --ignored`.

// Enable Clippy lints that are disabled by default.
// https://rust-lang.github.io/rust-clippy/stable/index.html
#![warn(clippy::pedantic)]
// Required due to: https://github.com/rust-lang/rust/issues/95513
#![allow(unused_crate_dependencies)]

use libcnb_test::{assert_contains, assert_empty, BuildConfig, TestRunner};

Expand Down
3 changes: 3 additions & 0 deletions examples/ruby-sample/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ edition.workspace = true
rust-version.workspace = true
publish = false

[lints]
workspace = true

[dependencies]
flate2 = { version = "1.0.27", default-features = false, features = ["zlib"] }
libcnb.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions examples/ruby-sample/src/layers/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ impl Layer for BundlerLayer {
}
}

// TODO: Remove use of unwrap(): https://github.com/heroku/libcnb.rs/issues/746
#[allow(clippy::unwrap_used)]
fn create(
&self,
context: &BuildContext<Self::Buildpack>,
Expand Down Expand Up @@ -84,6 +86,8 @@ impl Layer for BundlerLayer {
})
}

// TODO: Remove use of unwrap(): https://github.com/heroku/libcnb.rs/issues/746
#[allow(clippy::unwrap_used)]
fn update(
&self,
context: &BuildContext<Self::Buildpack>,
Expand Down
10 changes: 4 additions & 6 deletions examples/ruby-sample/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// Enable Clippy lints that are disabled by default.
// https://rust-lang.github.io/rust-clippy/stable/index.html
#![warn(clippy::pedantic)]
// This lint is too noisy and enforces a style that reduces readability in many cases.
#![allow(clippy::module_name_repetitions)]

use crate::layers::{BundlerLayer, RubyLayer};
use crate::util::{DownloadError, UntarError};
use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder};
Expand All @@ -16,6 +10,10 @@ use libcnb::{buildpack_main, Buildpack};
use serde::Deserialize;
use std::process::ExitStatus;

// Suppress warnings due to the `unused_crate_dependencies` lint not handling integration tests well.
#[cfg(test)]
use libcnb_test as _;

mod layers;
mod util;

Expand Down
5 changes: 2 additions & 3 deletions examples/ruby-sample/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! All integration tests are skipped by default (using the `ignore` attribute)
//! since performing builds is slow. To run them use: `cargo test -- --ignored`.

// Enable Clippy lints that are disabled by default.
// https://rust-lang.github.io/rust-clippy/stable/index.html
#![warn(clippy::pedantic)]
// Required due to: https://github.com/rust-lang/rust/issues/95513
#![allow(unused_crate_dependencies)]

use libcnb_test::{
assert_contains, assert_not_contains, BuildConfig, ContainerConfig, PackResult, TestRunner,
Expand Down
3 changes: 3 additions & 0 deletions libcnb-cargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ include = ["src/**/*", "LICENSE", "README.md"]
name = "cargo-libcnb"
path = "src/main.rs"

[lints]
workspace = true

[dependencies]
clap = { version = "4.3.24", default-features = false, features = [
"derive",
Expand Down
2 changes: 1 addition & 1 deletion libcnb-cargo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ pack build my-image-name \

[Latest Version]: https://img.shields.io/crates/v/libcnb-cargo.svg
[crates.io]: https://crates.io/crates/libcnb-cargo
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.64+-lightgray.svg
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg
[install-rust]: https://www.rust-lang.org/tools/install
6 changes: 0 additions & 6 deletions libcnb-cargo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(unused_crate_dependencies)]
#![warn(clippy::pedantic)]
#![warn(clippy::panic_in_result_fn)]
#![warn(clippy::unwrap_used)]
// This lint is too noisy and enforces a style that reduces readability in many cases.
#![allow(clippy::module_name_repetitions)]

// Suppress warnings due to the `unused_crate_dependencies` lint not handling integration tests well.
#[cfg(test)]
Expand Down
9 changes: 6 additions & 3 deletions libcnb-cargo/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! All integration tests are skipped by default (using the `ignore` attribute)
//! since performing builds is slow. To run them use: `cargo test -- --ignored`.

// Enable Clippy lints that are disabled by default.
// https://rust-lang.github.io/rust-clippy/stable/index.html
#![warn(clippy::pedantic)]
// Required due to: https://github.com/rust-lang/rust/issues/95513
#![allow(unused_crate_dependencies)]

use libcnb_common::toml_file::read_toml_file;
use libcnb_data::buildpack::{BuildpackDescriptor, BuildpackId};
Expand Down Expand Up @@ -276,6 +275,8 @@ fn package_command_respects_ignore_files() {
);
}

// Allow required due to: https://github.com/rust-lang/rust-clippy/issues/11119
#[allow(clippy::unwrap_used)]
fn validate_packaged_buildpack(packaged_buildpack_dir: &Path, buildpack_id: &BuildpackId) {
assert!(packaged_buildpack_dir.join("buildpack.toml").exists());
assert!(packaged_buildpack_dir.join("package.toml").exists());
Expand All @@ -291,6 +292,8 @@ fn validate_packaged_buildpack(packaged_buildpack_dir: &Path, buildpack_id: &Bui
);
}

// Allow required due to: https://github.com/rust-lang/rust-clippy/issues/11119
#[allow(clippy::unwrap_used)]
fn validate_packaged_composite_buildpack(
packaged_buildpack_dir: &Path,
buildpack_id: &BuildpackId,
Expand Down
3 changes: 3 additions & 0 deletions libcnb-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ documentation = "https://docs.rs/libcnb-common"
readme = "README.md"
include = ["src/**/*", "LICENSE", "README.md"]

[lints]
workspace = true

[dependencies]
serde = { version = "1.0.188", features = ["derive"] }
thiserror = "1.0.48"
Expand Down
2 changes: 1 addition & 1 deletion libcnb-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ This is an internal crate and should not be used by users directly. There are no
[docs.rs]: https://docs.rs/libcnb-proc-macros/latest/libcnb_common/
[Latest Version]: https://img.shields.io/crates/v/libcnb-common.svg
[crates.io]: https://crates.io/crates/libcnb-common
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.64+-lightgray.svg
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg
[install-rust]: https://www.rust-lang.org/tools/install
6 changes: 0 additions & 6 deletions libcnb-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#![doc = include_str!("../README.md")]
#![warn(unused_crate_dependencies)]
#![warn(clippy::pedantic)]
#![warn(clippy::panic_in_result_fn)]
#![warn(clippy::unwrap_used)]
// This lint is too noisy and enforces a style that reduces readability in many cases.
#![allow(clippy::module_name_repetitions)]

pub mod toml_file;
3 changes: 3 additions & 0 deletions libcnb-data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ documentation = "https://docs.rs/libcnb-data"
readme = "README.md"
include = ["src/**/*", "LICENSE", "README.md"]

[lints]
workspace = true

[dependencies]
fancy-regex = { version = "0.12.0", default-features = false, features = ["std"] }
libcnb-proc-macros.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion libcnb-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ on this crate directly.
[docs.rs]: https://docs.rs/libcnb-data/latest/libcnb_data/
[Latest Version]: https://img.shields.io/crates/v/libcnb-data.svg
[crates.io]: https://crates.io/crates/libcnb-data
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.64+-lightgray.svg
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg
[install-rust]: https://www.rust-lang.org/tools/install
6 changes: 0 additions & 6 deletions libcnb-data/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(unused_crate_dependencies)]
#![warn(clippy::pedantic)]
#![warn(clippy::panic_in_result_fn)]
#![warn(clippy::unwrap_used)]
// This lint is too noisy and enforces a style that reduces readability in many cases.
#![allow(clippy::module_name_repetitions)]

pub mod build;
pub mod build_plan;
Expand Down
3 changes: 3 additions & 0 deletions libcnb-package/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ documentation = "https://docs.rs/libcnb-package"
readme = "README.md"
include = ["src/**/*", "LICENSE", "README.md"]

[lints]
workspace = true

[dependencies]
cargo_metadata = "0.18.0"
ignore = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion libcnb-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ directly.
[docs.rs]: https://docs.rs/libcnb-package/latest/libcnb_package/
[Latest Version]: https://img.shields.io/crates/v/libcnb-package.svg
[crates.io]: https://crates.io/crates/libcnb-package
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.64+-lightgray.svg
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg
[install-rust]: https://www.rust-lang.org/tools/install
6 changes: 0 additions & 6 deletions libcnb-package/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(unused_crate_dependencies)]
#![warn(clippy::pedantic)]
#![warn(clippy::panic_in_result_fn)]
#![warn(clippy::unwrap_used)]
// This lint is too noisy and enforces a style that reduces readability in many cases.
#![allow(clippy::module_name_repetitions)]

pub mod build;
pub mod buildpack_dependency_graph;
Expand Down
3 changes: 3 additions & 0 deletions libcnb-proc-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ include = ["src/**/*", "LICENSE", "README.md"]
[lib]
proc-macro = true

[lints]
workspace = true

[dependencies]
cargo_metadata = "0.18.0"
fancy-regex = { version = "0.12.0", default-features = false, features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion libcnb-proc-macros/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ depending on this crate directly.
[docs.rs]: https://docs.rs/libcnb-proc-macros/latest/libcnb_proc_macros/
[Latest Version]: https://img.shields.io/crates/v/libcnb-proc-macros.svg
[crates.io]: https://crates.io/crates/libcnb-proc-macros
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.64+-lightgray.svg
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg
[install-rust]: https://www.rust-lang.org/tools/install
4 changes: 0 additions & 4 deletions libcnb-proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#![doc = include_str!("../README.md")]
#![warn(unused_crate_dependencies)]
#![warn(clippy::pedantic)]
#![warn(clippy::panic_in_result_fn)]
#![warn(clippy::unwrap_used)]

use proc_macro::TokenStream;
use quote::quote;
Expand Down
3 changes: 3 additions & 0 deletions libcnb-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ documentation = "https://docs.rs/libcnb-test"
readme = "README.md"
include = ["src/**/*", "LICENSE", "README.md"]

[lints]
workspace = true

[dependencies]
fastrand = "2.0.0"
fs_extra = "1.3.0"
Expand Down
2 changes: 1 addition & 1 deletion libcnb-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,5 @@ fn additional_buildpacks() {
[docs.rs]: https://docs.rs/libcnb-test/latest/libcnb_test/
[Latest Version]: https://img.shields.io/crates/v/libcnb-test.svg
[crates.io]: https://crates.io/crates/libcnb-test
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.64+-lightgray.svg
[MSRV]: https://img.shields.io/badge/MSRV-rustc_1.74+-lightgray.svg
[install-rust]: https://www.rust-lang.org/tools/install
7 changes: 0 additions & 7 deletions libcnb-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
#![doc = include_str!("../README.md")]
// Enable lints that are disabled by default.
#![warn(unused_crate_dependencies)]
#![warn(clippy::pedantic)]
#![warn(clippy::panic_in_result_fn)]
#![warn(clippy::unwrap_used)]
// This lint is too noisy and enforces a style that reduces readability in many cases.
#![allow(clippy::module_name_repetitions)]

mod app;
mod build;
Expand Down
5 changes: 2 additions & 3 deletions libcnb-test/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
//! to test dynamic values, in which case the only option is to use `panic::catch_unwind`
//! since `should_panic` doesn't support globs/regular expressions/compile time macros.

// Enable Clippy lints that are disabled by default.
// https://rust-lang.github.io/rust-clippy/stable/index.html
#![warn(clippy::pedantic)]
// Required due to: https://github.com/rust-lang/rust/issues/95513
#![allow(unused_crate_dependencies)]

use indoc::{formatdoc, indoc};
use libcnb_data::buildpack_id;
Expand Down
3 changes: 3 additions & 0 deletions libcnb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ documentation = "https://docs.rs/libcnb"
readme = "README.md"
include = ["src/**/*", "LICENSE", "README.md"]

[lints]
workspace = true

[dependencies]
anyhow = { version = "1.0.75", optional = true }
cyclonedx-bom = { version = "0.4.0", optional = true }
Expand Down
Loading

0 comments on commit 02f241c

Please sign in to comment.