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

Clippy lints + clippy CI #341

Closed

Conversation

joshfried-aws
Copy link
Contributor

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

@@ -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>
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope

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) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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

})
};

Ok(())
Copy link
Collaborator

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())

Copy link
Contributor Author

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kotlin has 'Unit' too

@@ -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>>],
Copy link
Collaborator

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?

Copy link
Contributor Author

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,
Copy link
Collaborator

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?

Copy link
Contributor Author

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)
// }
Copy link
Collaborator

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?

Copy link
Contributor Author

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

@@ -1,194 +0,0 @@
use crate::rules::path_value::{Path, PathAwareValue};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these removed?

Copy link
Contributor Author

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/functions/collections.rs Outdated Show resolved Hide resolved
guard/src/rules/eval_context_tests.rs Outdated Show resolved Hide resolved
QueryResult::UnResolved(ur) => Err(err(ur.clone())),
}
}
// pub(super) fn resolved<'value, E, R>(
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Akshay Rane and others added 8 commits June 9, 2023 10:13
* 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 ]

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())
//

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider deletion

@joshfried-aws
Copy link
Contributor Author

rejecting this in favour of #371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants