Skip to content

Commit 853353d

Browse files
bumahkib7claude
andcommitted
fix: collapse nested if statements for clippy compliance
Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 05a4dab commit 853353d

File tree

1 file changed

+44
-51
lines changed

1 file changed

+44
-51
lines changed

crates/common/src/config.rs

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,9 +2055,9 @@ impl SuppressionEngine {
20552055

20562056
// Handle patterns that start with .*/ to also match paths that start
20572057
// directly with the pattern (e.g., "tests/foo.rs" matching "**/tests/**")
2058-
let regex_pattern = if regex_pattern.starts_with(".*/") {
2059-
// Make the leading .*/ optional: (|.*/) matches empty or .*/
2060-
format!("(^|.*/){}", &regex_pattern[3..])
2058+
let regex_pattern = if let Some(rest) = regex_pattern.strip_prefix(".*/") {
2059+
// Make the leading .*/ optional: (^|.*/) matches start or .*/
2060+
format!("(^|.*/){}", rest)
20612061
} else if regex_pattern.starts_with(".*") {
20622062
// Pattern starts with ** but no trailing slash, just use as-is
20632063
regex_pattern
@@ -2126,36 +2126,32 @@ impl SuppressionEngine {
21262126
// 2. Check global path ignores
21272127
if Self::matches_patterns(&path_str, &self.global_patterns) {
21282128
for (i, pattern) in self.global_ignore_paths.iter().enumerate() {
2129-
if let Some(re) = self.global_patterns.get(i) {
2130-
if re.is_match(&path_str.replace('\\', "/")) {
2131-
return SuppressionResult::suppressed(
2132-
SuppressionSource::PathGlobal,
2133-
format!("Path matches global ignore pattern: {}", pattern),
2134-
pattern.clone(),
2135-
);
2136-
}
2129+
if let Some(re) = self.global_patterns.get(i)
2130+
&& re.is_match(&path_str.replace('\\', "/"))
2131+
{
2132+
return SuppressionResult::suppressed(
2133+
SuppressionSource::PathGlobal,
2134+
format!("Path matches global ignore pattern: {}", pattern),
2135+
pattern.clone(),
2136+
);
21372137
}
21382138
}
21392139
}
21402140

21412141
// 3. Check per-rule path ignores
2142-
if let Some(patterns) = self.rule_patterns.get(rule_id) {
2143-
if Self::matches_patterns(&path_str, patterns) {
2144-
if let Some(rule_paths) = self.rule_ignore_paths.get(rule_id) {
2145-
for (i, pattern) in rule_paths.iter().enumerate() {
2146-
if let Some(re) = patterns.get(i) {
2147-
if re.is_match(&path_str.replace('\\', "/")) {
2148-
return SuppressionResult::suppressed(
2149-
SuppressionSource::PathRule,
2150-
format!(
2151-
"Path matches rule-specific ignore pattern: {}",
2152-
pattern
2153-
),
2154-
format!("{}:{}", rule_id, pattern),
2155-
);
2156-
}
2157-
}
2158-
}
2142+
if let Some(patterns) = self.rule_patterns.get(rule_id)
2143+
&& Self::matches_patterns(&path_str, patterns)
2144+
&& let Some(rule_paths) = self.rule_ignore_paths.get(rule_id)
2145+
{
2146+
for (i, pattern) in rule_paths.iter().enumerate() {
2147+
if let Some(re) = patterns.get(i)
2148+
&& re.is_match(&path_str.replace('\\', "/"))
2149+
{
2150+
return SuppressionResult::suppressed(
2151+
SuppressionSource::PathRule,
2152+
format!("Path matches rule-specific ignore pattern: {}", pattern),
2153+
format!("{}:{}", rule_id, pattern),
2154+
);
21592155
}
21602156
}
21612157
}
@@ -2164,19 +2160,16 @@ impl SuppressionEngine {
21642160
for (pattern_rule_id, patterns) in &self.rule_patterns {
21652161
if pattern_rule_id.ends_with("/*") {
21662162
let prefix = pattern_rule_id.trim_end_matches("/*");
2167-
if rule_id.starts_with(prefix) && Self::matches_patterns(&path_str, patterns) {
2168-
if let Some(rule_paths) = self.rule_ignore_paths.get(pattern_rule_id) {
2169-
if let Some(pattern) = rule_paths.first() {
2170-
return SuppressionResult::suppressed(
2171-
SuppressionSource::PathRule,
2172-
format!(
2173-
"Path matches rule-specific ignore pattern: {}",
2174-
pattern
2175-
),
2176-
format!("{}:{}", pattern_rule_id, pattern),
2177-
);
2178-
}
2179-
}
2163+
if rule_id.starts_with(prefix)
2164+
&& Self::matches_patterns(&path_str, patterns)
2165+
&& let Some(rule_paths) = self.rule_ignore_paths.get(pattern_rule_id)
2166+
&& let Some(pattern) = rule_paths.first()
2167+
{
2168+
return SuppressionResult::suppressed(
2169+
SuppressionSource::PathRule,
2170+
format!("Path matches rule-specific ignore pattern: {}", pattern),
2171+
format!("{}:{}", pattern_rule_id, pattern),
2172+
);
21802173
}
21812174
}
21822175
}
@@ -2202,16 +2195,16 @@ impl SuppressionEngine {
22022195
}
22032196

22042197
// 5. Check baseline (applies to all rules including always-enabled)
2205-
if let Some(ref baseline) = self.baseline {
2206-
if let Some(fp) = fingerprint {
2207-
let fingerprint_obj = Fingerprint::from_string(fp.to_string());
2208-
if baseline.contains_fingerprint(&fingerprint_obj) {
2209-
return SuppressionResult::suppressed(
2210-
SuppressionSource::Baseline,
2211-
"Finding is in baseline".to_string(),
2212-
"baseline".to_string(),
2213-
);
2214-
}
2198+
if let Some(ref baseline) = self.baseline
2199+
&& let Some(fp) = fingerprint
2200+
{
2201+
let fingerprint_obj = Fingerprint::from_string(fp.to_string());
2202+
if baseline.contains_fingerprint(&fingerprint_obj) {
2203+
return SuppressionResult::suppressed(
2204+
SuppressionSource::Baseline,
2205+
"Finding is in baseline".to_string(),
2206+
"baseline".to_string(),
2207+
);
22152208
}
22162209
}
22172210

0 commit comments

Comments
 (0)