Skip to content

Commit 60181dd

Browse files
committed
Cargo fix part 2 + cargo clippy for wundergraph_derive
1 parent 41e40a8 commit 60181dd

File tree

7 files changed

+61
-66
lines changed

7 files changed

+61
-66
lines changed

wundergraph_derive/src/diagnostic_shim.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl Diagnostic {
7474
self.help(msg)
7575
}
7676

77+
#[allow(clippy::print_stdout)]
7778
pub fn emit(self) {
7879
match self.level {
7980
Level::Error => panic!("{}", self.message),

wundergraph_derive/src/lib.rs

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,38 @@
11
#![recursion_limit = "1024"]
22
#![deny(missing_debug_implementations, missing_copy_implementations)]
3-
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
4-
#![cfg_attr(feature = "cargo-clippy", warn(clippy))]
5-
// Clippy lints
6-
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
7-
#![cfg_attr(
8-
feature = "cargo-clippy",
9-
warn(
10-
wrong_pub_self_convention,
11-
used_underscore_binding,
12-
use_self,
13-
unseparated_literal_suffix,
14-
unnecessary_unwrap,
15-
unimplemented,
16-
single_match_else,
17-
shadow_unrelated,
18-
option_map_unwrap_or_else,
19-
option_map_unwrap_or,
20-
needless_continue,
21-
mutex_integer,
22-
needless_borrow,
23-
items_after_statements,
24-
filter_map,
25-
expl_impl_clone_on_copy,
26-
else_if_without_else,
27-
doc_markdown,
28-
default_trait_access,
29-
option_unwrap_used,
30-
result_unwrap_used,
31-
wrong_pub_self_convention,
32-
mut_mut,
33-
non_ascii_literal,
34-
unicode_not_nfc,
35-
enum_glob_use,
36-
if_not_else,
37-
items_after_statements,
38-
used_underscore_binding
39-
)
3+
#![warn(
4+
clippy::option_unwrap_used,
5+
clippy::result_unwrap_used,
6+
clippy::print_stdout,
7+
clippy::wrong_pub_self_convention,
8+
clippy::mut_mut,
9+
clippy::non_ascii_literal,
10+
clippy::similar_names,
11+
clippy::unicode_not_nfc,
12+
clippy::enum_glob_use,
13+
clippy::if_not_else,
14+
clippy::items_after_statements,
15+
clippy::used_underscore_binding,
16+
clippy::cargo_common_metadata,
17+
clippy::dbg_macro,
18+
clippy::doc_markdown,
19+
clippy::filter_map,
20+
clippy::map_flatten,
21+
clippy::match_same_arms,
22+
clippy::needless_borrow,
23+
clippy::needless_pass_by_value,
24+
clippy::option_map_unwrap_or,
25+
clippy::option_map_unwrap_or_else,
26+
clippy::redundant_clone,
27+
clippy::result_map_unwrap_or_else,
28+
clippy::unnecessary_unwrap,
29+
clippy::unseparated_literal_suffix,
30+
clippy::wildcard_dependencies
31+
4032
)]
4133

4234
extern crate proc_macro;
43-
extern crate proc_macro2;
35+
use proc_macro2;
4436
#[macro_use]
4537
extern crate quote;
4638
#[macro_use]

