From 12cec481343e87aa1e51ba054f6aa23f9b38935b Mon Sep 17 00:00:00 2001 From: Chris Wong Date: Thu, 11 Nov 2021 22:32:37 +1100 Subject: [PATCH] Run Clippy on docs builder (#319) --- .github/workflows/ci.yml | 4 ++++ docs/src/bin/build_nav.rs | 7 +++---- docs/src/bin/build_page.rs | 12 +++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68f7fc2d..9bed8b0c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,10 +53,14 @@ jobs: toolchain: nightly profile: minimal override: true + components: clippy - name: Build documentation run: cd docs && make -j$(nproc) + - name: Check Clippy + run: cd docs && cargo clippy --all-targets -- -D warnings + examples: name: Examples runs-on: ubuntu-latest diff --git a/docs/src/bin/build_nav.rs b/docs/src/bin/build_nav.rs index 04807c83..13a93d5f 100644 --- a/docs/src/bin/build_nav.rs +++ b/docs/src/bin/build_nav.rs @@ -3,18 +3,17 @@ use docs::{ page::{Page, COMRAK_OPTIONS}, string_writer::StringWriter, }; -use serde_json; use std::{env, error::Error, fs, io, path::Path, str}; fn main() -> Result<(), Box> { let args = env::args().collect::>(); - if args.len() < 2 || !args[2..].iter().all(|arg| arg.contains(":")) { + if args.len() < 2 || !args[2..].iter().all(|arg| arg.contains(':')) { return Err("invalid arguments".into()); } let entries = args[2..] .iter() .map(|arg| { - let mut splits = arg.splitn(2, ":"); + let mut splits = arg.splitn(2, ':'); let slug = splits.next().unwrap(); let input_path = splits.next().unwrap(); (slug, input_path) @@ -35,7 +34,7 @@ fn build_nav(entries: &[(&str, &str)], nav_path: &str) -> Result<(), Box>>()?; // Only write if different to avoid spurious rebuilds - let old_string = fs::read_to_string(nav_path).unwrap_or(String::new()); + let old_string = fs::read_to_string(nav_path).unwrap_or_default(); let new_string = serde_json::to_string_pretty(&nav)?; if old_string != new_string { fs::create_dir_all(Path::new(nav_path).parent().unwrap())?; diff --git a/docs/src/bin/build_page.rs b/docs/src/bin/build_page.rs index 98da9f07..63fd7ca4 100644 --- a/docs/src/bin/build_page.rs +++ b/docs/src/bin/build_page.rs @@ -7,13 +7,11 @@ use docs::{ page::{Page, COMRAK_OPTIONS}, views, }; -use serde_json; use std::{ env, error::Error, fs::{self, File}, io::BufReader, - mem, path::Path, str::{self, Utf8Error}, string::FromUtf8Error, @@ -90,7 +88,7 @@ fn rewrite_md_links<'a>(root: &'a AstNode<'a>) -> Result<(), FromUtf8Error> { for node in root.descendants() { let mut data = node.data.borrow_mut(); if let NodeValue::Link(NodeLink { url, .. }) = &mut data.value { - let mut url_string = String::from_utf8(mem::replace(url, Vec::new()))?; + let mut url_string = String::from_utf8(std::mem::take(url))?; if url_string.ends_with(".md") { url_string.truncate(url_string.len() - ".md".len()); url_string.push_str(".html"); @@ -117,7 +115,7 @@ fn strip_hidden_code<'a>(root: &'a AstNode<'a>) -> Result<(), Box> { fn strip_hidden_code_inner(literal: &str) -> String { let lines = literal - .split("\n") + .split('\n') .filter(|line| { let line = line.trim(); line != "#" && !line.starts_with("# ") @@ -142,10 +140,10 @@ fn highlight_code<'a>(root: &'a AstNode<'a>) -> Result<(), Box> { let info = parse_code_block_info(info)?; let syntax = info .into_iter() - .filter_map(|token| ss.find_syntax_by_token(&token)) + .filter_map(|token| ss.find_syntax_by_token(token)) .next() .unwrap_or_else(|| ss.find_syntax_plain_text()); - let mut literal = String::from_utf8(mem::replace(literal, Vec::new()))?; + let mut literal = String::from_utf8(std::mem::take(literal))?; if !literal.ends_with('\n') { // Syntect expects a trailing newline literal.push('\n'); @@ -160,5 +158,5 @@ fn highlight_code<'a>(root: &'a AstNode<'a>) -> Result<(), Box> { } fn parse_code_block_info(info: &[u8]) -> Result, Utf8Error> { - str::from_utf8(info).map(|info| info.split(",").map(str::trim).collect()) + str::from_utf8(info).map(|info| info.split(',').map(str::trim).collect()) }