Skip to content

Commit

Permalink
Disable clippy for submissions with dependencies (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor authored Aug 25, 2024
1 parent 0ad9262 commit 83e72c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions snippets/with_dependency/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "with_dependency"
version = "0.1.0"
edition = "2021"

[dependencies]
itertools = "*"
3 changes: 3 additions & 0 deletions snippets/with_dependency/expected_analysis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"comments": []
}
3 changes: 3 additions & 0 deletions snippets/with_dependency/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn decrement(x: i32) -> i32 {
--x
}
14 changes: 13 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ use anyhow::{Context, Result};
use serde::Serialize;

pub fn analyze_exercise(solution_dir: &Path) -> Result<AnalysisOutput> {
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;
Expand Down

0 comments on commit 83e72c9

Please sign in to comment.