-
Notifications
You must be signed in to change notification settings - Fork 176
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
Clippy lints + clippy CI #341
Conversation
@@ -14,35 +13,14 @@ pub(crate) fn read_file_content(file: File) -> Result<String, std::io::Error> { | |||
Ok(file_content) | |||
} | |||
|
|||
pub(crate) fn get_files<F>(file: &str, sort: F) -> Result<Vec<PathBuf>, Error> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function not used anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope
guard/src/commands/helper.rs
Outdated
pub fn validate_and_return_json( | ||
data: ValidateInput, | ||
rules: ValidateInput, | ||
verbose: bool, | ||
) -> Result<String> { | ||
let input_data = match serde_json::from_str::<serde_json::Value>(&data.content) { | ||
let input_data = match serde_json::from_str::<serde_json::Value>(data.content) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does changing reference to value not have any effect here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it doesnt...Since the content field of ValidateInput is already a &str
the reference infront of &data.content
is immediately being dereferenced by the compiler
guard/src/commands/validate/cfn.rs
Outdated
}) | ||
}; | ||
|
||
Ok(()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the older code, aren't we returning a writer as a result? In the newer one we are not?
Ok(... serde_yaml::to_writer())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function signature is unchanged. Those 3 methods inside the if statement all return a unit type. This is exactly the reason why its best practice to not to do something like
Ok(some_fn() -> Result<()>)
it makes it seem like we're returning something more than a unit type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kotlin has 'Unit' too
guard/src/commands/validate/cfn.rs
Outdated
@@ -465,7 +432,7 @@ fn handle_resource_aggr<'record, 'value: 'record>( | |||
root: &'value Node<'_>, | |||
name: String, | |||
by_resources: &mut HashMap<String, LocalResourceAggr<'record, 'value>>, | |||
value: &Vec<Rc<crate::commands::validate::common::Node<'record, 'value>>>, | |||
value: &[Rc<crate::commands::validate::common::Node<'record, 'value>>], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we changing a data type here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically yes, but it doesnt require any change other than function signature. https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
@@ -181,7 +172,7 @@ impl super::common::GenericReporter for SingleLineReporter { | |||
by_resource_name: HashMap<String, Vec<NameInfo<'_>>>, | |||
passed: HashSet<String>, | |||
skipped: HashSet<String>, | |||
longest_rule_len: usize, | |||
_longest_rule_len: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming Clippy adds _
as prefix to variables that aren't used? Can you confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
confirmed
// copy.push('/'); | ||
// copy.push_str(part); | ||
// Path(copy, loc) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this chunk commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compiler was complaining about unused code, and i commented it out and ran the test suite + did manual testing to make sure it wasnt actually being used...Forgot to delete it. Good catch
guard/src/rules/functions/strings.rs
Outdated
@@ -1,194 +0,0 @@ | |||
use crate::rules::path_value::{Path, PathAwareValue}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasnt being used anywhere
guard/src/rules/eval/operators.rs
Outdated
QueryResult::UnResolved(ur) => Err(err(ur.clone())), | ||
} | ||
} | ||
// pub(super) fn resolved<'value, E, R>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this chunk commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as the previous commented out chunk
* Added 2 runners to integration tests for rules registry * Fixed indent * Added explicit shell name * Moved shell to job parameters * Added powershell commands for windows * Removed test branch * Updated README.md (aws-cloudformation#352) * Updated README for Guard 3.0 * Update README.md Co-authored-by: Ben Bridts <ben.bridts@gmail.com> --------- Co-authored-by: Ben Bridts <ben.bridts@gmail.com> --------- Co-authored-by: Akshay Rane <raneaks@amazon.com> Co-authored-by: razcloud <34892703+razcloud@users.noreply.github.com> Co-authored-by: Ben Bridts <ben.bridts@gmail.com>
@@ -2,9 +2,9 @@ name: Rust | |||
|
|||
on: | |||
push: | |||
branches: [ main, development, rogue_one] | |||
branches: [ main, development, rogue_one ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
pub(crate) fn extend_string(&self, part: &String) -> Path { | ||
self.extend_str(part.as_str()) | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider deletion
rejecting this in favour of #371 |
Issue #, if available:
#208
Description of changes:
As part of our goal to improve code quality, we are addressing all clippy lints in our project + adding a clippy check to our CI
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license