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

Cargo fmt #2009

Merged
merged 2 commits into from
Nov 14, 2022
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
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions components/content/src/taxonomies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion components/imageproc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion components/site/src/minify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,3 @@ mod tests {
assert_eq!(res, expected);
}
}

11 changes: 4 additions & 7 deletions components/site/src/sass.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -67,16 +67,13 @@ 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> {
let glob_string = format!("*.{}", extension);
let glob = Glob::new(glob_string.as_str()).expect("Invalid glob for sass").compile_matcher();

WalkDir::new(sass_path)
.into_iter()
.filter_entry(|e| !is_partial_scss(e))
Expand Down
40 changes: 16 additions & 24 deletions components/templates/src/global_fns/files.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -201,14 +197,16 @@ 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)
.map_err(|e| format!("`get_hash`: {}", e))?
.map_err(|e| format!("`get_hash`: {}", e))?
{
Some((f, _)) => f,
None => {
Expand All @@ -234,23 +232,19 @@ 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"),
"`get_hash`: `sha_type` must be 256, 384 or 512"
)
.unwrap_or(384);

let base64 = optional_arg!(
bool,
args.get("base64"),
"`get_hash`: `base64` must be true or false"
)
.unwrap_or(true);

let base64 =
optional_arg!(bool, args.get("base64"), "`get_hash`: `base64` must be true or false")
.unwrap_or(true);

let hash = match sha_type {
256 => compute_hash::<Sha256>(contents, base64),
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -654,7 +646,7 @@ title = "A title"
args.insert(
"path".to_string(),
to_value(dir.path().join("app.css").strip_prefix(std::env::temp_dir()).unwrap())
.unwrap(),
.unwrap(),
);
assert_eq!(
static_fn.call(&args).unwrap(),
Expand Down