Skip to content

Commit 3a049fe

Browse files
authored
Organize imports (#899)
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 <david.calavera@gmail.com>
1 parent f484569 commit 3a049fe

File tree

42 files changed

+155
-181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+155
-181
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
*Issue #, if available:*
1+
📬 *Issue #, if available:*
22

3-
*Description of changes:*
3+
✍️ *Description of changes:*
44

5-
By submitting this pull request
5+
🔏 *By submitting this pull request*
66

7-
- [ ] I confirm that my contribution is made under the terms of the Apache 2.0 license.
7+
- [ ] I confirm that I've ran `cargo +nightly fmt`.
8+
- [ ] I confirm that I've ran `cargo clippy --fix`.
89
- [ ] I confirm that I've made a best effort attempt to update all relevant documentation.
10+
- [ ] I confirm that my contribution is made under the terms of the Apache 2.0 license.

.github/workflows/format.yml

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,29 @@ name: Formatting and Linting
33
on: [push, pull_request]
44

55
jobs:
6-
check:
6+
fmt:
7+
name: Cargo fmt
78
runs-on: ubuntu-latest
89
steps:
910
- uses: actions/checkout@v3
10-
- uses: dtolnay/rust-toolchain@stable
11+
- uses: dtolnay/rust-toolchain@nightly
12+
with:
13+
components: rustfmt
1114
- uses: Swatinem/rust-cache@v2
12-
1315
- name: Run fmt check
1416
id: cargoFmt
1517
shell: bash
16-
run: cargo fmt --all -- --check
17-
- name: Notify fmt check
18-
if: failure() && steps.cargoFmt.outcome == 'failure'
19-
uses: actions/github-script@v6
20-
with:
21-
script: |
22-
const message = `👋 It looks like your code is not formatted like we expect.
23-
24-
Please run \`cargo fmt\` and push the code again.`;
25-
26-
await github.rest.issues.createComment({
27-
issue_number: context.issue.number,
28-
owner: context.repo.owner,
29-
repo: context.repo.repo,
30-
body: message,
31-
});
32-
core.setFailed('It looks like there are formatting errors');
33-
18+
run: cargo +nightly fmt --all -- --check
19+
clippy:
20+
name: Cargo clippy
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: dtolnay/rust-toolchain@stable
25+
- uses: Swatinem/rust-cache@v2
3426
- name: Run clippy check
3527
id: cargoClippy
3628
shell: bash
3729
run: cargo clippy --workspace --all-features -- -D warnings
38-
- name: Notify fmt check
39-
if: failure() && steps.cargoClippy.outcome == 'failure'
40-
uses: actions/github-script@v6
41-
with:
42-
script: |
43-
const message = `👋 It looks like your code has some linting issues.
44-
45-
Please run \`cargo clippy --fix\` and push the code again.`;
46-
47-
await github.rest.issues.createComment({
48-
issue_number: context.issue.number,
49-
owner: context.repo.owner,
50-
repo: context.repo.repo,
51-
body: message,
52-
});
53-
core.setFailed('It looks like there are linting errors');
5430

5531

.rustfmt.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
edition = "2021"
2-
# imports_granularity is unstable
3-
# # https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#merge_imports
4-
# imports_granularity = "Crate"
2+
53
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#max_width
64
max_width = 120
5+
6+
#https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#reorder_imports
7+
reorder_imports = true
8+
9+
#https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#unstable_features
10+
unstable_features = true
11+
12+
# imports_granularity is unstable
13+
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#merge_imports
14+
imports_granularity = "Crate"

lambda-events/src/custom_serde/codebuild_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use chrono::{DateTime, NaiveDateTime, Utc};
2-
use serde::ser::Serializer;
32
use serde::{
43
de::{Deserializer, Error as DeError, Visitor},
4+
ser::Serializer,
55
Deserialize,
66
};
77
use std::fmt;

lambda-events/src/custom_serde/float_unix_epoch.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use serde::{de, ser};
22
use std::fmt;
33

4-
use chrono::offset::TimeZone;
5-
use chrono::{DateTime, LocalResult, Utc};
4+
use chrono::{offset::TimeZone, DateTime, LocalResult, Utc};
65

76
enum SerdeError<V: fmt::Display, D: fmt::Display> {
87
NonExistent { timestamp: V },

lambda-events/src/custom_serde/headers.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use http::header::HeaderName;
2-
use http::{HeaderMap, HeaderValue};
3-
use serde::de::{self, Deserializer, Error as DeError, MapAccess, Unexpected, Visitor};
4-
use serde::ser::{Error as SerError, SerializeMap, Serializer};
1+
use http::{header::HeaderName, HeaderMap, HeaderValue};
2+
use serde::{
3+
de::{self, Deserializer, Error as DeError, MapAccess, Unexpected, Visitor},
4+
ser::{Error as SerError, SerializeMap, Serializer},
5+
};
56
use std::{borrow::Cow, fmt};
67

78
/// Serialize a http::HeaderMap into a serde str => Vec<str> map

lambda-events/src/custom_serde/http_method.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use http::Method;
2-
use serde::de::{Deserialize, Deserializer, Error as DeError, Unexpected, Visitor};
3-
use serde::ser::Serializer;
2+
use serde::{
3+
de::{Deserialize, Deserializer, Error as DeError, Unexpected, Visitor},
4+
ser::Serializer,
5+
};
46
use std::fmt;
57

68
pub fn serialize<S: Serializer>(method: &Method, ser: S) -> Result<S::Ok, S::Error> {

lambda-events/src/custom_serde/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use base64::Engine;
2-
use serde::de::{Deserialize, Deserializer, Error as DeError};
3-
use serde::ser::Serializer;
2+
use serde::{
3+
de::{Deserialize, Deserializer, Error as DeError},
4+
ser::Serializer,
5+
};
46
use std::collections::HashMap;
57

68
#[cfg(feature = "codebuild")]

lambda-events/src/encodings/http.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use base64::display::Base64Display;
22
use bytes::Bytes;
33
use http_body::{Body as HttpBody, SizeHint};
4-
use serde::de::{Deserialize, Deserializer, Error as DeError, Visitor};
5-
use serde::ser::{Error as SerError, Serialize, Serializer};
4+
use serde::{
5+
de::{Deserialize, Deserializer, Error as DeError, Visitor},
6+
ser::{Error as SerError, Serialize, Serializer},
7+
};
68
use std::{borrow::Cow, mem::take, ops::Deref, pin::Pin, task::Poll};
79

810
/// Representation of http request and response bodies as supported

lambda-events/src/encodings/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde::{Deserialize, Serialize};
2-
use std::{ops::Deref, ops::DerefMut};
2+
use std::ops::{Deref, DerefMut};
33

44
#[cfg(feature = "chrono")]
55
mod time;

0 commit comments

Comments
 (0)