wundergraph_derive/src/meta.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl MetaItem {
3939
attrs
4040
.iter()
4141
.filter_map(|a| {
42-
let meta = a.parse_meta().unwrap();
42+
let meta = a.parse_meta().expect("Failed to parse meta");
4343
if meta.name() == "doc" {
4444
if let syn::Meta::NameValue(value) = meta {
4545
let s = match value.lit {
@@ -91,7 +91,6 @@ impl MetaItem {
9191
})
9292
}
9393

94-
9594
pub fn expect_ident_value(&self) -> syn::Ident {
9695
self.ident_value().unwrap_or_else(|e| {
9796
e.emit();
@@ -110,7 +109,7 @@ impl MetaItem {
110109
self.name(),
111110
))
112111
.emit();
113-
Ok(x.clone())
112+
Ok(x)
114113
}
115114
_ => Ok(syn::Ident::new(
116115
&self.str_value()?,
@@ -132,7 +131,7 @@ impl MetaItem {
132131
}
133132
}
134133

135-
pub fn nested(&self) -> Result<Nested, Diagnostic> {
134+
pub fn nested(&self) -> Result<Nested<'_>, Diagnostic> {
136135
use syn::Meta::*;
137136

138137
match self.meta {
@@ -218,7 +217,6 @@ impl MetaItem {
218217
}
219218
}
220219

221-
#[cfg_attr(rustfmt, rustfmt_skip)] // https://github.com/rust-lang-nursery/rustfmt/issues/2392
222220
pub struct Nested<'a>(syn::punctuated::Iter<'a, syn::NestedMeta>);
223221

224222
impl<'a> Iterator for Nested<'a> {

wundergraph_derive/src/model.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ impl Model {
2222
let flags = MetaItem::with_name(&item.attrs, "wundergraph")
2323
.unwrap_or_else(|| MetaItem::empty("wundergraph"));
2424
let docs = MetaItem::get_docs(&item.attrs);
25-
let primary_keys = MetaItem::with_name(&item.attrs, "primary_key")
26-
.map(|m| m.nested()?.map(|m| m.word()).collect())
27-
.unwrap_or_else(|| Ok(vec![syn::Ident::new("id", Span::call_site())]))?;
25+
let primary_keys = MetaItem::with_name(&item.attrs, "primary_key").map_or_else(
26+
|| Ok(vec![syn::Ident::new("id", Span::call_site())]),
27+
|m| m.nested()?.map(|m| m.word()).collect(),
28+
)?;
2829
Ok(Self {
2930
name: item.ident.clone(),
3031
fields,

wundergraph_derive/src/wundergraph_entity.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::diagnostic_shim::{Diagnostic, DiagnosticShim};
2+
use crate::field::Field;
23
use crate::model::Model;
4+
use crate::utils::{inner_of_option_ty, inner_ty_args, is_has_many, wrap_in_dummy_mod};
35
use proc_macro2::{Span, TokenStream};
46
use syn;
5-
use crate::utils::{inner_of_option_ty, inner_ty_args, is_has_many, wrap_in_dummy_mod};
67

78
pub fn derive(item: &syn::DeriveInput) -> Result<TokenStream, Diagnostic> {
89
let model = Model::from_item(item)?;
@@ -124,7 +125,7 @@ fn derive_loading_handler(
124125
let struct_type = &model.name;
125126
let (_, ty_generics, _) = item.generics.split_for_impl();
126127
let table = model.table_type()?;
127-
let field_names = model.fields().iter().map(|f| f.graphql_name());
128+
let field_names = model.fields().iter().map(Field::graphql_name);
128129
let field_list = model.fields().iter().map(|f| &f.ty);
129130
let columns = model.fields().iter().filter_map(|f| {
130131
if is_has_many(&f.ty) {
@@ -178,17 +179,19 @@ fn derive_loading_handler(
178179
}
179180
});
180181

181-
let type_description = model
182-
.docs
183-
.as_ref()
184-
.map(|d| quote!(std::option::Option::Some(#d)))
185-
.unwrap_or_else(|| quote!(std::option::Option::None));
182+
let type_description = model.docs.as_ref().map_or_else(
183+
|| quote!(std::option::Option::None),
184+
|d| quote!(std::option::Option::Some(#d)),
185+
);
186186

187-
let filter = model.filter_type().map(|p| quote!(#p)).unwrap_or_else(|| {
188-
quote! {
189-
wundergraph::filter::filter_helper::FilterWrapper<Self, #backend, __Ctx>
190-
}
191-
});
187+
let filter = model.filter_type().map_or_else(
188+
|| {
189+
quote! {
190+
wundergraph::filter::filter_helper::FilterWrapper<Self, #backend, __Ctx>
191+
}
192+
},
193+
|p| quote!(#p),
194+
);
192195

193196
let mut generics = item.generics.clone();
194197
generics

wundergraph_derive/src/wundergraph_filter.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::diagnostic_shim::{Diagnostic, };
1+
use crate::diagnostic_shim::Diagnostic;
22
use crate::field::Field;
33
use crate::model::Model;
4-
use proc_macro2::{TokenStream};
5-
use syn;
64
use crate::utils::{inner_of_box_ty, inner_of_option_ty, is_box_ty, wrap_in_dummy_mod};
5+
use proc_macro2::TokenStream;
6+
use syn;
77

88
pub fn derive(item: &syn::DeriveInput) -> Result<TokenStream, Diagnostic> {
99
let inner_filter = inner_filter(item)?;
@@ -139,7 +139,7 @@ fn build_from_inner_input_value(model: &Model) -> Result<TokenStream, Diagnostic
139139
};
140140
)
141141
});
142-
let fields = model.fields().iter().map(|f| f.rust_name());
142+
let fields = model.fields().iter().map(Field::rust_name);
143143
Ok(quote! {
144144
#(#build_field)*
145145

@@ -165,7 +165,7 @@ fn build_from_look_ahead(model: &Model) -> Result<TokenStream, Diagnostic> {
165165
#map_box;
166166
}
167167
});
168-
let fields = model.fields().iter().map(|f| f.rust_name());
168+
let fields = model.fields().iter().map(Field::rust_name);
169169
Ok(quote! {
170170
#(#build_field)*
171171

@@ -198,7 +198,7 @@ fn build_register_fields(model: &Model) -> Result<TokenStream, Diagnostic> {
198198
);
199199
}
200200
});
201-
let fields = model.fields().iter().map(|f| f.graphql_name());
201+
let fields = model.fields().iter().map(Field::graphql_name);
202202
Ok(quote! {
203203
#(#register_field)*
204204
vec![#(#fields,)*]

wundergraph_derive/src/wundergraph_value.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::diagnostic_shim::*;
22
use crate::meta::MetaItem;
3+
use crate::utils::wrap_in_dummy_mod;
34
use proc_macro2::{Span, TokenStream};
45
use syn;
56
use syn::spanned::Spanned;
6-
use crate::utils::wrap_in_dummy_mod;
77

88
pub fn derive(item: &syn::DeriveInput) -> Result<TokenStream, Diagnostic> {
99
let filter_value = filter_value(item);
@@ -59,7 +59,7 @@ fn wundergraph_value(item: &syn::DeriveInput) -> Result<TokenStream, Diagnostic>
5959
.map(|m| m.expect_ident_value())
6060
.ok_or_else(|| {
6161
item.span()
62-
.error(format!("Missing required option `sql_type`",))
62+
.error("Missing required option `sql_type`".to_string())
6363
})?;
6464
let item_name = &item.ident;
6565
let (impl_generics, ty_generics, where_clause) = item.generics.split_for_impl();

0 commit comments

Comments
 (0)