Merge pull request #2673 from ehuss/clippy

Add clippy in CI
This commit is contained in:
Eric Huss 2025-04-21 02:32:31 +00:00 committed by GitHub
commit c948fe4d6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 25 additions and 17 deletions

View file

@ -88,6 +88,16 @@ jobs:
- name: Build and run tests (+ GUI) - name: Build and run tests (+ GUI)
run: cargo test --locked --target x86_64-unknown-linux-gnu --test gui run: cargo test --locked --target x86_64-unknown-linux-gnu --test gui
# Ensure there are no clippy warnings
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: bash ci/install-rust.sh stable x86_64-unknown-linux-gnu
- run: rustup component add clippy
- run: cargo clippy --workspace --all-targets --no-deps -- -D warnings
# The success job is here to consolidate the total success/failure state of # The success job is here to consolidate the total success/failure state of
# all other jobs. This job is then included in the GitHub branch protection # all other jobs. This job is then included in the GitHub branch protection
# rule which prevents merges unless all other jobs are passing. This makes # rule which prevents merges unless all other jobs are passing. This makes
@ -101,6 +111,7 @@ jobs:
- rustfmt - rustfmt
- aarch64-cross-builds - aarch64-cross-builds
- gui - gui
- clippy
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}' - run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'

View file

@ -1,6 +1,12 @@
[workspace] [workspace]
members = [".", "examples/remove-emphasis/mdbook-remove-emphasis"] members = [".", "examples/remove-emphasis/mdbook-remove-emphasis"]
[workspace.lints.clippy]
all = { level = "allow", priority = -2 }
correctness = { level = "warn", priority = -1 }
complexity = { level = "warn", priority = -1 }
needless-lifetimes = "allow" # Remove once 1.87 is stable, https://github.com/rust-lang/rust-clippy/issues/13514
[package] [package]
name = "mdbook" name = "mdbook"
version = "0.4.48" version = "0.4.48"
@ -91,3 +97,6 @@ test = false
name = "gui" name = "gui"
path = "tests/gui/runner.rs" path = "tests/gui/runner.rs"
crate-type = ["bin"] crate-type = ["bin"]
[lints]
workspace = true

View file

@ -1,12 +1,10 @@
use mdbook::MDBook;
#[test] #[test]
fn remove_emphasis_works() { fn remove_emphasis_works() {
// Tests that the remove-emphasis example works as expected. // Tests that the remove-emphasis example works as expected.
// Workaround for https://github.com/rust-lang/mdBook/issues/1424 // Workaround for https://github.com/rust-lang/mdBook/issues/1424
std::env::set_current_dir("examples/remove-emphasis").unwrap(); std::env::set_current_dir("examples/remove-emphasis").unwrap();
let book = MDBook::load(".").unwrap(); let book = mdbook::MDBook::load(".").unwrap();
book.build().unwrap(); book.build().unwrap();
let ch1 = std::fs::read_to_string("book/chapter_1.html").unwrap(); let ch1 = std::fs::read_to_string("book/chapter_1.html").unwrap();
assert!(ch1.contains("This has light emphasis and bold emphasis.")); assert!(ch1.contains("This has light emphasis and bold emphasis."));

View file

@ -5,7 +5,6 @@
//! //!
//! [1]: ../index.html //! [1]: ../index.html
#[allow(clippy::module_inception)]
mod book; mod book;
mod init; mod init;
mod summary; mod summary;
@ -860,7 +859,7 @@ mod tests {
.and_then(Value::as_str) .and_then(Value::as_str)
.unwrap(); .unwrap();
assert_eq!(html, "html"); assert_eq!(html, "html");
let html_renderer = HtmlHandlebars::default(); let html_renderer = HtmlHandlebars;
let pre = LinkPreprocessor::new(); let pre = LinkPreprocessor::new();
let should_run = preprocessor_should_run(&pre, &html_renderer, &cfg); let should_run = preprocessor_should_run(&pre, &html_renderer, &cfg);

View file

@ -248,7 +248,7 @@ impl<'a> SummaryParser<'a> {
let mut files = HashSet::new(); let mut files = HashSet::new();
for part in [&prefix_chapters, &numbered_chapters, &suffix_chapters] { for part in [&prefix_chapters, &numbered_chapters, &suffix_chapters] {
self.check_for_duplicates(&part, &mut files)?; Self::check_for_duplicates(&part, &mut files)?;
} }
Ok(Summary { Ok(Summary {
@ -261,7 +261,6 @@ impl<'a> SummaryParser<'a> {
/// Recursively check for duplicate files in the summary items. /// Recursively check for duplicate files in the summary items.
fn check_for_duplicates<'b>( fn check_for_duplicates<'b>(
&self,
items: &'b [SummaryItem], items: &'b [SummaryItem],
files: &mut HashSet<&'b PathBuf>, files: &mut HashSet<&'b PathBuf>,
) -> Result<()> { ) -> Result<()> {
@ -276,7 +275,7 @@ impl<'a> SummaryParser<'a> {
} }
} }
// Recursively check nested items // Recursively check nested items
self.check_for_duplicates(&link.nested_items, files)?; Self::check_for_duplicates(&link.nested_items, files)?;
} }
} }
Ok(()) Ok(())

View file

@ -148,7 +148,6 @@ enum RangeOrAnchor {
} }
// A range of lines specified with some include directive. // A range of lines specified with some include directive.
#[allow(clippy::enum_variant_names)] // The prefix can't be removed, and is meant to mirror the contained type
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Debug, Clone)]
enum LineRange { enum LineRange {
Range(Range<usize>), Range(Range<usize>),

View file

@ -207,7 +207,6 @@ impl HtmlHandlebars {
Ok(()) Ok(())
} }
#[allow(clippy::let_and_return)]
fn post_process( fn post_process(
&self, &self,
rendered: String, rendered: String,

View file

@ -39,12 +39,7 @@ impl HelperDef for ResourceHelper {
let path_to_root = utils::fs::path_to_root(&base_path); let path_to_root = utils::fs::path_to_root(&base_path);
out.write(&path_to_root)?; out.write(&path_to_root)?;
out.write( out.write(self.hash_map.get(param).map(|p| &p[..]).unwrap_or(&param))?;
self.hash_map
.get(&param[..])
.map(|p| &p[..])
.unwrap_or(&param),
)?;
Ok(()) Ok(())
} }
} }

View file

@ -780,7 +780,6 @@ mod search {
} }
#[test] #[test]
#[allow(clippy::float_cmp)]
fn book_creates_reasonable_search_index() { fn book_creates_reasonable_search_index() {
let temp = DummyBook::new().build().unwrap(); let temp = DummyBook::new().build().unwrap();
let md = MDBook::load(temp.path()).unwrap(); let md = MDBook::load(temp.path()).unwrap();