From 4cc99d585985a70eb6e0c5eb7a994099b8ac93bc Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Fri, 29 Mar 2024 10:48:04 +0300 Subject: [PATCH] check if rustfmt.toml exists in git --- src/lib.rs | 13 +++++++++++++ src/render.rs | 18 ++++++++++++++++++ src/vcs.rs | 2 ++ templates/stats.html | 10 ++++++++++ 4 files changed, 43 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 67052be..6eb68a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ use once_cell::sync::Lazy; use regex::Regex; #[derive(Debug, serde::Serialize, serde::Deserialize, Clone)] +#[allow(clippy::struct_excessive_bools)] pub struct Details { pub has_github_action: bool, pub has_gitlab_pipeline: bool, @@ -17,6 +18,12 @@ pub struct Details { #[serde(default = "empty_string")] pub git_clone_error: String, + + #[serde(default = "default_false")] + pub has_rustfmt_toml: bool, + + #[serde(default = "default_false")] + pub has_dot_rustfmt_toml: bool, } impl Details { @@ -27,6 +34,8 @@ impl Details { commit_count: 0, cargo_toml_in_root: false, cargo_fmt: String::new(), + has_rustfmt_toml: false, + has_dot_rustfmt_toml: false, git_clone_error: String::new(), } @@ -139,6 +148,10 @@ const fn get_zero() -> usize { 0 } +const fn default_false() -> bool { + false +} + #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct Team { pub avatar: String, diff --git a/src/render.rs b/src/render.rs index e2938e5..245d697 100644 --- a/src/render.rs +++ b/src/render.rs @@ -474,6 +474,22 @@ pub fn generate_pages( crates, )?; + let has_rustfmt_toml = render_filtered_crates( + "has-rustfmt-toml.html", + "Has rustfmt.toml file", + "has-rustfmt-toml", + crates, + |krate| krate.details.has_rustfmt_toml, + )?; + + let has_dot_rustfmt_toml = render_filtered_crates( + "has-dot-rustfmt-toml.html", + "Has .rustfmt.toml file", + "has-dot-rustfmt-toml", + crates, + |krate| krate.details.has_dot_rustfmt_toml, + )?; + let github_but_no_ci = render_filtered_crates( "github-but-no-ci.html", "On GitHub but has no CI", @@ -533,6 +549,8 @@ pub fn generate_pages( ("github_but_no_ci", github_but_no_ci), ("gitlab_but_no_ci", gitlab_but_no_ci), ("no_repo", no_repo), + ("has_rustfmt_toml", has_rustfmt_toml), + ("has_dot_rustfmt_toml", has_dot_rustfmt_toml), ]); render_stats_page(crates.len(), repos, &stats); diff --git a/src/vcs.rs b/src/vcs.rs index 1bef8ce..237f079 100644 --- a/src/vcs.rs +++ b/src/vcs.rs @@ -96,6 +96,8 @@ fn collect_data_from_vcs(crates: &Vec, limit: u32) { details.has_gitlab_pipeline = gitlab_ci_file.exists(); } details.cargo_toml_in_root = Path::new("Cargo.toml").exists(); + details.has_rustfmt_toml = Path::new("rustfmt.toml").exists(); + details.has_dot_rustfmt_toml = Path::new(".rustfmt.toml").exists(); if !host.is_empty() { details.commit_count = git_get_count(); diff --git a/templates/stats.html b/templates/stats.html index 9d5fd58..86944b9 100644 --- a/templates/stats.html +++ b/templates/stats.html @@ -53,6 +53,16 @@

Rust Digger Stats

{{stats.crates_without_owner | commafy}} {{percentage.crates_without_owner}}% + + Has rustfmt.toml + {{stats.has_rustfmt_toml | commafy}} + {{percentage.has_rustfmt_toml}}% + + + Has .rustfmt.toml + {{stats.has_dot_rustfmt_toml | commafy}} + {{percentage.has_dot_rustfmt_toml}}% +