* 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) displayName: Cargo build (Rust TLS)
- script: cargo test --all - script: cargo test --all
displayName: Cargo test displayName: Cargo test
- script: cargo fmt --check
displayName: Cargo fmt
- stage: Release - stage: Release

View File

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

View File

@ -4,7 +4,10 @@ use std::ffi::OsStr;
use std::fs::{self, File}; use std::fs::{self, File};
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf}; 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::error::ImageResult;
use image::io::Reader as ImgReader; use image::io::Reader as ImgReader;

View File

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

View File

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

View File

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