Skip to content

Add clippy in CI #2673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ jobs:
- name: Build and run tests (+ 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
# 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
Expand All @@ -101,6 +111,7 @@ jobs:
- rustfmt
- aarch64-cross-builds
- gui
- clippy
runs-on: ubuntu-latest
steps:
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
Expand Down
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[workspace]
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]
name = "mdbook"
version = "0.4.48"
Expand Down Expand Up @@ -91,3 +97,6 @@ test = false
name = "gui"
path = "tests/gui/runner.rs"
crate-type = ["bin"]

[lints]
workspace = true
4 changes: 1 addition & 3 deletions examples/remove-emphasis/test.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use mdbook::MDBook;

#[test]
fn remove_emphasis_works() {
// Tests that the remove-emphasis example works as expected.

// Workaround for https://github.com/rust-lang/mdBook/issues/1424
std::env::set_current_dir("examples/remove-emphasis").unwrap();
let book = MDBook::load(".").unwrap();
let book = mdbook::MDBook::load(".").unwrap();
book.build().unwrap();
let ch1 = std::fs::read_to_string("book/chapter_1.html").unwrap();
assert!(ch1.contains("This has light emphasis and bold emphasis."));
Expand Down
3 changes: 1 addition & 2 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//!
//! [1]: ../index.html

#[allow(clippy::module_inception)]
mod book;
mod init;
mod summary;
Expand Down Expand Up @@ -860,7 +859,7 @@ mod tests {
.and_then(Value::as_str)
.unwrap();
assert_eq!(html, "html");
let html_renderer = HtmlHandlebars::default();
let html_renderer = HtmlHandlebars;
let pre = LinkPreprocessor::new();

let should_run = preprocessor_should_run(&pre, &html_renderer, &cfg);
Expand Down
5 changes: 2 additions & 3 deletions src/book/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<'a> SummaryParser<'a> {

let mut files = HashSet::new();
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 {
Expand All @@ -261,7 +261,6 @@ impl<'a> SummaryParser<'a> {

/// Recursively check for duplicate files in the summary items.
fn check_for_duplicates<'b>(
&self,
items: &'b [SummaryItem],
files: &mut HashSet<&'b PathBuf>,
) -> Result<()> {
Expand All @@ -276,7 +275,7 @@ impl<'a> SummaryParser<'a> {
}
}
// Recursively check nested items
self.check_for_duplicates(&link.nested_items, files)?;
Self::check_for_duplicates(&link.nested_items, files)?;
}
}
Ok(())
Expand Down
1 change: 0 additions & 1 deletion src/preprocess/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ enum RangeOrAnchor {
}

// 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)]
enum LineRange {
Range(Range<usize>),
Expand Down
1 change: 0 additions & 1 deletion src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ impl HtmlHandlebars {
Ok(())
}

#[allow(clippy::let_and_return)]
fn post_process(
&self,
rendered: String,
Expand Down
7 changes: 1 addition & 6 deletions src/renderer/html_handlebars/helpers/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ impl HelperDef for ResourceHelper {
let path_to_root = utils::fs::path_to_root(&base_path);

out.write(&path_to_root)?;
out.write(
self.hash_map
.get(&param[..])
.map(|p| &p[..])
.unwrap_or(&param),
)?;
out.write(self.hash_map.get(param).map(|p| &p[..]).unwrap_or(&param))?;
Ok(())
}
}
1 change: 0 additions & 1 deletion tests/rendered_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ mod search {
}

#[test]
#[allow(clippy::float_cmp)]
fn book_creates_reasonable_search_index() {
let temp = DummyBook::new().build().unwrap();
let md = MDBook::load(temp.path()).unwrap();
Expand Down