Skip to content

Commit 4d3e9ea

Browse files
authored
Clippy lints (#330)
* Clippy lints * Updating lint workflows * More lint updates
1 parent e58214a commit 4d3e9ea

File tree

33 files changed

+181
-184
lines changed

33 files changed

+181
-184
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ permissions:
44

55
on:
66
push:
7-
pull_request:
87

98
jobs:
109
build:

.github/workflows/fmt.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/license-check.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ permissions:
44

55
on:
66
push:
7-
pull_request:
87

98
jobs:
109
license:

.github/workflows/lint.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Fmt
2+
permissions:
3+
contents: read
4+
5+
on:
6+
push:
7+
8+
jobs:
9+
format:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
14+
- name: cargo fmt --all -- --check
15+
run: cargo fmt --all -- --check
16+
clippy:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
21+
- name: cargo clippy -- -Dwarnings
22+
run: cargo clippy -- -Dwarnings

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ permissions:
44

55
on:
66
push:
7-
pull_request:
87

98
jobs:
109
test:

dropshot-authorization-header/src/basic.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ impl SharedExtractor for BasicAuth {
5050
header
5151
.to_str()
5252
.map(|s| s.to_string())
53-
.map_err(|err| {
54-
tracing::info!("Failed to turn Authorization header into string");
55-
err
53+
.inspect_err(|err| {
54+
tracing::info!(?err, "Failed to turn Authorization header into string");
5655
})
5756
.ok()
5857
});
@@ -64,18 +63,17 @@ impl SharedExtractor for BasicAuth {
6463
match parts {
6564
Some(("Basic", token)) => BASE64_STANDARD
6665
.decode(token)
67-
.map_err(|err| {
68-
tracing::info!("Failed to decode basic auth header");
69-
err
66+
.inspect_err(|err| {
67+
tracing::info!(?err, "Failed to decode basic auth header");
7068
})
7169
.ok()
7270
.and_then(|decoded| {
7371
String::from_utf8(decoded)
74-
.map_err(|err| {
72+
.inspect_err(|err| {
7573
tracing::info!(
74+
?err,
7675
"Failed to interpret decoded bytes from authorization header"
7776
);
78-
err
7977
})
8078
.ok()
8179
})

dropshot-authorization-header/src/bearer.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl BearerAuth {
1717
}
1818

1919
pub fn key(&self) -> Option<&str> {
20-
self.0.as_ref().map(|s| s.as_str())
20+
self.0.as_deref()
2121
}
2222

2323
pub fn consume(self) -> Option<String> {
@@ -43,9 +43,8 @@ impl SharedExtractor for BearerAuth {
4343
header
4444
.to_str()
4545
.map(|s| s.to_string())
46-
.map_err(|err| {
47-
tracing::info!("Failed to turn Authorization header into string");
48-
err
46+
.inspect_err(|err| {
47+
tracing::info!(?err, "Failed to turn Authorization header into string");
4948
})
5049
.ok()
5150
});

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "stable"
3+
components = ["clippy", "rustfmt"]

v-api-installer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn migrations() -> Vec<Box<dyn Migration<Pg>>> {
1717
}
1818

1919
pub fn run_migrations(url: &str) {
20-
let mut conn = db_conn(&url);
20+
let mut conn = db_conn(url);
2121
run_migrations_on_conn(&mut conn);
2222
}
2323

v-api-permission-derive/src/lib.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ impl Parse for ContractSettings {
168168

169169
let kind = settings
170170
.iter()
171+
.find(|&s| s.name == "kind")
171172
.cloned()
172-
.find(|s| s.name == "kind")
173173
.ok_or_else(|| Error::new(span, "Expand must contain a \"kind\" setting"))?;
174174

175175
Ok(ContractSettings {
@@ -201,8 +201,8 @@ impl Parse for ExpandSettings {
201201

202202
let kind = settings
203203
.iter()
204+
.find(|&s| s.name == "kind")
204205
.cloned()
205-
.find(|s| s.name == "kind")
206206
.ok_or_else(|| Error::new(span, "Expand must contain a \"kind\" setting"))?;
207207

208208
Ok(ExpandSettings {
@@ -214,8 +214,8 @@ impl Parse for ExpandSettings {
214214
},
215215
variant: settings
216216
.iter()
217+
.find(|&s| s.name == "variant")
217218
.cloned()
218-
.find(|s| s.name == "variant")
219219
.expect("Expand must contain a \"variant\" setting")
220220
.value,
221221
source: settings.iter().find(|s| s.name == "source").map(|s| {
@@ -253,13 +253,13 @@ impl Parse for ScopeSettings {
253253
Ok(ScopeSettings {
254254
from: settings
255255
.iter()
256+
.find(|&v| v.name == "from")
256257
.cloned()
257-
.find(|v| v.name == "from")
258258
.map(|v| v.value),
259259
to: settings
260260
.iter()
261+
.find(|&v| v.name == "to")
261262
.cloned()
262-
.find(|v| v.name == "to")
263263
.map(|v| v.value),
264264
})
265265
}
@@ -313,12 +313,10 @@ pub fn v_api(attr: TokenStream, input: TokenStream) -> TokenStream {
313313
#as_scope_out
314314
#permission_storage_out
315315
}
316-
.into()
317316
}
318317
_ => quote_spanned! {
319318
input_span => compile_error!("v_api may only be applied to enums");
320-
}
321-
.into(),
319+
},
322320
};
323321

324322
let from = from_system_permission_tokens(&attr.source, &input.ident);
@@ -734,7 +732,7 @@ fn as_scope_trait_tokens(
734732
) -> proc_macro2::TokenStream {
735733
let as_scope_mapping = scope_settings.iter().filter_map(|(variant, settings)| {
736734
settings.to.as_ref().map(|to| {
737-
let fields = if variant.fields.len() > 0 {
735+
let fields = if !variant.fields.is_empty() {
738736
let mut fields = quote! {};
739737
variant
740738
.fields
@@ -802,7 +800,6 @@ fn as_scope_trait_tokens(
802800
}
803801
}
804802
}
805-
.into()
806803
}
807804

808805
fn permission_storage_trait_tokens(
@@ -844,7 +841,7 @@ fn permission_storage_contract_tokens(
844841
.then(|| set_name.clone()),
845842
);
846843

847-
let fields = if variant.fields.len() > 0 && setting.kind != ContractKind::Drop {
844+
let fields = if !variant.fields.is_empty() && setting.kind != ContractKind::Drop {
848845
let mut fields = quote! {};
849846
variant
850847
.fields

0 commit comments

Comments
 (0)