Skip to content
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

Add clippy and formatting to CI #204

Merged
merged 5 commits into from
Aug 29, 2024
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
21 changes: 19 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
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: |
cd ..
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
11 changes: 6 additions & 5 deletions src/csl/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ pub enum ArchivedStyle {
VancouverSuperscript,
}

#[rustfmt::skip]
impl ArchivedStyle {
/// Retrieve this style by name.
pub fn by_name(name: &str) -> Option<Self> {
Expand Down Expand Up @@ -426,7 +427,7 @@ impl ArchivedStyle {
"turabian-fullnote-8" => Some(Self::TurabianFullnote8),
"vancouver" => Some(Self::Vancouver),
"vancouver-superscript" => Some(Self::VancouverSuperscript),
_ => None
_ => None,
}
}

Expand Down Expand Up @@ -1125,7 +1126,6 @@ impl ArchivedStyle {
Self::VancouverSuperscript => "http://www.zotero.org/styles/vancouver-superscript",
}
}

}
fn from_cbor<T: DeserializeOwned>(
reader: &[u8],
Expand Down Expand Up @@ -1195,7 +1195,8 @@ pub const LOCALES: &[&[u8]] = &[

/// Get all CSL locales.
pub fn locales() -> Vec<Locale> {
LOCALES.iter().map(|bytes| {
from_cbor::<Locale>(bytes).unwrap()
}).collect()
LOCALES
.iter()
.map(|bytes| from_cbor::<Locale>(bytes).unwrap())
.collect()
}
2 changes: 1 addition & 1 deletion src/csl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions tests/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {{")?;
Expand All @@ -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)?;
Expand Down Expand Up @@ -239,7 +240,6 @@ fn write_styles_section(
}
writeln!(w, " }}")?;
writeln!(w, " }}")?;
writeln!(w)?;
writeln!(w, "}}")?;

writeln!(w, "fn from_cbor<T: DeserializeOwned>(")?;
Expand Down Expand Up @@ -268,9 +268,10 @@ fn write_locales_section(w: &mut String, items: &[(Vec<u8>, Locale)]) -> fmt::Re

writeln!(w, "/// Get all CSL locales.")?;
writeln!(w, "pub fn locales() -> Vec<Locale> {{")?;
writeln!(w, " LOCALES.iter().map(|bytes| {{")?;
writeln!(w, " from_cbor::<Locale>(bytes).unwrap()")?;
writeln!(w, " }}).collect()")?;
writeln!(w, " LOCALES")?;
writeln!(w, " .iter()")?;
writeln!(w, " .map(|bytes| from_cbor::<Locale>(bytes).unwrap())")?;
writeln!(w, " .collect()")?;
writeln!(w, "}}")?;

Ok(())
Expand All @@ -288,7 +289,7 @@ fn get_names<'a>(id: &'a str, over: Option<&'a Override>) -> Vec<String> {
}
.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()
Expand Down