use std::sync::Arc;
use crate::evaluator::Evaluator;
use crate::evaluators::code::cargo_check::run_cargo;
use crate::evaluators::code::extractor::CodeExtractor;
use crate::evaluators::code::harness::CargoHarness;
use crate::types::{EvalCase, EvalMetricResult, Invocation};
pub struct ClippyEvaluator {
name: &'static str,
extractor: Arc<CodeExtractor>,
harness: CargoHarness,
}
impl ClippyEvaluator {
#[must_use]
pub fn new(extractor: Arc<CodeExtractor>) -> Self {
Self {
name: "clippy",
extractor,
harness: CargoHarness::default(),
}
}
#[must_use]
pub const fn with_name(mut self, name: &'static str) -> Self {
self.name = name;
self
}
#[must_use]
pub fn with_harness(mut self, harness: CargoHarness) -> Self {
self.harness = harness;
self
}
}
impl Evaluator for ClippyEvaluator {
fn name(&self) -> &'static str {
self.name
}
fn evaluate(&self, _case: &EvalCase, invocation: &Invocation) -> Option<EvalMetricResult> {
let response = invocation.final_response.as_ref()?;
let code = crate::evaluators::block_on(self.extractor.extract(response))?;
let outcome = run_cargo(&self.harness, &code, &["clippy", "--", "-D", "warnings"]);
Some(outcome.into_metric_result(self.name))
}
}