diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37b1bc9b..b815e336 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,15 @@ name: Continuous integration on: [push, pull_request] +env: + RUSTFLAGS: "-Dwarnings" + RUSTDOCFLAGS: "-Dwarnings" + jobs: - ci: + test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - name: Check out CSL styles run: | @@ -13,3 +17,16 @@ jobs: git clone --depth 1 https://github.com/citation-style-language/styles - run: cargo build - run: cargo test --features csl-json + + checks: + name: Check clippy, formatting, and documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@1.80.0 + with: + components: clippy, rustfmt + - uses: Swatinem/rust-cache@v2 + - run: cargo clippy --workspace --all-targets --all-features + - run: cargo fmt --check --all + - run: cargo doc --workspace --no-deps diff --git a/src/csl/archive.rs b/src/csl/archive.rs index 8e0e04b5..f1a516d3 100644 --- a/src/csl/archive.rs +++ b/src/csl/archive.rs @@ -335,6 +335,7 @@ pub enum ArchivedStyle { VancouverSuperscript, } +#[rustfmt::skip] impl ArchivedStyle { /// Retrieve this style by name. pub fn by_name(name: &str) -> Option { @@ -426,7 +427,7 @@ impl ArchivedStyle { "turabian-fullnote-8" => Some(Self::TurabianFullnote8), "vancouver" => Some(Self::Vancouver), "vancouver-superscript" => Some(Self::VancouverSuperscript), - _ => None + _ => None, } } @@ -1125,7 +1126,6 @@ impl ArchivedStyle { Self::VancouverSuperscript => "http://www.zotero.org/styles/vancouver-superscript", } } - } fn from_cbor( reader: &[u8], @@ -1195,7 +1195,8 @@ pub const LOCALES: &[&[u8]] = &[ /// Get all CSL locales. pub fn locales() -> Vec { - LOCALES.iter().map(|bytes| { - from_cbor::(bytes).unwrap() - }).collect() + LOCALES + .iter() + .map(|bytes| from_cbor::(bytes).unwrap()) + .collect() } diff --git a/src/csl/mod.rs b/src/csl/mod.rs index 62062757..69d269d6 100644 --- a/src/csl/mod.rs +++ b/src/csl/mod.rs @@ -129,7 +129,7 @@ impl<'a, T: EntryLike + Hash + PartialEq + Eq + Debug> BibliographyDriver<'a, T> &mut citation.items, style.csl.citation.sort.as_ref(), citation.locale.as_ref(), - &citation_number, + citation_number, ); let items = &citation.items; diff --git a/src/lib.rs b/src/lib.rs index ada473b1..fe78df84 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -610,9 +610,7 @@ impl Entry { // Index parents with the items in path. If, at any level, the index // exceeds the number of parents, increment the index at the // previous level. If no other level remains, return. - let Some(first_path) = path.first() else { - return None; - }; + let first_path = path.first()?; if self.parents.len() <= *first_path { return None; diff --git a/src/types/mod.rs b/src/types/mod.rs index 3de87668..cd6be34b 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -436,13 +436,13 @@ impl<'de> Deserialize<'de> for SerialNumber { Float(f64), } - impl ToString for StringOrNumber { - fn to_string(&self) -> String { + impl Display for StringOrNumber { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::String(s) => s.clone(), - Self::Number(n) => n.to_string(), - Self::UnsignedNumber(n) => n.to_string(), - Self::Float(f) => f.to_string(), + Self::String(s) => s.fmt(formatter), + Self::Number(n) => n.fmt(formatter), + Self::UnsignedNumber(n) => n.fmt(formatter), + Self::Float(f) => f.fmt(formatter), } } } diff --git a/tests/archiver.rs b/tests/archiver.rs index ddb55c70..7876ae3a 100644 --- a/tests/archiver.rs +++ b/tests/archiver.rs @@ -150,6 +150,7 @@ fn write_styles_section( writeln!(w, "}}")?; writeln!(w)?; + writeln!(w, "#[rustfmt::skip]")?; writeln!(w, "impl ArchivedStyle {{")?; writeln!(w, " /// Retrieve this style by name.")?; writeln!(w, " pub fn by_name(name: &str) -> Option {{")?; @@ -159,7 +160,7 @@ fn write_styles_section( writeln!(w, " {:?} => Some(Self::{}),", name, variant)?; } } - writeln!(w, " _ => None")?; + writeln!(w, " _ => None,")?; writeln!(w, " }}")?; writeln!(w, " }}")?; writeln!(w)?; @@ -239,7 +240,6 @@ fn write_styles_section( } writeln!(w, " }}")?; writeln!(w, " }}")?; - writeln!(w)?; writeln!(w, "}}")?; writeln!(w, "fn from_cbor(")?; @@ -268,9 +268,10 @@ fn write_locales_section(w: &mut String, items: &[(Vec, Locale)]) -> fmt::Re writeln!(w, "/// Get all CSL locales.")?; writeln!(w, "pub fn locales() -> Vec {{")?; - writeln!(w, " LOCALES.iter().map(|bytes| {{")?; - writeln!(w, " from_cbor::(bytes).unwrap()")?; - writeln!(w, " }}).collect()")?; + writeln!(w, " LOCALES")?; + writeln!(w, " .iter()")?; + writeln!(w, " .map(|bytes| from_cbor::(bytes).unwrap())")?; + writeln!(w, " .collect()")?; writeln!(w, "}}")?; Ok(()) @@ -288,7 +289,7 @@ fn get_names<'a>(id: &'a str, over: Option<&'a Override>) -> Vec { } .to_string(); - let other = if let Some(alias) = over.and_then(|o| o.alias) { alias } else { &[] }; + let other = over.and_then(|o| o.alias).unwrap_or_default(); iter::once(main) .chain(other.iter().map(ToString::to_string)) .collect()