Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed May 14, 2024
1 parent 4388a05 commit 3810ca6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
20 changes: 7 additions & 13 deletions src/applier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ fn apply_file_metadata_conditions(

rules_with_conditions.retain(|(_, path_condition)| {
for content_condition_node in &path_condition.content_conditions {
match &content_condition_node.condition {
ContentCondition::Size(size_condition) => {
if !size_condition.check(size) {
return false;
}
if let ContentCondition::Size(size_condition) = &content_condition_node.condition {
if !size_condition.check(size) {
return false;
}
_ => {}
}
}
true
Expand All @@ -45,14 +42,11 @@ fn apply_file_line_conditions(
) {
rules_with_conditions.retain(|(_, path_condition)| {
for content_condition_node in &path_condition.content_conditions {
match &content_condition_node.condition {
ContentCondition::Lines(size_condition) => {
if !size_condition.check(num_lines) {
rules_with_conditions_to_finalize.remove(&path_condition.number);
return false;
}
if let ContentCondition::Lines(size_condition) = &content_condition_node.condition {
if !size_condition.check(num_lines) {
rules_with_conditions_to_finalize.remove(&path_condition.number);
return false;
}
_ => {}
}
}
true
Expand Down
8 changes: 4 additions & 4 deletions src/config/dumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ fn dump_content_condition(content_condition_node: &ContentConditionNode) {
match &content_condition_node.condition {
ContentCondition::Match(regex_condition) => {
print!(" match");
dump_regex_condition_args(&regex_condition);
dump_regex_condition_args(regex_condition);
}
ContentCondition::NoMatch(regex_condition) => {
print!(" nomatch");
dump_regex_condition_args(&regex_condition);
dump_regex_condition_args(regex_condition);
}
ContentCondition::Size(size_condition) => {
print!(" size");
dump_size_condition_args(&size_condition);
dump_size_condition_args(size_condition);
}
ContentCondition::Lines(size_condition) => {
print!(" lines");
dump_size_condition_args(&size_condition);
dump_size_condition_args(size_condition);
}
}
println!();
Expand Down
13 changes: 6 additions & 7 deletions src/config/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn parse_regexes_condition(pair: pest::iterators::Pair<Rule>) -> Result<RegexCon
}

fn parse_size_condition(pair: pest::iterators::Pair<Rule>) -> Result<SizeCondition, PestError> {
let mut iter = pair.into_inner().into_iter();
let mut iter = pair.into_inner();
let operator = iter.next().unwrap();
let value = iter.next().unwrap();

Expand Down Expand Up @@ -266,7 +266,7 @@ fn parse_rule(
if title.is_empty() {
rule.title = format!(
"rule from {}:{} (#{})",
config_path.display().to_string(),
config_path.display(),
line_number,
rule_number + 1
);
Expand Down Expand Up @@ -433,13 +433,12 @@ impl Config {
}

pub fn from_file(path: &Path) -> Result<Config, Error> {
let content = fs::read_to_string(&path).with_context(|| {
format!("failed to read config file {}", path.display().to_string())
})?;
let content = fs::read_to_string(path)
.with_context(|| format!("failed to read config file {}", path.display()))?;

parse_file(&content, &path)
parse_file(&content, path)
.map_err(|e| e.with_path(&path.display().to_string()))
.with_context(|| format!("failed to parse config file {}", path.display().to_string()))
.with_context(|| format!("failed to parse config file {}", path.display()))
}

pub fn from_file_expand_includes(path: &Path) -> Result<Config, Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/config/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn get_first_regex_exclude(config: &Config) -> &Regex {

fn get_first_size_condition(config: &Config) -> &SizeCondition {
match &config.ruleset.rules[0].path_conditions[0].content_conditions[0].condition {
ContentCondition::Size(size_condition) => &size_condition,
ContentCondition::Size(size_condition) => size_condition,
_ => panic!(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ruleset/parts/content_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl ContentConditionNode {
ContentConditionNode {
number: Default::default(),
is_reporting_target: Default::default(),
condition: condition,
condition,
}
}
}
2 changes: 1 addition & 1 deletion tests/config_parse_dump_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn with_test_config() {
let input_path = Path::new("tests/config_parse_dump_test.conf");

let first_dump = read_to_string(input_path).unwrap().replace('\r', ""); // line endings could be changed by git
let second_dump = parse_dump_config(&input_path);
let second_dump = parse_dump_config(input_path);

pretty_assertions::assert_eq!(first_dump, second_dump);
}
Expand Down

0 comments on commit 3810ca6

Please sign in to comment.