Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Misc]: clippy lints #440

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion guard/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ or failure testing.
.unwrap_or(false)
})?;

let path = PathBuf::try_from(file)?;
let path = PathBuf::from(file);

let rule_file = File::open(&path)?;
if !rule_file.metadata()?.is_file() {
Expand Down
2 changes: 1 addition & 1 deletion guard/src/commands/validate/cfn_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Reporter for CfnReporter {
),
"".to_string(),
),
Err(e) => return Err(Error::from(e)),
Err(e) => return Err(Error::from(Box::new(e))),
};
resource_info.path = property_path;
by_resource_name
Expand Down
2 changes: 1 addition & 1 deletion guard/src/commands/validate/tf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn single_line(
let resource_ptr = match RESOURCE_CHANGE_EXTRACTION.captures(key) {
Ok(Some(cap)) => cap.name("index_or_name").unwrap().as_str(),
Ok(None) => unreachable!(),
Err(e) => return Err(Error::from(e)),
Err(e) => return Err(Error::from(Box::new(e))),
};

let address = format!("/resource_changes/{}", resource_ptr);
Expand Down
2 changes: 1 addition & 1 deletion guard/src/rules/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum Error {
#[error("Parser Error when parsing `{0}`")]
ParseError(String),
#[error("Regex expression parse error for rules file {0}")]
RegexError(#[from] fancy_regex::Error),
RegexError(#[from] Box<fancy_regex::Error>),
#[error(
"Could not evaluate clause for a rule with missing property for incoming context `{0}`"
)]
Expand Down
2 changes: 1 addition & 1 deletion guard/src/rules/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn accumulate<'value, 'loc: 'value>(
}

let mut accumulated = Vec::with_capacity(elements.len());
for (_index, each) in elements.iter().enumerate() {
for each in elements.iter() {
accumulated.extend(query_retrieval_with_converter(
query_index + 1,
query,
Expand Down
4 changes: 2 additions & 2 deletions guard/src/rules/eval_context_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ fn extraction_test() -> Result<()> {
root_scope
.rules
.get("aws_route53_recordset")
.map(|s| s.get(0))
.map(|s| s.first())
.and_then(|s| s.copied()),
rules.guard_rules.get(0)
rules.guard_rules.first()
);

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions guard/src/rules/functions/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ pub(crate) fn regex_replace(
match entry {
QueryResult::Literal(v) | QueryResult::Resolved(v) => {
if let PathAwareValue::String((path, val)) = &**v {
let regex = Regex::new(extract_expr)?;
let regex = Regex::try_from(extract_expr).map_err(Box::new)?;
let mut replaced = String::with_capacity(replace_expr.len() * 2);
for cap in regex.captures_iter(val) {
cap?.expand(replace_expr, &mut replaced);
cap.map_err(Box::new)?.expand(replace_expr, &mut replaced);
}
aggr.push(Some(PathAwareValue::String((path.clone(), replaced))));
} else {
Expand Down
2 changes: 1 addition & 1 deletion guard/src/rules/parser_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ fn testing_access_with_cmp<'loc, A, C>(
C: Fn() -> Option<LetValue<'loc>>,
{
for (lhs_sep, rhs_sep) in separators {
for (_idx, (each_op, value_cmp)) in comparators.iter().enumerate() {
for (each_op, value_cmp) in comparators.iter() {
let access_pattern = format!(
"{lhs}{lhs_sep}{op}{rhs_sep}{rhs}",
lhs = lhs,
Expand Down
6 changes: 3 additions & 3 deletions guard/src/rules/path_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,10 @@ fn compare_values(first: &PathAwareValue, other: &PathAwareValue) -> Result<Orde
pub(crate) fn compare_eq(first: &PathAwareValue, second: &PathAwareValue) -> Result<bool, Error> {
let (reg, s) = match (first, second) {
(PathAwareValue::String((_, s)), PathAwareValue::Regex((_, r))) => {
(Regex::new(r.as_str())?, s.as_str())
(Regex::try_from(r.as_str()).map_err(Box::new)?, s.as_str())
}
(PathAwareValue::Regex((_, r)), PathAwareValue::String((_, s))) => {
(Regex::new(r.as_str())?, s.as_str())
(Regex::try_from(r.as_str()).map_err(Box::new)?, s.as_str())
}

(PathAwareValue::String((_, s1)), PathAwareValue::String((_, s2))) => return Ok(s1 == s2),
Expand Down Expand Up @@ -1147,7 +1147,7 @@ pub(crate) fn compare_eq(first: &PathAwareValue, second: &PathAwareValue) -> Res
let match_result = reg.is_match(s);
match match_result {
Ok(is_match) => Ok(is_match),
Err(error) => Err(Error::from(error)),
Err(error) => Err(Error::from(Box::new(error))),
}
}

Expand Down