diagnostics: reduce complexity of redundant rule checks
This commit is contained in:
parent
d36120c87b
commit
9791296634
1 changed files with 17 additions and 20 deletions
|
@ -1000,7 +1000,7 @@ impl SemanticAnalyzer {
|
|||
|
||||
fn check_for_redundant_rules(&self, source: &str) -> Vec<Diagnostic> {
|
||||
let mut diagnostics = Vec::new();
|
||||
let mut rules = Vec::new();
|
||||
let mut seen_rules = HashSet::new();
|
||||
|
||||
for (line_idx, line) in source.lines().enumerate() {
|
||||
let line_num = line_idx as u32;
|
||||
|
@ -1011,26 +1011,23 @@ impl SemanticAnalyzer {
|
|||
|| trimmed.contains(" drop")
|
||||
|| trimmed.contains(" reject")
|
||||
{
|
||||
for (existing_idx, existing_rule) in rules.iter().enumerate() {
|
||||
if existing_rule == &trimmed {
|
||||
let range = Range::new(
|
||||
Position::new(line_num, 0),
|
||||
Position::new(line_num, line.len() as u32),
|
||||
);
|
||||
let diagnostic = Diagnostic::new(
|
||||
range,
|
||||
DiagnosticSeverity::Warning,
|
||||
DiagnosticCode::RedundantRule,
|
||||
format!(
|
||||
"Duplicate rule found (first occurrence at line {})",
|
||||
existing_idx + 1
|
||||
),
|
||||
);
|
||||
diagnostics.push(diagnostic);
|
||||
break;
|
||||
}
|
||||
// Check if rule already exists in the HashSet
|
||||
if seen_rules.contains(trimmed) {
|
||||
let range = Range::new(
|
||||
Position::new(line_num, 0),
|
||||
Position::new(line_num, line.len() as u32),
|
||||
);
|
||||
let diagnostic = Diagnostic::new(
|
||||
range,
|
||||
DiagnosticSeverity::Warning,
|
||||
DiagnosticCode::RedundantRule,
|
||||
"Duplicate rule found".to_string(),
|
||||
);
|
||||
diagnostics.push(diagnostic);
|
||||
} else {
|
||||
// Add the rule to the HashSet if it's not a duplicate
|
||||
seen_rules.insert(trimmed.to_string());
|
||||
}
|
||||
rules.push(trimmed.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue