Skip to content

Commit 9e5a263

Browse files
authored
cargo fix, cargo fmt, and manual cleanup
1 parent fcb16c8 commit 9e5a263

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

src/info/langs/language.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,24 @@ include!(concat!(env!("OUT_DIR"), "/language.rs"));
1010
pub struct LanguageType(pub Category);
1111

1212
impl LanguageType {
13-
pub(crate) const DEFAULT_ARGS: [Self;3] = [Self(Category::Programming), Self(Category::Markup), Self(Category::Query)];
13+
pub(crate) const DEFAULT_ARGS: [Self; 3] = [
14+
Self(Category::Programming),
15+
Self(Category::Markup),
16+
Self(Category::Query),
17+
];
1418
// pub(crate) const VARIANTS: [Self;5]
1519
}
1620

1721
impl clap::ValueEnum for LanguageType {
1822
fn value_variants<'a>() -> &'a [Self] {
1923
use Category::*;
20-
&[Self(Programming), Self(Markup), Self(Prose), Self(Data), Self(Query)]
24+
&[
25+
Self(Programming),
26+
Self(Markup),
27+
Self(Prose),
28+
Self(Data),
29+
Self(Query),
30+
]
2131
}
2232

2333
fn to_possible_value(&self) -> Option<PossibleValue> {

src/info/langs/mod.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use anyhow::{anyhow, Context, Result};
2-
use gengo::{analysis, FileSource, Git, Builder};
3-
use gix::filter::plumbing::eol::Stats;
1+
use anyhow::{anyhow, Result};
2+
use gengo::{Builder, Git};
3+
4+
use globset::{Glob, GlobSetBuilder};
45
use language::{Language, LanguageType};
56
use std::collections::HashMap;
67
use std::error::Error;
78
use std::path::Path;
8-
use strum::IntoEnumIterator;
9-
use globset::{Glob, GlobSetBuilder};
109

1110
pub mod language;
1211

@@ -23,20 +22,22 @@ pub fn get_size_by_language_sorted(
2322
language_types: &[LanguageType],
2423
include_hidden: bool,
2524
) -> Result<Vec<(Language, usize)>> {
26-
let globset = globs_to_exclude.iter()
25+
let globset = globs_to_exclude
26+
.iter()
2727
.filter_map(|glob| Glob::new(glob).ok())
2828
.fold(GlobSetBuilder::new(), |mut builder, glob| {
2929
builder.add(glob);
3030
builder
3131
})
3232
.build()?;
33-
let analysis = match get_statistics(dir, globs_to_exclude, language_types, include_hidden) {
33+
let analysis = match get_statistics(dir) {
3434
Ok(stats) => stats,
35-
Err(e) => return Err(anyhow!("Could not analyze repository: {}", e))
35+
Err(e) => return Err(anyhow!("Could not analyze repository: {}", e)),
3636
};
3737

3838
// NOTE If finer control is ever needed, summary_with can be used.
39-
let mut size_by_language: Vec<(Language, _)> = analysis.iter()
39+
let mut size_by_language: Vec<(Language, _)> = analysis
40+
.iter()
4041
.filter(|(path, _)| include_hidden || !is_hidden(path))
4142
.filter(|(path, _)| !globset.is_match(path))
4243
.filter(|(_, entry)| {
@@ -60,12 +61,7 @@ pub fn get_size_by_language_sorted(
6061
Ok(size_by_language)
6162
}
6263

63-
fn get_statistics(
64-
dir: &Path,
65-
globs_to_exclude: &[String],
66-
language_types: &[LanguageType],
67-
include_hidden: bool,
68-
) -> Result<gengo::Analysis, Box<dyn Error>> {
64+
fn get_statistics(dir: &Path) -> Result<gengo::Analysis, Box<dyn Error>> {
6965
// TODO Determine best way to ignore files (and if that should continue to be handled by onefetch)
7066
let file_source = Git::new(dir, "HEAD")?;
7167
let gengo = Builder::new(file_source).build()?;
@@ -74,9 +70,9 @@ fn get_statistics(
7470

7571
/// Returns `true` if the file is or any of its containing directories are hidden.
7672
fn is_hidden(path: impl AsRef<Path>) -> bool {
77-
path.as_ref().components().any(|c| {
78-
c.as_os_str().to_string_lossy().starts_with('.')
79-
})
73+
path.as_ref()
74+
.components()
75+
.any(|c| c.as_os_str().to_string_lossy().starts_with('.'))
8076
}
8177

8278
#[cfg(test)]

0 commit comments

Comments
 (0)