Skip to content

Commit 2e2c05b

Browse files
authored
Merge pull request #34 from 1Password/ivan/push-kprlmpyqqsum
Fix clippy warnings
2 parents 35a7ae2 + 1d0e6fe commit 2e2c05b

File tree

27 files changed

+105
-115
lines changed

27 files changed

+105
-115
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
toolchain: ${{ matrix.rust }}
9797
components: clippy
9898
- name: Check with clippy
99-
run: cargo clippy --all
99+
run: cargo clippy --all --all-features --all-targets
100100

101101
book_examples:
102102
name: Test book examples

benches/static_schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ impl QueryRoot {
321321
}
322322
}
323323

324+
#[allow(clippy::duplicated_attributes)]
324325
#[derive(Interface)]
325326
#[graphql(
326327
field(name = "id", ty = "&str"),

derive/src/args.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -913,19 +913,14 @@ pub struct Description {
913913
pub internal: bool,
914914
}
915915

916-
#[derive(Debug)]
916+
#[derive(Debug, Default)]
917917
pub enum NewTypeName {
918918
New(String),
919919
Rust,
920+
#[default]
920921
Original,
921922
}
922923

923-
impl Default for NewTypeName {
924-
fn default() -> Self {
925-
Self::Original
926-
}
927-
}
928-
929924
impl FromMeta for NewTypeName {
930925
fn from_word() -> darling::Result<Self> {
931926
Ok(Self::Rust)

derive/src/complex_object.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ pub fn generate(
6060
.iter()
6161
.nth(1)
6262
.map(|x| {
63-
if let FnArg::Typed(pat) = x {
64-
if let Type::Reference(TypeReference { elem, .. }) = &*pat.ty {
65-
if let Type::Path(path) = elem.as_ref() {
66-
return path.path.segments.last().unwrap().ident
67-
!= "Context";
68-
}
69-
}
63+
if let FnArg::Typed(pat) = x
64+
&& let Type::Reference(TypeReference { elem, .. }) = &*pat.ty
65+
&& let Type::Path(path) = elem.as_ref()
66+
{
67+
return path.path.segments.last().unwrap().ident != "Context";
7068
};
7169
true
7270
})

derive/src/directive.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ pub fn generate(
3939
for arg in item_fn.sig.inputs.iter_mut() {
4040
let mut arg_info = None;
4141

42-
if let FnArg::Typed(pat) = arg {
43-
if let Pat::Ident(ident) = &*pat.pat {
44-
arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone()));
45-
remove_graphql_attrs(&mut pat.attrs);
46-
}
42+
if let FnArg::Typed(pat) = arg
43+
&& let Pat::Ident(ident) = &*pat.pat
44+
{
45+
arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone()));
46+
remove_graphql_attrs(&mut pat.attrs);
4747
}
4848

4949
let (arg_ident, arg_ty, arg_attrs) = match arg_info {

derive/src/object.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,11 @@ pub fn generate(
104104
.iter()
105105
.nth(1)
106106
.map(|x| {
107-
if let FnArg::Typed(pat) = x {
108-
if let Type::Reference(TypeReference { elem, .. }) = &*pat.ty {
109-
if let Type::Path(path) = elem.as_ref() {
110-
return path.path.segments.last().unwrap().ident
111-
!= "Context";
112-
}
113-
}
107+
if let FnArg::Typed(pat) = x
108+
&& let Type::Reference(TypeReference { elem, .. }) = &*pat.ty
109+
&& let Type::Path(path) = elem.as_ref()
110+
{
111+
return path.path.segments.last().unwrap().ident != "Context";
114112
};
115113
true
116114
})

derive/src/type_directive.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ pub fn generate(
4444
for arg in item_fn.sig.inputs.iter_mut() {
4545
let mut arg_info = None;
4646

47-
if let FnArg::Typed(pat) = arg {
48-
if let Pat::Ident(ident) = &*pat.pat {
49-
arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone()));
50-
remove_graphql_attrs(&mut pat.attrs);
51-
}
47+
if let FnArg::Typed(pat) = arg
48+
&& let Pat::Ident(ident) = &*pat.pat
49+
{
50+
arg_info = Some((ident.clone(), pat.ty.clone(), pat.attrs.clone()));
51+
remove_graphql_attrs(&mut pat.attrs);
5252
}
5353

5454
let (arg_ident, arg_ty, arg_attrs) = match arg_info {

derive/src/union.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,13 @@ pub fn generate(union_args: &args::Union) -> GeneratorResult<TokenStream> {
325325

326326
// Check if the type is a generic parameter which we should
327327
// convert to a concrete type
328-
if let syn::Type::Path(ty_path) = ty {
329-
if let Some(idx) = type_params.iter().position(|p| {
328+
if let syn::Type::Path(ty_path) = ty
329+
&& let Some(idx) = type_params.iter().position(|p| {
330330
p.ident == ty_path.path.segments[0].ident
331-
}) {
332-
let param = &params[idx];
333-
*ty = syn::parse2::<syn::Type>(quote!(#param))
334-
.unwrap();
335-
}
331+
})
332+
{
333+
let param = &params[idx];
334+
*ty = syn::parse2::<syn::Type>(quote!(#param)).unwrap();
336335
}
337336
}
338337
}

derive/src/utils.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,28 @@ pub fn get_rustdoc(attrs: &[Attribute]) -> GeneratorResult<Option<TokenStream>>
6363
let mut full_docs: Vec<TokenStream> = vec![];
6464
let mut combined_docs_literal = String::new();
6565
for attr in attrs {
66-
if let Meta::NameValue(nv) = &attr.meta {
67-
if nv.path.is_ident("doc") {
68-
match &nv.value {
69-
Expr::Lit(ExprLit {
70-
lit: Lit::Str(doc), ..
71-
}) => {
72-
let doc = doc.value();
73-
let doc_str = doc.trim();
66+
if let Meta::NameValue(nv) = &attr.meta
67+
&& nv.path.is_ident("doc")
68+
{
69+
match &nv.value {
70+
Expr::Lit(ExprLit {
71+
lit: Lit::Str(doc), ..
72+
}) => {
73+
let doc = doc.value();
74+
let doc_str = doc.trim();
75+
combined_docs_literal += "\n";
76+
combined_docs_literal += doc_str;
77+
}
78+
Expr::Macro(include_macro) => {
79+
if !combined_docs_literal.is_empty() {
7480
combined_docs_literal += "\n";
75-
combined_docs_literal += doc_str;
76-
}
77-
Expr::Macro(include_macro) => {
78-
if !combined_docs_literal.is_empty() {
79-
combined_docs_literal += "\n";
80-
let lit = LitStr::new(&combined_docs_literal, Span::call_site());
81-
full_docs.push(quote!( #lit ));
82-
combined_docs_literal.clear();
83-
}
84-
full_docs.push(quote!( #include_macro ));
81+
let lit = LitStr::new(&combined_docs_literal, Span::call_site());
82+
full_docs.push(quote!( #lit ));
83+
combined_docs_literal.clear();
8584
}
86-
_ => (),
85+
full_docs.push(quote!( #include_macro ));
8786
}
87+
_ => (),
8888
}
8989
}
9090
}
@@ -226,10 +226,10 @@ pub fn parse_complexity_expr(expr: Expr) -> GeneratorResult<(HashSet<String>, Ex
226226

227227
impl<'a> Visit<'a> for VisitComplexityExpr {
228228
fn visit_expr_path(&mut self, i: &'a ExprPath) {
229-
if let Some(ident) = i.path.get_ident() {
230-
if ident != "child_complexity" {
231-
self.variables.insert(ident.to_string());
232-
}
229+
if let Some(ident) = i.path.get_ident()
230+
&& ident != "child_complexity"
231+
{
232+
self.variables.insert(ident.to_string());
233233
}
234234
}
235235
}
@@ -355,17 +355,17 @@ pub fn gen_directive_calls(
355355
}
356356

357357
fn extract_directive_call_path(directive: &Expr) -> Option<syn::Path> {
358-
if let Expr::Call(expr) = directive {
359-
if let Expr::Path(ref expr) = *expr.func {
360-
let mut path = expr.path.clone();
361-
if path.segments.pop()?.value().ident != "apply" {
362-
return None;
363-
}
358+
if let Expr::Call(expr) = directive
359+
&& let Expr::Path(ref expr) = *expr.func
360+
{
361+
let mut path = expr.path.clone();
362+
if path.segments.pop()?.value().ident != "apply" {
363+
return None;
364+
}
364365

365-
path.segments.pop_punct()?;
366+
path.segments.pop_punct()?;
366367

367-
return Some(path);
368-
}
368+
return Some(path);
369369
}
370370

371371
None

integrations/axum/src/response.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ impl IntoResponse for GraphQLResponse {
3131
http::header::CONTENT_TYPE,
3232
HeaderValue::from_static("application/graphql-response+json"),
3333
);
34-
if self.0.is_ok() {
35-
if let Some(cache_control) = self.0.cache_control().value() {
36-
if let Ok(value) = HeaderValue::from_str(&cache_control) {
37-
resp.headers_mut()
38-
.insert(http::header::CACHE_CONTROL, value);
39-
}
40-
}
34+
if self.0.is_ok()
35+
&& let Some(cache_control) = self.0.cache_control().value()
36+
&& let Ok(value) = HeaderValue::from_str(&cache_control)
37+
{
38+
resp.headers_mut()
39+
.insert(http::header::CACHE_CONTROL, value);
4140
}
4241

4342
resp.headers_mut().extend(self.0.http_headers());

0 commit comments

Comments
 (0)