Skip to content

Commit

Permalink
fix clippy warn
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Dec 17, 2020
1 parent dbb88e8 commit a7055f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/onefetch/deps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use {

pub mod package_manager;

type DependencyParser = fn(&str) -> Result<usize>;

pub struct DependencyDetector {
package_managers: HashMap<String, (fn(&str) -> Result<usize>, package_manager::PackageManager)>,
package_managers: HashMap<String, (DependencyParser, package_manager::PackageManager)>,
}

impl DependencyDetector {
Expand Down
10 changes: 5 additions & 5 deletions src/onefetch/deps/package_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ define_package_managers! {
{ Pub, "pub", "pubspec.yaml", pub_packages },
}

pub fn cargo(contents: &str) -> Result<usize> {
fn cargo(contents: &str) -> Result<usize> {
let parsed = contents.parse::<Value>()?;
let count = parsed.get("dependencies");

Expand All @@ -52,7 +52,7 @@ pub fn cargo(contents: &str) -> Result<usize> {
}
}

pub fn go_modules(contents: &str) -> Result<usize> {
fn go_modules(contents: &str) -> Result<usize> {
let mut count = 0;
let mut start = false;
for line in contents.lines() {
Expand All @@ -73,19 +73,19 @@ pub fn go_modules(contents: &str) -> Result<usize> {
Ok(count)
}

pub fn npm(contents: &str) -> Result<usize> {
fn npm(contents: &str) -> Result<usize> {
let parsed = json::parse(contents)?;

Ok(parsed["dependencies"].len())
}

pub fn pip(contents: &str) -> Result<usize> {
fn pip(contents: &str) -> Result<usize> {
let count = Regex::new(r"(^|\n)[A-z]+")?.find_iter(contents).count();

Ok(count)
}

pub fn pub_packages(contents: &str) -> Result<usize> {
fn pub_packages(contents: &str) -> Result<usize> {
match YamlLoader::load_from_str(contents) {
Ok(parsed) => match &parsed[0]["dependencies"].as_hash() {
Some(deps) => Ok(deps.len()),
Expand Down

0 comments on commit a7055f1

Please sign in to comment.