Skip to content

Commit

Permalink
Organize imports (#899)
Browse files Browse the repository at this point in the history
Group imports by crate.
Add instructions to the PR template about clippy and fmt.
Remove PR comments because they don't work on forks.

Signed-off-by: David Calavera <[email protected]>
  • Loading branch information
calavera authored Jun 26, 2024
1 parent f484569 commit 3a049fe
Show file tree
Hide file tree
Showing 42 changed files with 155 additions and 181 deletions.
10 changes: 6 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
*Issue #, if available:*
📬 *Issue #, if available:*

*Description of changes:*
✍️ *Description of changes:*

By submitting this pull request
🔏 *By submitting this pull request*

- [ ] I confirm that my contribution is made under the terms of the Apache 2.0 license.
- [ ] I confirm that I've ran `cargo +nightly fmt`.
- [ ] I confirm that I've ran `cargo clippy --fix`.
- [ ] I confirm that I've made a best effort attempt to update all relevant documentation.
- [ ] I confirm that my contribution is made under the terms of the Apache 2.0 license.
50 changes: 13 additions & 37 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,29 @@ name: Formatting and Linting
on: [push, pull_request]

jobs:
check:
fmt:
name: Cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- uses: Swatinem/rust-cache@v2

- name: Run fmt check
id: cargoFmt
shell: bash
run: cargo fmt --all -- --check
- name: Notify fmt check
if: failure() && steps.cargoFmt.outcome == 'failure'
uses: actions/github-script@v6
with:
script: |
const message = `👋 It looks like your code is not formatted like we expect.
Please run \`cargo fmt\` and push the code again.`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message,
});
core.setFailed('It looks like there are formatting errors');

run: cargo +nightly fmt --all -- --check
clippy:
name: Cargo clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run clippy check
id: cargoClippy
shell: bash
run: cargo clippy --workspace --all-features -- -D warnings
- name: Notify fmt check
if: failure() && steps.cargoClippy.outcome == 'failure'
uses: actions/github-script@v6
with:
script: |
const message = `👋 It looks like your code has some linting issues.
Please run \`cargo clippy --fix\` and push the code again.`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message,
});
core.setFailed('It looks like there are linting errors');


14 changes: 11 additions & 3 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
edition = "2021"
# imports_granularity is unstable
# # https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#merge_imports
# imports_granularity = "Crate"

# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#max_width
max_width = 120

#https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#reorder_imports
reorder_imports = true

#https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#unstable_features
unstable_features = true

# imports_granularity is unstable
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#merge_imports
imports_granularity = "Crate"
2 changes: 1 addition & 1 deletion lambda-events/src/custom_serde/codebuild_time.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chrono::{DateTime, NaiveDateTime, Utc};
use serde::ser::Serializer;
use serde::{
de::{Deserializer, Error as DeError, Visitor},
ser::Serializer,
Deserialize,
};
use std::fmt;
Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/custom_serde/float_unix_epoch.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use serde::{de, ser};
use std::fmt;

use chrono::offset::TimeZone;
use chrono::{DateTime, LocalResult, Utc};
use chrono::{offset::TimeZone, DateTime, LocalResult, Utc};

