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> {
|
fn check_for_redundant_rules(&self, source: &str) -> Vec<Diagnostic> {
|
||||||
let mut diagnostics = Vec::new();
|
let mut diagnostics = Vec::new();
|
||||||
let mut rules = Vec::new();
|
let mut seen_rules = HashSet::new();
|
||||||
|
|
||||||
for (line_idx, line) in source.lines().enumerate() {
|
for (line_idx, line) in source.lines().enumerate() {
|
||||||
let line_num = line_idx as u32;
|
let line_num = line_idx as u32;
|
||||||
|
@ -1011,8 +1011,8 @@ impl SemanticAnalyzer {
|
||||||
|| trimmed.contains(" drop")
|
|| trimmed.contains(" drop")
|
||||||
|| trimmed.contains(" reject")
|
|| trimmed.contains(" reject")
|
||||||
{
|
{
|
||||||
for (existing_idx, existing_rule) in rules.iter().enumerate() {
|
// Check if rule already exists in the HashSet
|
||||||
if existing_rule == &trimmed {
|
if seen_rules.contains(trimmed) {
|
||||||
let range = Range::new(
|
let range = Range::new(
|
||||||
Position::new(line_num, 0),
|
Position::new(line_num, 0),
|
||||||
Position::new(line_num, line.len() as u32),
|
Position::new(line_num, line.len() as u32),
|
||||||
|
@ -1021,17 +1021,14 @@ impl SemanticAnalyzer {
|
||||||
range,
|
range,
|
||||||
DiagnosticSeverity::Warning,
|
DiagnosticSeverity::Warning,
|
||||||
DiagnosticCode::RedundantRule,
|
DiagnosticCode::RedundantRule,
|
||||||
format!(
|
"Duplicate rule found".to_string(),
|
||||||
"Duplicate rule found (first occurrence at line {})",
|
|
||||||
existing_idx + 1
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
diagnostics.push(diagnostic);
|
diagnostics.push(diagnostic);
|
||||||
break;
|
} else {
|
||||||
|
// Add the rule to the HashSet if it's not a duplicate
|
||||||
|
seen_rules.insert(trimmed.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rules.push(trimmed.to_string());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
diagnostics
|
diagnostics
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue