Skip to content

Commit c948fe4

Browse files
authored
Merge pull request #2673 from ehuss/clippy
Add clippy in CI
2 parents 14aeb0c + b0ef5a5 commit c948fe4

File tree

9 files changed

+25
-17
lines changed

9 files changed

+25
-17
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ jobs:
8888
- name: Build and run tests (+ GUI)
8989
run: cargo test --locked --target x86_64-unknown-linux-gnu --test gui
9090

91+
# Ensure there are no clippy warnings
92+
clippy:
93+
runs-on: ubuntu-latest
94+
steps:
95+
- uses: actions/checkout@v4
96+
- name: Install Rust
97+
run: bash ci/install-rust.sh stable x86_64-unknown-linux-gnu
98+
- run: rustup component add clippy
99+
- run: cargo clippy --workspace --all-targets --no-deps -- -D warnings
100+
91101
# The success job is here to consolidate the total success/failure state of
92102
# all other jobs. This job is then included in the GitHub branch protection
93103
# rule which prevents merges unless all other jobs are passing. This makes
@@ -101,6 +111,7 @@ jobs:
101111
- rustfmt
102112
- aarch64-cross-builds
103113
- gui
114+
- clippy
104115
runs-on: ubuntu-latest
105116
steps:
106117
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
[workspace]
22
members = [".", "examples/remove-emphasis/mdbook-remove-emphasis"]
33

4+
[workspace.lints.clippy]
5+
all = { level = "allow", priority = -2 }
6+
correctness = { level = "warn", priority = -1 }
7+
complexity = { level = "warn", priority = -1 }
8+
needless-lifetimes = "allow" # Remove once 1.87 is stable, https://github.com/rust-lang/rust-clippy/issues/13514
9+
410
[package]
511
name = "mdbook"
612
version = "0.4.48"
@@ -91,3 +97,6 @@ test = false
9197
name = "gui"
9298
path = "tests/gui/runner.rs"
9399
crate-type = ["bin"]
100+
101+
[lints]
102+
workspace = true

examples/remove-emphasis/test.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use mdbook::MDBook;
2-
31
#[test]
42
fn remove_emphasis_works() {
53
// Tests that the remove-emphasis example works as expected.
64

75
// Workaround for https://github.com/rust-lang/mdBook/issues/1424
86
std::env::set_current_dir("examples/remove-emphasis").unwrap();
9-
let book = MDBook::load(".").unwrap();
7+
let book = mdbook::MDBook::load(".").unwrap();
108
book.build().unwrap();
119
let ch1 = std::fs::read_to_string("book/chapter_1.html").unwrap();
1210
assert!(ch1.contains("This has light emphasis and bold emphasis."));

src/book/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//!
66
//! [1]: ../index.html
77
8-
#[allow(clippy::module_inception)]
98
mod book;
109
mod init;
1110
mod summary;
@@ -860,7 +859,7 @@ mod tests {
860859
.and_then(Value::as_str)
861860
.unwrap();
862861
assert_eq!(html, "html");
863-
let html_renderer = HtmlHandlebars::default();
862+
let html_renderer = HtmlHandlebars;
864863
let pre = LinkPreprocessor::new();
865864

866865
let should_run = preprocessor_should_run(&pre, &html_renderer, &cfg);

src/book/summary.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'a> SummaryParser<'a> {
248248

249249
let mut files = HashSet::new();
250250
for part in [&prefix_chapters, &numbered_chapters, &suffix_chapters] {
251-
self.check_for_duplicates(&part, &mut files)?;
251+
Self::check_for_duplicates(&part, &mut files)?;
252252
}
253253

254254
Ok(Summary {
@@ -261,7 +261,6 @@ impl<'a> SummaryParser<'a> {
261261

262262
/// Recursively check for duplicate files in the summary items.
263263
fn check_for_duplicates<'b>(
264-
&self,
265264
items: &'b [SummaryItem],
266265
files: &mut HashSet<&'b PathBuf>,
267266
) -> Result<()> {
@@ -276,7 +275,7 @@ impl<'a> SummaryParser<'a> {
276275
}
277276
}
278277
// Recursively check nested items
279-
self.check_for_duplicates(&link.nested_items, files)?;
278+
Self::check_for_duplicates(&link.nested_items, files)?;
280279
}
281280
}
282281
Ok(())

src/preprocess/links.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ enum RangeOrAnchor {
148148
}
149149

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

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ impl HtmlHandlebars {
207207
Ok(())
208208
}
209209

210-
#[allow(clippy::let_and_return)]
211210
fn post_process(
212211
&self,
213212
rendered: String,

src/renderer/html_handlebars/helpers/resources.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ impl HelperDef for ResourceHelper {
3939
let path_to_root = utils::fs::path_to_root(&base_path);
4040

4141
out.write(&path_to_root)?;
42-
out.write(
43-
self.hash_map
44-
.get(&param[..])
45-
.map(|p| &p[..])
46-
.unwrap_or(&param),
47-
)?;
42+
out.write(self.hash_map.get(param).map(|p| &p[..]).unwrap_or(&param))?;
4843
Ok(())
4944
}
5045
}

tests/rendered_output.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ mod search {
780780
}
781781

782782
#[test]
783-
#[allow(clippy::float_cmp)]
784783
fn book_creates_reasonable_search_index() {
785784
let temp = DummyBook::new().build().unwrap();
786785
let md = MDBook::load(temp.path()).unwrap();

0 commit comments

Comments
 (0)