Skip to content

Commit

Permalink
fix(yaml): fixed loaded rule count by filtering level #1188
Browse files Browse the repository at this point in the history
  • Loading branch information
hitenkoku committed Oct 21, 2023
1 parent a2e2987 commit fba5471
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,21 @@ impl ParseYaml {
}
};

// 指定されたレベルより低いルールは無視する
let doc_level = &yaml_doc["level"]
.as_str()
.unwrap_or("informational")
.to_uppercase();
let doc_level_num = self.level_map.get(doc_level).unwrap_or(&1);
let args_level_num = self.level_map.get(min_level).unwrap_or(&1);
let target_level_num = self.level_map.get(target_level).unwrap_or(&0);
if doc_level_num < args_level_num
|| (target_level_num != &0_u128 && doc_level_num != target_level_num)
{
up_rule_load_cnt("excluded", rule_id.unwrap_or(&String::default()));
return Option::None;
}

let status = yaml_doc["status"].as_str();
if let Some(s) = yaml_doc["status"].as_str() {
// excluded status optionで指定されたstatusとinclude_status optionで指定されたstatus以外のルールは除外する
Expand Down Expand Up @@ -457,20 +472,6 @@ impl ParseYaml {
println!("Loaded rule: {filepath}");
}

// 指定されたレベルより低いルールは無視する
let doc_level = &yaml_doc["level"]
.as_str()
.unwrap_or("informational")
.to_uppercase();
let doc_level_num = self.level_map.get(doc_level).unwrap_or(&1);
let args_level_num = self.level_map.get(min_level).unwrap_or(&1);
let target_level_num = self.level_map.get(target_level).unwrap_or(&0);
if doc_level_num < args_level_num
|| (target_level_num != &0_u128 && doc_level_num != target_level_num)
{
return Option::None;
}

Option::Some((filepath, yaml_doc))
});
self.files.extend(files);
Expand Down

0 comments on commit fba5471

Please sign in to comment.