Fix clippy lints and run formatter (#2080)

* fix: clippy lints in integration tests
format: integration tests

* fix: clippy lints in runtime crates
format: runtime crates

* fix: clippy lints in tools
format: tools

* fix: undo clippy lint change that doesn't compile with tracing v0.1
This commit is contained in:
Zelda Hessler 2022-12-09 13:00:02 -06:00 committed by GitHub
parent a15ce735b9
commit f3e05625e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 55 additions and 57 deletions

View File

@ -115,11 +115,11 @@ impl CredentialProcessProvider {
let mut command = if cfg!(windows) {
let mut command = Command::new("cmd.exe");
command.args(&["/C", self.command.unredacted()]);
command.args(["/C", self.command.unredacted()]);
command
} else {
let mut command = Command::new("sh");
command.args(&["-c", self.command.unredacted()]);
command.args(["-c", self.command.unredacted()]);
command
};

View File

@ -123,9 +123,9 @@ pub(super) fn resolve_chain<'a>(
// - There is not default profile
// Then:
// - Treat this situation as if no profiles were defined
if profile_override == None
if profile_override.is_none()
&& profile_set.selected_profile() == "default"
&& profile_set.get_profile("default") == None
&& profile_set.get_profile("default").is_none()
{
tracing::debug!("No default profile defined");
return Err(ProfileFileError::NoProfilesDefined);

View File

@ -140,7 +140,7 @@ fn validate_identifier(input: &str) -> Result<&str, ()> {
.iter()
.any(|c| *c == ch)
})
.then(|| input)
.then_some(input)
.ok_or(())
}

View File

@ -26,7 +26,7 @@ async fn set_correct_headers() {
.await;
let req = handler.expect_request();
assert_ok(validate_headers(
&req.headers(),
req.headers(),
[
(
"x-amz-sha256-tree-hash",

View File

@ -55,7 +55,12 @@ async fn client_is_debug() {
async fn client_is_clone() {
let conf = kms::Config::builder().build();
let client = kms::Client::from_conf(conf);
let _ = client.clone();
fn is_clone(it: impl Clone) {
drop(it)
}
is_clone(client);
}
#[test]

View File

@ -74,7 +74,7 @@ async fn test_s3_signer_with_naughty_string_metadata() {
for (idx, line) in NAUGHTY_STRINGS.split('\n').enumerate() {
// add lines to metadata unless they're a comment or empty
// Some naughty strings aren't valid HeaderValues so we skip those too
if !line.starts_with("#") && !line.is_empty() && HeaderValue::from_str(line).is_ok() {
if !line.starts_with('#') && !line.is_empty() && HeaderValue::from_str(line).is_ok() {
let key = format!("line-{}", idx);
builder = builder.metadata(key, line);

View File

@ -111,15 +111,13 @@ Hello"#;
}
}
if socket.writable().await.is_ok() {
if time_to_respond {
// The content length is 12 but we'll only write 5 bytes
socket.try_write(&response).unwrap();
// We break from the R/W loop after sending a partial response in order to
// close the connection early.
debug!("faulty server has written partial response, now closing connection");
break;
}
if socket.writable().await.is_ok() && time_to_respond {
// The content length is 12 but we'll only write 5 bytes
socket.try_write(response).unwrap();
// We break from the R/W loop after sending a partial response in order to
// close the connection early.
debug!("faulty server has written partial response, now closing connection");
break;
}
}
}

View File

@ -81,11 +81,10 @@ async fn test_read_timeout() {
(
async move {
while shutdown_receiver.try_recv().is_err() {
if let Ok(result) = timeout(Duration::from_millis(100), listener.accept()).await
if let Ok(Ok((_socket, _))) =
timeout(Duration::from_millis(100), listener.accept()).await
{
if let Ok((_socket, _)) = result {
tokio::time::sleep(Duration::from_millis(1000)).await;
}
tokio::time::sleep(Duration::from_millis(1000)).await;
}
}
},

View File

@ -38,7 +38,7 @@ async fn test_success() {
match event {
TranscriptResultStream::TranscriptEvent(transcript_event) => {
let transcript = transcript_event.transcript.unwrap();
for result in transcript.results.unwrap_or_else(Vec::new) {
for result in transcript.results.unwrap_or_default() {
if !result.is_partial {
let first_alternative = &result.alternatives.as_ref().unwrap()[0];
full_message += first_alternative.transcript.as_ref().unwrap();

View File

@ -140,7 +140,7 @@ pub trait PyApp: Clone + pyo3::IntoPy<PyObject> {
/// Other signals are NOOP.
fn block_on_rust_signals(&self) {
let mut signals =
Signals::new(&[SIGINT, SIGHUP, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2, SIGWINCH])
Signals::new([SIGINT, SIGHUP, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2, SIGWINCH])
.expect("Unable to register signals");
for sig in signals.forever() {
match sig {
@ -226,7 +226,7 @@ event_loop.add_signal_handler(signal.SIGINT,
) -> PyResult<()> {
// Clone the socket.
let borrow = socket.try_borrow_mut()?;
let held_socket: &PySocket = &*borrow;
let held_socket: &PySocket = &borrow;
let raw_socket = held_socket.get_socket()?;
// Register signals on the Python event loop.
self.register_python_signals(py, event_loop.to_object(py))?;

View File

@ -7,6 +7,7 @@
use crate::rejection::MissingContentTypeReason;
#[allow(deprecated)]
use crate::request::RequestParts;
use http::HeaderMap;
/// When there are no modeled inputs,
/// a request body is empty and the content-type request header must not be set
@ -19,13 +20,7 @@ pub fn content_type_header_empty_body_no_modeled_input<B>(
}
let headers = req.headers().unwrap();
if headers.contains_key(http::header::CONTENT_TYPE) {
let found_mime = headers
.get(http::header::CONTENT_TYPE)
.unwrap() // The header is present, `unwrap` will not panic.
.to_str()
.map_err(MissingContentTypeReason::ToStrError)?
.parse::<mime::Mime>()
.map_err(MissingContentTypeReason::MimeParseError)?;
let found_mime = parse_content_type(headers)?;
Err(MissingContentTypeReason::UnexpectedMimeType {
expected_mime: None,
found_mime: Some(found_mime),
@ -35,6 +30,16 @@ pub fn content_type_header_empty_body_no_modeled_input<B>(
}
}
fn parse_content_type(headers: &HeaderMap) -> Result<mime::Mime, MissingContentTypeReason> {
headers
.get(http::header::CONTENT_TYPE)
.unwrap() // The header is present, `unwrap` will not panic.
.to_str()
.map_err(MissingContentTypeReason::ToStrError)?
.parse::<mime::Mime>()
.map_err(MissingContentTypeReason::MimeParseError)
}
/// Checks that the content-type in request headers is valid
#[allow(deprecated)]
pub fn content_type_header_classifier<B>(
@ -49,31 +54,25 @@ pub fn content_type_header_classifier<B>(
if !headers.contains_key(http::header::CONTENT_TYPE) {
return Ok(());
}
let client_type = headers
.get(http::header::CONTENT_TYPE)
.unwrap() // The header is present, `unwrap` will not panic.
.to_str()
.map_err(MissingContentTypeReason::ToStrError)?
.parse::<mime::Mime>()
.map_err(MissingContentTypeReason::MimeParseError)?;
let found_mime = parse_content_type(headers)?;
// There is a content-type header
// If there is an implied content type, they must match
if let Some(expected_content_type) = expected_content_type {
let content_type = expected_content_type
let expected_mime = expected_content_type
.parse::<mime::Mime>()
// `expected_content_type` comes from the codegen.
.expect("BUG: MIME parsing failed, expected_content_type is not valid. Please file a bug report under https://github.com/awslabs/smithy-rs/issues");
if expected_content_type != client_type {
if expected_content_type != found_mime {
return Err(MissingContentTypeReason::UnexpectedMimeType {
expected_mime: Some(content_type),
found_mime: Some(client_type),
expected_mime: Some(expected_mime),
found_mime: Some(found_mime),
});
}
} else {
// Content-type header and no modeled input (mismatch)
return Err(MissingContentTypeReason::UnexpectedMimeType {
expected_mime: None,
found_mime: Some(client_type),
found_mime: Some(found_mime),
});
}
Ok(())
@ -166,7 +165,7 @@ mod tests {
#[test]
fn check_invalid_content_type() {
let invalid = vec!["application/ajson", "text/xml"];
let invalid = vec!["application/jason", "text/xml"];
for invalid_mime in invalid {
let request = req_content_type(invalid_mime);
let result = content_type_header_classifier(&request, EXPECTED_MIME_APPLICATION_JSON);

View File

@ -244,7 +244,7 @@ pub fn forbid_headers(
) -> Result<(), ProtocolTestFailure> {
for key in forbidden_headers {
// Protocol tests store header lists as comma-delimited
if let Some(value) = normalized_header(headers, *key) {
if let Some(value) = normalized_header(headers, key) {
return Err(ProtocolTestFailure::ForbiddenHeader {
forbidden: key.to_string(),
found: format!("{}: {}", key, value),
@ -260,7 +260,7 @@ pub fn require_headers(
) -> Result<(), ProtocolTestFailure> {
for key in required_headers {
// Protocol tests store header lists as comma-delimited
if normalized_header(headers, *key).is_none() {
if normalized_header(headers, key).is_none() {
return Err(ProtocolTestFailure::MissingHeader {
expected: key.to_string(),
});

View File

@ -404,7 +404,7 @@ mod test {
fn render_full(entries: &[ChangelogEntry], release_header: &str) -> String {
let (header, body) = render(entries, release_header);
return format!("{}{}", header, body);
format!("{header}{body}")
}
#[test]

View File

@ -15,7 +15,7 @@ use std::process::Command;
use tempfile::TempDir;
use time::OffsetDateTime;
const SOURCE_TOML: &'static str = r#"
const SOURCE_TOML: &str = r#"
[[aws-sdk-rust]]
message = "Some change"
references = ["aws-sdk-rust#123", "smithy-rs#456"]
@ -37,7 +37,7 @@ const SOURCE_TOML: &'static str = r#"
author = "another-dev"
"#;
const SDK_MODEL_SOURCE_TOML: &'static str = r#"
const SDK_MODEL_SOURCE_TOML: &str = r#"
[[aws-sdk-model]]
module = "aws-sdk-ec2"
version = "0.12.0"
@ -390,7 +390,7 @@ Old entry contents
/// set, which should result in the default
#[test]
fn render_smithy_entries() {
const NEXT_CHANGELOG: &'static str = r#"
const NEXT_CHANGELOG: &str = r#"
# Example changelog entries
# [[aws-sdk-rust]]
# message = "Fix typos in module documentation for generated crates"
@ -499,7 +499,7 @@ Old entry contents
/// aws_sdk_rust should not be allowed to have target entries
#[test]
fn aws_sdk_cannot_have_target() {
const NEXT_CHANGELOG: &'static str = r#"
const NEXT_CHANGELOG: &str = r#"
# Example changelog entries
# [[aws-sdk-rust]]
# message = "Fix typos in module documentation for generated crates"
@ -565,8 +565,8 @@ author = "rcoh"
change_set: ChangeSet::SmithyRs,
independent_versioning: true,
source: vec![source_path.clone()],
source_to_truncate: source_path.clone(),
changelog_output: dest_path.clone(),
source_to_truncate: source_path,
changelog_output: dest_path,
release_manifest_output: Some(tmp_dir.path().into()),
date_override: Some(OffsetDateTime::UNIX_EPOCH),
previous_release_versions_manifest: None,
@ -579,9 +579,6 @@ author = "rcoh"
.find("aws-sdk-rust changelog entry cannot have an affected target");
assert!(index.is_some());
} else {
assert!(
false,
"This should have been error that aws-sdk-rust has a target entry"
);
panic!("This should have been error that aws-sdk-rust has a target entry");
}
}