diff --git a/snippets/with_dependency/Cargo.toml b/snippets/with_dependency/Cargo.toml new file mode 100644 index 0000000..d4aff80 --- /dev/null +++ b/snippets/with_dependency/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "with_dependency" +version = "0.1.0" +edition = "2021" + +[dependencies] +itertools = "*" diff --git a/snippets/with_dependency/expected_analysis.json b/snippets/with_dependency/expected_analysis.json new file mode 100644 index 0000000..b27d850 --- /dev/null +++ b/snippets/with_dependency/expected_analysis.json @@ -0,0 +1,3 @@ +{ + "comments": [] +} \ No newline at end of file diff --git a/snippets/with_dependency/src/lib.rs b/snippets/with_dependency/src/lib.rs new file mode 100644 index 0000000..e5d422b --- /dev/null +++ b/snippets/with_dependency/src/lib.rs @@ -0,0 +1,3 @@ +pub fn decrement(x: i32) -> i32 { + --x +} diff --git a/src/lib.rs b/src/lib.rs index 475e29c..7b5b3a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,11 +4,23 @@ use anyhow::{Context, Result}; use serde::Serialize; pub fn analyze_exercise(solution_dir: &Path) -> Result { + let manifest_path = solution_dir.join("Cargo.toml"); + if std::fs::read_to_string(&manifest_path) + .context("failed to read Cargo.toml")? + .contains("[dependencies]") + { + // Do not run clippy on exercises that make use of dependencies. + // The analyzer currently has no support for dependencies like the + // test runner. + return Ok(AnalysisOutput { comments: vec![] }); + } + let clippy_output = Command::new("cargo") .arg("clippy") + .arg("--offline") .arg("--quiet") // suppress compilation progress output .arg("--manifest-path") - .arg(solution_dir.join("Cargo.toml").display().to_string()) + .arg(manifest_path.display().to_string()) .output() .context("failed to run clippy")? .stderr;