* Run cargo fmt

* Add cargo fmt --check to pipeline
This commit is contained in:
Soso 2022-11-14 21:23:30 +01:00 committed by Vincent Prouillet
parent da5c4c496a
commit 405dda6722
6 changed files with 31 additions and 35 deletions

View File

@ -42,6 +42,8 @@ stages:
displayName: Cargo build (Rust TLS)
- script: cargo test --all
displayName: Cargo test
- script: cargo fmt --check
displayName: Cargo fmt
- stage: Release

View File

@ -222,8 +222,11 @@ impl Taxonomy {
) -> Result<String> {
let mut context = Context::new();
context.insert("config", &config.serialize(&self.lang));
let terms: Vec<SerializedTaxonomyTerm> =
self.items.iter().map(|i| SerializedTaxonomyTerm::from_item(i, library, true)).collect();
let terms: Vec<SerializedTaxonomyTerm> = self
.items
.iter()
.map(|i| SerializedTaxonomyTerm::from_item(i, library, true))
.collect();
context.insert("terms", &terms);
context.insert("lang", &self.lang);
context.insert("taxonomy", &self.kind);

View File

@ -4,7 +4,10 @@ use std::ffi::OsStr;
use std::fs::{self, File};
use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
use std::{collections::hash_map::DefaultHasher, io::{Write, BufWriter}};
use std::{
collections::hash_map::DefaultHasher,
io::{BufWriter, Write},
};
use image::error::ImageResult;
use image::io::Reader as ImgReader;

View File

@ -142,4 +142,3 @@ mod tests {
assert_eq!(res, expected);
}
}

View File

@ -1,9 +1,9 @@
use std::fs::create_dir_all;
use std::path::{Path, PathBuf};
use libs::walkdir::{WalkDir, DirEntry};
use libs::globset::{Glob};
use libs::globset::Glob;
use libs::sass_rs::{compile_file, Options, OutputStyle};
use libs::walkdir::{DirEntry, WalkDir};
use crate::anyhow;
use errors::{bail, Result};
@ -67,10 +67,7 @@ fn compile_sass_glob(
}
fn is_partial_scss(entry: &DirEntry) -> bool {
entry.file_name()
.to_str()
.map(|s| s.starts_with("_"))
.unwrap_or(false)
entry.file_name().to_str().map(|s| s.starts_with("_")).unwrap_or(false)
}
fn get_non_partial_scss(sass_path: &Path, extension: &str) -> Vec<PathBuf> {

View File

@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::path::PathBuf;
use std::fs;
use std::io::Read;
use std::path::PathBuf;
use crate::global_fns::helpers::search_for_file;
use config::Config;
@ -11,10 +11,7 @@ use libs::tera::{from_value, to_value, Function as TeraFn, Result, Value};
use libs::url;
use utils::site::resolve_internal_link;
fn compute_hash<D: digest::Digest>(
literal: String,
as_base64: bool,
) -> String
fn compute_hash<D: digest::Digest>(literal: String, as_base64: bool) -> String
where
digest::Output<D>: core::fmt::LowerHex,
D: std::io::Write,
@ -135,8 +132,7 @@ impl TeraFn for GetUrl {
f.read_to_string(&mut contents).ok()?;
Some(compute_hash::<Sha256>(contents, false))
})
{
}) {
Some(hash) => {
permalink = format!("{}?h={}", permalink, hash);
}
@ -201,10 +197,12 @@ impl TeraFn for GetHash {
let contents = match (path, literal) {
(Some(_), Some(_)) => {
return Err("`get_hash`: must have only one of `path` or `literal` argument".into());
},
}
(None, None) => {
return Err("`get_hash`: must have at least one of `path` or `literal` argument".into());
},
return Err(
"`get_hash`: must have at least one of `path` or `literal` argument".into()
);
}
(Some(path_v), None) => {
let file_path =
match search_for_file(&self.base_path, &path_v, &self.theme, &self.output_path)
@ -234,10 +232,9 @@ impl TeraFn for GetHash {
contents
}
(None, Some(literal_v)) => { literal_v }
(None, Some(literal_v)) => literal_v,
};
let sha_type = optional_arg!(
u16,
args.get("sha_type"),
@ -245,11 +242,8 @@ impl TeraFn for GetHash {
)
.unwrap_or(384);
let base64 = optional_arg!(
bool,
args.get("base64"),
"`get_hash`: `base64` must be true or false"
)
let base64 =
optional_arg!(bool, args.get("base64"), "`get_hash`: `base64` must be true or false")
.unwrap_or(true);
let hash = match sha_type {
@ -587,9 +581,7 @@ title = "A title"
args.insert("literal".to_string(), to_value("Hello World").unwrap());
args.insert("sha_type".to_string(), to_value(256).unwrap());
args.insert("base64".to_string(), to_value(true).unwrap());
assert_eq!(
static_fn.call(&args).unwrap(),
"pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4=");
assert_eq!(static_fn.call(&args).unwrap(), "pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4=");
}
#[test]