Skip to content

Commit

Permalink
check if rustfmt.toml exists in git
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Mar 29, 2024
1 parent 2456f1b commit 4cc99d5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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(),
}
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ fn collect_data_from_vcs(crates: &Vec<Crate>, 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();
Expand Down
10 changes: 10 additions & 0 deletions templates/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ <h1 class="title">Rust Digger Stats</h1>
<td>{{stats.crates_without_owner | commafy}}</td>
<td>{{percentage.crates_without_owner}}%</td>
</tr>
<tr>
<td><a href="/has-rustfmt-toml">Has rustfmt.toml</a></td>
<td>{{stats.has_rustfmt_toml | commafy}}</td>
<td>{{percentage.has_rustfmt_toml}}%</td>
</tr>
<tr>
<td><a href="/has-dot-rustfmt-toml">Has .rustfmt.toml</a></td>
<td>{{stats.has_dot_rustfmt_toml | commafy}}</td>
<td>{{percentage.has_dot_rustfmt_toml}}%</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit 4cc99d5

Please sign in to comment.