Skip to content

Commit

Permalink
style: configure pedantic lints and adhere to them
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoniePhiline committed Mar 29, 2024
1 parent e4eaca0 commit d2c3ea7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
27 changes: 27 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,30 @@ chrono = { version = "0.4.37", default-features = false }
color-eyre = "0.6.3"
gix = { version = "0.61.0", features = ["blocking-http-transport-reqwest-rust-tls"] }
nom = "7.1.3"

[lints.rust] # https://git.nsb-software.de/devel/manifest/-/blob/main/policy.md#rust-compiler-lints
elided_lifetimes_in_paths = "warn"
future_incompatible = "warn"
let_underscore = "warn"
missing_copy_implementations = "warn"
missing_debug_implementations = "warn"
missing_docs = "warn"
# must_not_suspend = "warn" # https://github.com/rust-lang/rust/issues/83310
non_ascii_idents = "warn"
nonstandard_style = "warn"
noop_method_call = "warn"
# unnameable_types = "warn" # https://github.com/rust-lang/rust/issues/48054
unreachable_pub = "warn"
unused = "warn"
unused_crate_dependencies = "warn"
unused_lifetimes = "warn"

pointer_structural_match = "deny"
# lossy_provenance_casts = "deny" # https://github.com/rust-lang/rust/issues/95228
# fuzzy_provenance_casts = "deny" # https://github.com/rust-lang/rust/issues/95228
unsafe_code = "deny" # Exceptions must be discussed and deemed indispensable and use `#![deny(invalid_reference_casting, unsafe_op_in_unsafe_fn)]`.

[lints.clippy] # https://git.nsb-software.de/devel/manifest/-/blob/main/policy.md#clippy-lints
pedantic = "warn"
cargo = "warn"
multiple_crate_versions = { level = "allow", priority = 1 } # https://git.nsb-software.de/devel/manifest/-/blob/main/policy.md#explicit-opt-out-of-clippymultiple_crate_versions
17 changes: 11 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! # This Week in Rust: _Quote of the Week_ scraper
//!
//! An ad-hoc, just-for-fun project
//! of [Rust Hack and Learn Meetup Berlin](https://berline.rs/).

use std::{fs, path::Path};

use chrono::NaiveDate;
Expand Down Expand Up @@ -75,15 +80,15 @@ fn main() -> Result<()> {
);

println!("# Quotes of the week\n");
collection.into_iter().for_each(|(date, maybe_quote)| {
for (date, maybe_quote) in collection {
if let Some(quote) = maybe_quote {
println!("## {date} - Quote of the Week\n");
println!("{quote}\n\n");
} else {
println!("## {date}\n");
println!("_No Quote of the Week._\n")
println!("_No Quote of the Week._\n");
}
});
}

Ok(())
}
Expand Down Expand Up @@ -128,9 +133,8 @@ fn find_quote(input: &str) -> Option<&str> {
let start = "# Quote of the Week\n\n";

// Skip all text until the start-of-quote marker.
let input = match take_until(start)(input) {
Ok((input, _)) => input,
Err::<_, nom::Err<nom::error::Error<&str>>>(_) => return None, // TakeUntil error -> Quote not found.
let Ok((input, _)) = take_until::<&str, &str, nom::error::Error<&str>>(start)(input) else {
return None; // TakeUntil error -> Quote not found.
};

// Consume the marker, removing it from the parseable remainder.
Expand Down Expand Up @@ -161,6 +165,7 @@ fn take_quote(input: &str) -> Result<&str> {
fn git_clone_or_open(src: &str, dest: &Path) -> Result<()> {
// SAFETY: The closure doesn't use mutexes or memory allocation,
// so it should be safe to call from a signal handler.
#[allow(unsafe_code)]
unsafe {
gix::interrupt::init_handler(1, || {})?;
}
Expand Down

0 comments on commit d2c3ea7

Please sign in to comment.