enum SerdeError<V: fmt::Display, D: fmt::Display> {
NonExistent { timestamp: V },
Expand Down
9 changes: 5 additions & 4 deletions lambda-events/src/custom_serde/headers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use http::header::HeaderName;
use http::{HeaderMap, HeaderValue};
use serde::de::{self, Deserializer, Error as DeError, MapAccess, Unexpected, Visitor};
use serde::ser::{Error as SerError, SerializeMap, Serializer};
use http::{header::HeaderName, HeaderMap, HeaderValue};
use serde::{
de::{self, Deserializer, Error as DeError, MapAccess, Unexpected, Visitor},
ser::{Error as SerError, SerializeMap, Serializer},
};
use std::{borrow::Cow, fmt};

/// Serialize a http::HeaderMap into a serde str => Vec<str> map
Expand Down
6 changes: 4 additions & 2 deletions lambda-events/src/custom_serde/http_method.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use http::Method;
use serde::de::{Deserialize, Deserializer, Error as DeError, Unexpected, Visitor};
use serde::ser::Serializer;
use serde::{
de::{Deserialize, Deserializer, Error as DeError, Unexpected, Visitor},
ser::Serializer,
};
use std::fmt;

pub fn serialize<S: Serializer>(method: &Method, ser: S) -> Result<S::Ok, S::Error> {
Expand Down
6 changes: 4 additions & 2 deletions lambda-events/src/custom_serde/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use base64::Engine;
use serde::de::{Deserialize, Deserializer, Error as DeError};
use serde::ser::Serializer;
use serde::{
de::{Deserialize, Deserializer, Error as DeError},
ser::Serializer,
};
use std::collections::HashMap;

#[cfg(feature = "codebuild")]
Expand Down
6 changes: 4 additions & 2 deletions lambda-events/src/encodings/http.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use base64::display::Base64Display;
use bytes::Bytes;
use http_body::{Body as HttpBody, SizeHint};
use serde::de::{Deserialize, Deserializer, Error as DeError, Visitor};
use serde::ser::{Error as SerError, Serialize, Serializer};
use serde::{
de::{Deserialize, Deserializer, Error as DeError, Visitor},
ser::{Error as SerError, Serialize, Serializer},
};
use std::{borrow::Cow, mem::take, ops::Deref, pin::Pin, task::Poll};

/// Representation of http request and response bodies as supported
Expand Down
2 changes: 1 addition & 1 deletion lambda-events/src/encodings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use std::{ops::Deref, ops::DerefMut};
use std::ops::{Deref, DerefMut};

#[cfg(feature = "chrono")]
mod time;
Expand Down
2 changes: 1 addition & 1 deletion lambda-events/src/encodings/time.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chrono::{DateTime, TimeDelta, TimeZone, Utc};
use serde::ser::Serializer;
use serde::{
de::{Deserializer, Error as DeError},
ser::Serializer,
Deserialize, Serialize,
};
use std::ops::{Deref, DerefMut};
Expand Down
8 changes: 5 additions & 3 deletions lambda-events/src/event/alb/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::custom_serde::{
deserialize_headers, deserialize_nullish_boolean, http_method, serialize_headers, serialize_multi_value_headers,
use crate::{
custom_serde::{
deserialize_headers, deserialize_nullish_boolean, http_method, serialize_headers, serialize_multi_value_headers,
},
encodings::Body,
};
use crate::encodings::Body;
use http::{HeaderMap, Method};
use query_map::QueryMap;
use serde::{Deserialize, Serialize};
Expand Down
12 changes: 7 additions & 5 deletions lambda-events/src/event/apigw/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::custom_serde::{
deserialize_headers, deserialize_lambda_map, deserialize_nullish_boolean, http_method, serialize_headers,
serialize_multi_value_headers,
use crate::{
custom_serde::{
deserialize_headers, deserialize_lambda_map, deserialize_nullish_boolean, http_method, serialize_headers,
serialize_multi_value_headers,
},
encodings::Body,
iam::IamPolicyStatement,
};
use crate::encodings::Body;
use crate::iam::IamPolicyStatement;
use http::{HeaderMap, Method};
use query_map::QueryMap;
use serde::{de::DeserializeOwned, ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/event/appsync/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/event/autoscaling/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use chrono::{DateTime, Utc};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/event/cloudformation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ pub enum CloudFormationCustomResourceResponseStatus {
mod test {
use std::collections::HashMap;

use super::CloudFormationCustomResourceRequest::*;
use super::*;
use super::{CloudFormationCustomResourceRequest::*, *};

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/event/cloudformation/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ where
mod test {
use std::collections::HashMap;

use super::CloudFormationCustomResourceRequest::*;
use super::*;
use super::{CloudFormationCustomResourceRequest::*, *};

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/event/cloudwatch_events/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use chrono::{DateTime, Utc};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;

pub mod cloudtrail;
Expand Down
9 changes: 5 additions & 4 deletions lambda-events/src/event/codebuild/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::custom_serde::{codebuild_time, CodeBuildNumber};
use crate::encodings::{MinuteDuration, SecondDuration};
use crate::{
custom_serde::{codebuild_time, CodeBuildNumber},
encodings::{MinuteDuration, SecondDuration},
};
use chrono::{DateTime, Utc};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;

pub type CodeBuildPhaseStatus = String;
Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/event/cognito/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

Expand Down
8 changes: 5 additions & 3 deletions lambda-events/src/event/dynamodb/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::custom_serde::deserialize_lambda_dynamodb_item;
use crate::time_window::*;
use crate::{custom_serde::float_unix_epoch, streams::DynamoDbBatchItemFailure};
use crate::{
custom_serde::{deserialize_lambda_dynamodb_item, float_unix_epoch},
streams::DynamoDbBatchItemFailure,
time_window::*,
};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::fmt;
Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/event/eventbridge/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use chrono::{DateTime, Utc};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;

/// Parse EventBridge events.
Expand Down
4 changes: 1 addition & 3 deletions lambda-events/src/event/iot/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::custom_serde::serialize_headers;
use crate::encodings::Base64Data;
use crate::iam::IamPolicyDocument;
use crate::{custom_serde::serialize_headers, encodings::Base64Data, iam::IamPolicyDocument};
use http::HeaderMap;
use serde::{Deserialize, Serialize};

Expand Down
6 changes: 4 additions & 2 deletions lambda-events/src/event/kinesis/event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::encodings::{Base64Data, SecondTimestamp};
use crate::time_window::{TimeWindowEventResponseProperties, TimeWindowProperties};
use crate::{
encodings::{Base64Data, SecondTimestamp},
time_window::{TimeWindowEventResponseProperties, TimeWindowProperties},
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/event/rabbitmq/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/event/s3/object_lambda.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use http::HeaderMap;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

Expand Down
3 changes: 1 addition & 2 deletions lambda-events/src/event/sns/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use chrono::{DateTime, Utc};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::collections::HashMap;

use crate::custom_serde::{deserialize_lambda_map, deserialize_nullish_boolean};
Expand Down
6 changes: 2 additions & 4 deletions lambda-events/src/event/sqs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::custom_serde::deserialize_lambda_map;
use crate::encodings::Base64Data;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use crate::{custom_serde::deserialize_lambda_map, encodings::Base64Data};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::collections::HashMap;

/// The Event sent to Lambda from SQS. Contains 1 or more individual SQS Messages
Expand Down
12 changes: 8 additions & 4 deletions lambda-extension/src/extension.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use http::Request;
use http_body_util::BodyExt;
use hyper::body::Incoming;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::{body::Incoming, server::conn::http1, service::service_fn};

use hyper_util::rt::tokio::TokioIo;
use lambda_runtime_api_client::Client;
use serde::Deserialize;
use std::{
convert::Infallible, fmt, future::ready, future::Future, net::SocketAddr, path::PathBuf, pin::Pin, sync::Arc,
convert::Infallible,
fmt,
future::{ready, Future},
net::SocketAddr,
path::PathBuf,
pin::Pin,
sync::Arc,
};
use tokio::{net::TcpListener, sync::Mutex};
use tokio_stream::StreamExt;
Expand Down
7 changes: 2 additions & 5 deletions lambda-http/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ use aws_lambda_events::apigw::{ApiGatewayV2httpRequest, ApiGatewayV2httpRequestC
#[cfg(feature = "apigw_websockets")]
use aws_lambda_events::apigw::{ApiGatewayWebsocketProxyRequest, ApiGatewayWebsocketProxyRequestContext};
use aws_lambda_events::{encodings::Body, query_map::QueryMap};
use http::header::HeaderName;
use http::{HeaderMap, HeaderValue};
use http::{header::HeaderName, HeaderMap, HeaderValue};

use serde::{Deserialize, Serialize};
use serde_json::error::Error as JsonError;

use std::future::Future;
use std::pin::Pin;
use std::{env, io::Read};
use std::{env, future::Future, io::Read, pin::Pin};
use url::Url;

/// Internal representation of an Lambda http event from
Expand Down
Loading

0 comments on commit 3a049fe

Please sign in to comment.