Skip to content

Commit

Permalink
💄 Format
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiBardon committed Jan 3, 2024
1 parent 7757a53 commit 808f2a7
Show file tree
Hide file tree
Showing 12 changed files with 521 additions and 287 deletions.
29 changes: 29 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Comes from <https://stackoverflow.com/a/71222423/10967642>.

exe=$(which rustfmt)

if [ -n "$exe" ]
then
# field separator to the new line
IFS=$'\n'

for line in $(git status -s)
do
# if added or modified
if [[ $line == A* || $line == M* ]]
then
# check file extension
if [[ $line == *.rs ]]
then
# format file
rustfmt --edition 2021 -l -- $(pwd)/${line:3}
# add changes
git add $(pwd)/${line:3}
fi
fi
done
else
echo "rustfmt was not found"
fi
9 changes: 4 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ jobs:
working-directory: ./src/orangutan
run: cargo test

# TODO: Re-enable style checking
# # TODO: Only check code style for one target
# - name: Check code style
# working-directory: ./src/orangutan
# run: cargo fmt -- --check
# TODO: Only check code style for one target
- name: Check code style
working-directory: ./src/orangutan
run: cargo fmt -- --check
6 changes: 6 additions & 0 deletions src/orangutan/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
array_width = 48
fn_params_layout = "Vertical"
group_imports = "StdExternalCrate"
imports_granularity = "Module"
match_block_trailing_comma = true
overflow_delimited_expr = true
28 changes: 19 additions & 9 deletions src/orangutan/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{path::{PathBuf, Path}, env, collections::HashSet, fmt::Display};
use std::collections::HashSet;
use std::env;
use std::fmt::Display;
use std::path::{Path, PathBuf};

use lazy_static::lazy_static;

Expand All @@ -20,15 +23,16 @@ const WEBSITE_DIR_NAME: &'static str = "website";

lazy_static! {
static ref WORK_DIR: PathBuf = env::current_dir().unwrap();
pub static ref WEBSITE_REPOSITORY: String = env::var("WEBSITE_REPOSITORY").expect("Environment variable `WEBSITE_REPOSITORY` is required.");
pub static ref WEBSITE_REPOSITORY: String = env::var("WEBSITE_REPOSITORY")
.expect("Environment variable `WEBSITE_REPOSITORY` is required.");
pub static ref BASE_DIR: PathBuf = WORK_DIR.join(".orangutan");
pub static ref WEBSITE_ROOT: PathBuf = BASE_DIR.join("website");
pub static ref KEYS_DIR: PathBuf = BASE_DIR.join("keys");
pub static ref HUGO_CONFIG_DIR: PathBuf = BASE_DIR.join("hugo-config");
pub static ref DEST_DIR: PathBuf = BASE_DIR.join("out");
pub static ref WEBSITE_DATA_DIR: PathBuf = DEST_DIR.join("data");
pub static ref SUFFIXED_EXTENSIONS: Vec<&'static str> = vec!["html", "json", "xml", "css", "js", "txt"];

pub static ref SUFFIXED_EXTENSIONS: Vec<&'static str> =
vec!["html", "json", "xml", "css", "js", "txt"];
pub static ref MODE: Result<String, env::VarError> = env::var("MODE");
pub static ref KEYS_MODE: Result<String, env::VarError> = env::var("KEYS_MODE");
}
Expand Down Expand Up @@ -61,7 +65,7 @@ impl WebsiteId {
impl From<&Vec<String>> for WebsiteId {
fn from(value: &Vec<String>) -> Self {
if value.is_empty() {
return Self::default()
return Self::default();
}

// Convert Vec<String> to HashSet<String> to get unique profiles
Expand All @@ -71,22 +75,28 @@ impl From<&Vec<String>> for WebsiteId {
let mut used_profiles = used_profiles().clone();
// Insert special "*" profile so it is kept for website generation
used_profiles.insert("*".to_string());
profiles = profiles.intersection(&used_profiles).map(|s| s.clone()).collect();
profiles = profiles
.intersection(&used_profiles)
.map(|s| s.clone())
.collect();

return Self { profiles }
return Self { profiles };
}
}

impl Display for WebsiteId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(
&self,
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
write!(f, "{}", self.dir_name())
}
}

impl Default for WebsiteId {
fn default() -> Self {
let profiles = vec![DEFAULT_PROFILE.to_string()].into_iter().collect();
return Self { profiles }
return Self { profiles };
}
}

Expand Down
Loading

0 comments on commit 808f2a7

Please sign in to comment.