Skip to content

Commit 5985f5b

Browse files
authored
Merge pull request #40 from tomhoule/clippy
Fix most clippy warnings
2 parents e29f381 + 4d638f7 commit 5985f5b

File tree

10 files changed

+38
-31
lines changed

10 files changed

+38
-31
lines changed

graphql_client_cli/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

graphql_query_derive/src/constants.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ use field_type::FieldType;
22
use objects::GqlObjectField;
33
use proc_macro2::{Ident, Span};
44

5-
pub const TYPENAME_FIELD: &'static str = "__typename";
5+
pub const TYPENAME_FIELD: &str = "__typename";
66

77
pub fn string_type() -> Ident {
88
Ident::new("String", Span::call_site())
99
}
1010

11+
#[cfg(test)]
1112
pub fn float_type() -> Ident {
1213
Ident::new("Float", Span::call_site())
1314
}

graphql_query_derive/src/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use proc_macro2::{Ident, Span, TokenStream};
22

3-
pub const ENUMS_PREFIX: &'static str = "";
3+
pub const ENUMS_PREFIX: &str = "";
44

55
#[derive(Debug, PartialEq)]
66
pub struct GqlEnum {

graphql_query_derive/src/field_type.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ impl FieldType {
2727
let name = if context.schema.scalars.contains(&name_string)
2828
|| DEFAULT_SCALARS
2929
.iter()
30-
.find(|elem| elem == &&name_string)
31-
.is_some()
30+
.any(|elem| elem == &name_string.as_str())
3231
{
3332
name.clone()
3433
} else if context.schema.enums.contains_key(&name_string) {

graphql_query_derive/src/interfaces.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl GqlInterface {
7474
);
7575

7676
let attached_enum_name = Ident::new(&format!("{}On", name), Span::call_site());
77-
let (attached_enum, last_object_field) = if union_variants.len() > 0 {
77+
let (attached_enum, last_object_field) = if !union_variants.is_empty() {
7878
let attached_enum = quote! {
7979
#[derive(Deserialize, Debug, Serialize)]
8080
#[serde(tag = "__typename")]

graphql_query_derive/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,15 @@ fn extract_attr(ast: &syn::DeriveInput, attr: &str) -> Result<String, failure::E
140140
let path = &attr.path;
141141
quote!(#path).to_string() == "GraphQLQuery"
142142
})
143-
.ok_or(format_err!("The GraphQLQuery attribute is missing"))?;
143+
.ok_or_else(|| format_err!("The GraphQLQuery attribute is missing"))?;
144144
if let syn::Meta::List(items) = &attribute
145145
.interpret_meta()
146146
.expect("Attribute is well formatted")
147147
{
148148
for item in items.nested.iter() {
149149
if let syn::NestedMeta::Meta(syn::Meta::NameValue(name_value)) = item {
150-
let syn::MetaNameValue {
151-
ident,
152-
eq_token: _,
153-
lit,
154-
} = name_value;
155-
if ident == &attr {
150+
let syn::MetaNameValue { ident, lit, .. } = name_value;
151+
if ident == attr {
156152
if let syn::Lit::Str(lit) = lit {
157153
return Ok(lit.value());
158154
}

graphql_query_derive/src/schema.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use selection::Selection;
1212
use std::collections::{BTreeMap, BTreeSet};
1313
use unions::GqlUnion;
1414

15-
pub const DEFAULT_SCALARS: &[&'static str] = &["ID", "String", "Int", "Float", "Boolean"];
15+
pub const DEFAULT_SCALARS: &[&str] = &["ID", "String", "Int", "Float", "Boolean"];
1616

1717
#[derive(Debug, PartialEq)]
1818
pub struct Schema {
@@ -147,8 +147,8 @@ impl Schema {
147147
let response_data_fields = context
148148
.query_root
149149
.as_ref()
150-
.or(context.mutation_root.as_ref())
151-
.or(context._subscription_root.as_ref())
150+
.or_else(|| context.mutation_root.as_ref())
151+
.or_else(|| context._subscription_root.as_ref())
152152
.expect("no selection defined");
153153

154154
// TODO: do something smarter here
@@ -192,14 +192,21 @@ impl Schema {
192192
})
193193
}
194194

195-
pub fn ingest_interface_implementations(&mut self, impls: BTreeMap<String, Vec<String>>) {
196-
impls.into_iter().for_each(|(iface_name, implementors)| {
197-
let iface = self
198-
.interfaces
199-
.get_mut(&iface_name)
200-
.expect(&format!("interface not found: {}", iface_name));
201-
iface.implemented_by = implementors.into_iter().collect();
202-
});
195+
pub fn ingest_interface_implementations(
196+
&mut self,
197+
impls: BTreeMap<String, Vec<String>>,
198+
) -> Result<(), failure::Error> {
199+
impls
200+
.into_iter()
201+
.map(|(iface_name, implementors)| {
202+
let iface = self
203+
.interfaces
204+
.get_mut(&iface_name)
205+
.ok_or_else(|| format_err!("interface not found: {}", iface_name))?;
206+
iface.implemented_by = implementors.into_iter().collect();
207+
Ok(())
208+
})
209+
.collect()
203210
}
204211
}
205212

@@ -215,7 +222,7 @@ impl ::std::convert::From<graphql_parser::schema::Document> for Schema {
215222
match definition {
216223
schema::Definition::TypeDefinition(ty_definition) => match ty_definition {
217224
schema::TypeDefinition::Object(obj) => {
218-
for implementing in obj.implements_interfaces.iter() {
225+
for implementing in &obj.implements_interfaces {
219226
let name = &obj.name;
220227
interface_implementations
221228
.entry(implementing.to_string())
@@ -269,7 +276,9 @@ impl ::std::convert::From<graphql_parser::schema::Document> for Schema {
269276
}
270277
}
271278

272-
schema.ingest_interface_implementations(interface_implementations);
279+
schema
280+
.ingest_interface_implementations(interface_implementations)
281+
.expect("schema ingestion");
273282

274283
schema
275284
}
@@ -372,7 +381,9 @@ impl ::std::convert::From<::introspection_response::IntrospectionResponse> for S
372381
}
373382
}
374383

375-
schema.ingest_interface_implementations(interface_implementations);
384+
schema
385+
.ingest_interface_implementations(interface_implementations)
386+
.expect("schema ingestion");
376387

377388
schema
378389
}

graphql_query_derive/src/selection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a> ::std::convert::From<&'a SelectionSet> for Selection {
5151

5252
let mut items = Vec::new();
5353

54-
for item in selection_set.items.iter() {
54+
for item in &selection_set.items {
5555
let converted = match item {
5656
Selection::Field(f) => SelectionItem::Field(SelectionField {
5757
name: f.name.to_string(),

graphql_query_derive/src/shared.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use proc_macro2::{Ident, Span, TokenStream};
55
use query::QueryContext;
66
use selection::*;
77

8-
pub(crate) fn render_object_field(field_name: &str, field_type: TokenStream) -> TokenStream {
8+
pub(crate) fn render_object_field(field_name: &str, field_type: &TokenStream) -> TokenStream {
99
if field_name == "type" {
1010
let name_ident = Ident::new(&format!("{}_", field_name), Span::call_site());
1111
return quote! {
@@ -65,13 +65,13 @@ pub fn response_fields_for_selection(
6565
let ty = &schema_fields
6666
.iter()
6767
.find(|field| field.name.as_str() == name.as_str())
68-
.ok_or(format_err!("Could not find field: {}", name.as_str()))?
68+
.ok_or_else(|| format_err!("Could not find field: {}", name.as_str()))?
6969
.type_;
7070
let ty = ty.to_rust(
7171
context,
7272
&format!("{}{}", prefix.to_camel_case(), name.to_camel_case()),
7373
);
74-
Ok(render_object_field(name, ty))
74+
Ok(render_object_field(name, &ty))
7575
}
7676
SelectionItem::FragmentSpread(fragment) => {
7777
let field_name =

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
extern crate serde;
22
#[macro_use]
33
extern crate serde_derive;
4-
#[allow(unused_imports)]
54
#[macro_use]
65
extern crate graphql_query_derive;
76

0 commit comments

Comments
 (0)