remove unnecessary logic in exclude pattern
use crate::error::*;
use colored::Color;
-use regex::Regex;
use serde::Serialize;
use std::collections::HashMap;
use std::env;
@@ -339,31 +338,12 @@ impl Language {
}
fn get_statistics(dir: &str, ignored_directories: &[String]) -> tokei::Languages {
- use tokei::Config;
-
let mut languages = tokei::Languages::new();
let required_languages = get_all_language_types();
- let tokei_config = Config { types: Some(required_languages), ..Config::default() };
-
- if !ignored_directories.is_empty() {
- let re = Regex::new(r"((.*)+/)+(.*)").unwrap();
- let mut v = Vec::with_capacity(ignored_directories.len());
- for ignored in ignored_directories {
- if re.is_match(&ignored) {
- let p = if ignored.starts_with('/') { "**" } else { "**/" };
- v.push(format!("{}{}", p, ignored));
- } else {
- v.push(String::from(ignored));
- }
- }
- let ignored_directories_for_ab: Vec<&str> = v.iter().map(|x| &**x).collect();
- languages.get_statistics(&[&dir], &ignored_directories_for_ab, &tokei_config);
- } else {
- let ignored_directories_ref: Vec<&str> =
- ignored_directories.iter().map(|s| &**s).collect();
- languages.get_statistics(&[&dir], &ignored_directories_ref, &tokei_config);
- }
-
+ let tokei_config =
+ tokei::Config { types: Some(required_languages), ..tokei::Config::default() };
+ let ignored: Vec<&str> = ignored_directories.iter().map(AsRef::as_ref).collect();
+ languages.get_statistics(&[&dir], &ignored, &tokei_config);
languages
}
}
