Skip to content

Commit

Permalink
Simplify code as suggested by Micha
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLuo committed Sep 9, 2024
1 parent 325b534 commit c5d7f1d
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions crates/ruff_linter/src/message/sarif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::io::Write;
use anyhow::Result;
use serde::{Serialize, Serializer};
use serde_json::json;
use strum::IntoEnumIterator;

use ruff_source_file::OneIndexed;

Expand All @@ -28,12 +27,9 @@ impl Emitter for SarifEmitter {
.map(SarifResult::from_message)
.collect::<Result<Vec<_>>>()?;

let mut rule_ids = HashSet::new();
for result in &results {
if let Some(rule) = result.rule {
rule_ids.insert(rule.noqa_code().to_string());
}
}
let unique_rules: HashSet<_> = results.iter().filter_map(|result| result.rule).collect();
let mut rules: Vec<SarifRule> = unique_rules.into_iter().map(SarifRule::from).collect();
rules.sort_by(|a, b| a.code.cmp(&b.code));

let output = json!({
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
Expand All @@ -43,10 +39,7 @@ impl Emitter for SarifEmitter {
"driver": {
"name": "ruff",
"informationUri": "https://github.com/astral-sh/ruff",
"rules": Rule::iter()
.filter(|rule| rule_ids.contains(&rule.noqa_code().to_string()))
.map(SarifRule::from)
.collect::<Vec<_>>(),
"rules": rules,
"version": VERSION.to_string(),
}
},
Expand Down

0 comments on commit c5d7f1d

Please sign in to comment.