Skip to content

Commit a231e87

Browse files
greenpixels (Sven Teigler)greenpixels (Sven Teigler)
authored andcommitted
refactor allowed location rules
1 parent bf5e579 commit a231e87

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/rules/rule_allowed_custom_resource_location.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,26 @@ pub fn execute_rule_allowed_custom_resource_location(
2929
}
3030

3131
let mut in_correct_root = false;
32-
let mut has_rule_entry = false;
33-
let mut matched_locations: Vec<String> = vec![];
32+
let mut matched_allowed_locations: Vec<String> = vec![];
3433

34+
// Check if file matches any configured patterns
3535
for (custom_resource_class_name, locations) in config.allowed_custom_resource_locations.iter() {
3636
if resource_name.eq(custom_resource_class_name) {
37-
has_rule_entry = true;
3837
for location in locations {
39-
matched_locations.push(location.to_owned());
38+
matched_allowed_locations.push(location.to_owned());
4039
if glob_match(location, &file.relative_path) {
4140
in_correct_root = true;
41+
break;
4242
}
4343
}
4444
}
4545
}
46-
if !has_rule_entry {
46+
47+
if matched_allowed_locations.is_empty() {
4748
return;
4849
}
49-
let folders_list = matched_locations.join(" or ");
50+
51+
let folders_list = matched_allowed_locations.join(" or ");
5052

5153
let validation_output = handle_validation_result(
5254
in_correct_root,

src/rules/rule_allowed_file_location.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,30 @@ pub fn execute_rule_allowed_file_location(
2222
return;
2323
}
2424

25-
let mut in_correct_root = false;
26-
let mut has_path_entry = false;
27-
let mut matched_locations: Vec<String> = vec![];
25+
let mut is_in_correct_location = false;
26+
let mut matched_allowed_locations: Vec<String> = vec![];
2827

28+
// Check if file matches any configured patterns
2929
for (pattern, locations) in config.allowed_file_locations.iter() {
3030
if glob_match(pattern, &file.relative_path) {
31-
has_path_entry = true;
3231
for location in locations {
33-
matched_locations.push(location.to_owned());
32+
matched_allowed_locations.push(location.to_owned());
3433
if glob_match(location, &file.relative_path) {
35-
in_correct_root = true;
34+
is_in_correct_location = true;
35+
break;
3636
}
3737
}
3838
}
3939
}
40-
if !has_path_entry {
40+
41+
if matched_allowed_locations.is_empty() {
4142
return;
4243
}
43-
let folders_list = matched_locations.join(" or ");
44+
45+
let folders_list = matched_allowed_locations.join(" or ");
4446

4547
let validation_output = handle_validation_result(
46-
in_correct_root,
48+
is_in_correct_location,
4749
"rule-allowed-file-location".to_owned(),
4850
format!("Found {} in correct location", file.file_name.bold()),
4951
format!(
@@ -56,7 +58,8 @@ pub fn execute_rule_allowed_file_location(
5658
test_results,
5759
file,
5860
);
59-
if validation_output.is_some() {
60-
println!("{}", validation_output.unwrap())
61+
62+
if let Some(output) = validation_output {
63+
println!("{}", output);
6164
}
6265
}

0 commit comments

Comments
 (0)