Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bikeshedder committed Jan 9, 2024
1 parent fc0ca9d commit 414b483
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 56 deletions.
14 changes: 6 additions & 8 deletions src/codegen/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn gen_enum(enum_: &schema::Enum, ns: &[String]) -> TokenStream {
}
});
if let Some(extends) = &enum_.extends {
let extends_typeref = gen_typeref_ref(&extends, ns);
let extends_typeref = gen_typeref_ref(extends, ns);
let mut matches = TokenStream::new();
let extends_enum = enum_.extends_enum().unwrap();
for variant in extends_enum.borrow().all_variants.iter() {
Expand Down Expand Up @@ -152,7 +152,7 @@ fn gen_validation_macros(field: &schema::Field) -> TokenStream {
match field.format.as_deref() {
Some("email") => rules.extend(quote! { email, }),
Some("url") => rules.extend(quote! { url, }),
_ => {},
_ => {}
}
match field.length {
(Some(min), Some(max)) => rules.extend(quote! { length(min=#min, max=#max), }),
Expand Down Expand Up @@ -201,7 +201,7 @@ fn gen_fieldset_field(field: &schema::FieldsetField, ns: &[String]) -> TokenStre

fn gen_service(service: &schema::Service, ns: &[String]) -> TokenStream {
let service_name = quote::format_ident!("{}", &service.name);
let methods = gen_service_methods(&service, ns);
let methods = gen_service_methods(service, ns);
quote! {
#[::async_trait::async_trait]
pub trait #service_name {
Expand Down Expand Up @@ -248,7 +248,7 @@ fn gen_provider(service: &schema::Service, ns: &[String]) -> TokenStream {
format!("{}.{}", ns.join("."), &service.name)
};
let provider_name = quote::format_ident!("{}Provider", service.name);
let matches = gen_provider_matches(&service, ns);
let matches = gen_provider_matches(service, ns);
quote! {
pub struct #provider_name<F>(pub F);
// NamedProvider impl
Expand Down Expand Up @@ -332,7 +332,7 @@ fn gen_provider_matches(service: &schema::Service, ns: &[String]) -> TokenStream

fn gen_consumer(service: &schema::Service, ns: &[String]) -> TokenStream {
let consumer_name = quote::format_ident!("{}Consumer", service.name);
let consumer_methods = gen_consumer_methods(&service, ns);
let consumer_methods = gen_consumer_methods(service, ns);
quote! {
pub struct #consumer_name<'a>(pub &'a (dyn ::webwire::Consumer + ::std::marker::Sync + ::std::marker::Send));
impl<'a> #consumer_name<'a> {
Expand Down Expand Up @@ -427,9 +427,7 @@ fn gen_typeref(type_: &schema::Type, ns: &[String]) -> TokenStream {
}
}
// named
schema::Type::Ref(typeref) => {
gen_typeref_ref(typeref, ns)
}
schema::Type::Ref(typeref) => gen_typeref_ref(typeref, ns),
schema::Type::Builtin(name) => {
// FIXME unwrap... igh!
let identifier: TokenStream = ::syn::parse_str(name).unwrap();
Expand Down
16 changes: 8 additions & 8 deletions src/codegen/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn gen(doc: &schema::Document) -> String {
fn gen_namespace(ns: &schema::Namespace, gen: &mut Generator) {
for type_ in ns.types.values() {
gen.line("");
gen_type(&*type_, gen);
gen_type(type_, gen);
}
for service in ns.services.values() {
gen.line("");
Expand All @@ -72,9 +72,9 @@ fn gen_namespace(ns: &schema::Namespace, gen: &mut Generator) {

fn gen_type(type_: &schema::UserDefinedType, gen: &mut Generator) {
match type_ {
schema::UserDefinedType::Enum(enum_) => gen_enum(&*enum_.borrow(), gen),
schema::UserDefinedType::Struct(struct_) => gen_struct(&*struct_.borrow(), gen),
schema::UserDefinedType::Fieldset(fieldset) => gen_fieldset(&*fieldset.borrow(), gen),
schema::UserDefinedType::Enum(enum_) => gen_enum(&enum_.borrow(), gen),
schema::UserDefinedType::Struct(struct_) => gen_struct(&struct_.borrow(), gen),
schema::UserDefinedType::Fieldset(fieldset) => gen_fieldset(&fieldset.borrow(), gen),
}
}

Expand Down Expand Up @@ -160,20 +160,20 @@ fn gen_fieldset(fieldset: &schema::Fieldset, gen: &mut Generator) {

fn method_signature(method: &schema::Method) -> String {
let input = match &method.input {
Some(t) => format!("input: {}", gen_typeref(&t)),
Some(t) => format!("input: {}", gen_typeref(t)),
None => String::new(),
};
let output = match &method.output {
Some(t) => gen_typeref(t),
None => "void".to_string(),
};
format!("{}({}): Promise<{}>", method.name, input, output)
format!("{}({}): webwire.Response<{}>", method.name, input, output)
}

fn gen_service(service: &schema::Service, gen: &mut Generator) {
gen.begin(&format!("export interface {} {{", service.name));
for method in service.methods.iter() {
gen.line(&format!("{},", method_signature(&method)));
gen.line(&format!("{},", method_signature(method)));
}
gen.end("}");
}
Expand All @@ -188,7 +188,7 @@ fn gen_consumer(ns: &schema::Namespace, service: &schema::Service, gen: &mut Gen
gen.line("this._client = client");
gen.end("}");
for method in service.methods.iter() {
gen.begin(&format!("async {} {{", method_signature(&method)));
gen.begin(&format!("async {} {{", method_signature(method)));
let fqsn = if ns.path.is_empty() {
service.name.to_owned()
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/idl/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pub fn parse_identifier_with_generics(input: Span) -> IResult<Span, (String, Vec
}

#[cfg(test)]
pub(crate) fn assert_parse<'a, T: std::fmt::Debug + PartialEq>(
output: IResult<LocatedSpan<&'a str>, T>,
pub(crate) fn assert_parse<T: std::fmt::Debug + PartialEq>(
output: IResult<LocatedSpan<&str>, T>,
expected_value: T,
) {
assert!(output.is_ok(), "{:?}", output);
Expand Down
2 changes: 1 addition & 1 deletion src/idl/fieldset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn parse_field(input: Span) -> IResult<Span, Field> {
pair(preceded(ws, parse_identifier), preceded(ws, opt(char('?')))),
|(name, optional)| Field {
name,
optional: optional != None,
optional: optional.is_some(),
},
)(input)
}
Expand Down
6 changes: 3 additions & 3 deletions src/idl/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn parse_field(input: Span) -> IResult<Span, Field> {
|((name, optional), (type_, options))| Field {
name,
position: input.into(),
optional: optional != None,
optional: optional.is_some(),
type_,
options: if let Some(options) = options {
options
Expand Down Expand Up @@ -431,7 +431,7 @@ fn test_parse_struct_with_fields() {

#[test]
fn test_parse_struct_with_fields_ws_variants() {
let contents = vec![
let contents = [
"struct Person{name:String,age:Integer}",
"struct Person {name:String,age:Integer}",
"struct Person{ name:String,age:Integer}",
Expand Down Expand Up @@ -481,7 +481,7 @@ fn test_parse_struct_with_generics() {

#[test]
fn test_parse_struct_with_generics_ws_variants() {
let contents = vec![
let contents = [
"struct Wrapper<T>{value:T}",
"struct Wrapper <T>{value:T}",
"struct Wrapper< T>{value:T}",
Expand Down
13 changes: 5 additions & 8 deletions src/schema/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ impl Enum {
value_type: ivariant
.value_type
.as_ref()
.map(|itype| Type::from_idl(itype, &ns, &builtin_types)),
.map(|itype| Type::from_idl(itype, ns, builtin_types)),
})
.collect();
let extends = ienum
.extends
.as_ref()
.map(|itype| TypeRef::from_idl(itype, &ns, &builtin_types));
.map(|itype| TypeRef::from_idl(itype, ns, builtin_types));
Self {
fqtn: FQTN::new(&ienum.name, ns),
generics: ienum.generics.clone(),
Expand Down Expand Up @@ -91,19 +91,16 @@ impl Enum {
Ok(variants)
}
pub fn extends_enum(&self) -> Option<Rc<RefCell<Enum>>> {
if let Some(extends) = &self.extends {
if let TypeRef::Enum(extends) = extends {
Some(extends.enum_.upgrade().unwrap())
} else {
None
}
if let Some(TypeRef::Enum(extends)) = &self.extends {
Some(extends.enum_.upgrade().unwrap())
} else {
None
}
}
}

#[test]
#[allow(clippy::disallowed_names)]
fn test_schema_enum_extends() {
let idl = r"
enum Foo { Foo }
Expand Down
2 changes: 1 addition & 1 deletion src/schema/fieldset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Fieldset {
Self {
fqtn: FQTN::new(&ifieldset.name, ns),
generics: ifieldset.generics.clone(),
r#struct: TypeRef::from_idl(&ifieldset.r#struct, ns, &builtin_types),
r#struct: TypeRef::from_idl(&ifieldset.r#struct, ns, builtin_types),
fields: ifieldset
.fields
.iter()
Expand Down
18 changes: 9 additions & 9 deletions src/schema/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Namespace {
let mut ns = Self::default();
let mut type_map = TypeMap::new();
for ins in inss {
ns.idl_convert(ins, &mut type_map, &builtin_types)?;
ns.idl_convert(ins, &mut type_map, builtin_types)?;
}
ns.resolve(&type_map)?;
Ok(ns)
Expand Down Expand Up @@ -62,37 +62,37 @@ impl Namespace {
idl::NamespacePart::Enum(ienum) => {
self.add_type(
UserDefinedType::Enum(Rc::new(RefCell::new(Enum::from_idl(
&ienum,
ienum,
self,
&builtin_types,
builtin_types,
)))),
type_map,
);
}
idl::NamespacePart::Struct(istruct) => {
self.add_type(
UserDefinedType::Struct(Rc::new(RefCell::new(Struct::from_idl(
&istruct,
istruct,
self,
&builtin_types,
builtin_types,
)))),
type_map,
);
}
idl::NamespacePart::Fieldset(ifieldset) => {
self.add_type(
UserDefinedType::Fieldset(Rc::new(RefCell::new(Fieldset::from_idl(
&ifieldset,
ifieldset,
self,
&builtin_types,
builtin_types,
)))),
type_map,
);
}
idl::NamespacePart::Service(iservice) => {
self.services.insert(
iservice.name.clone(),
Service::from_idl(iservice, self, &builtin_types),
Service::from_idl(iservice, self, builtin_types),
);
// This is done in the next step. Since services do not
// define any types we can ignore the merging and just
Expand All @@ -104,7 +104,7 @@ impl Namespace {
..Default::default()
};
child_ns.path.push(ipart.name().to_owned());
child_ns.idl_convert(&inamespace, type_map, &builtin_types)?;
child_ns.idl_convert(inamespace, type_map, builtin_types)?;
self.namespaces.insert(inamespace.name.to_owned(), child_ns);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/schema/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ impl Service {
input: imethod
.input
.as_ref()
.map(|x| Type::from_idl(x, ns, &builtin_types)),
.map(|x| Type::from_idl(x, ns, builtin_types)),
output: imethod
.output
.as_ref()
.map(|x| Type::from_idl(x, ns, &builtin_types)),
.map(|x| Type::from_idl(x, ns, builtin_types)),
})
.collect(),
}
Expand Down
4 changes: 2 additions & 2 deletions src/schema/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Struct {
let fields = istruct
.fields
.iter()
.map(|ifield| Field::from_idl(ifield, ns, &builtin_types))
.map(|ifield| Field::from_idl(ifield, ns, builtin_types))
.collect();
Self {
fqtn: FQTN::new(&istruct.name, ns),
Expand Down Expand Up @@ -71,7 +71,7 @@ impl Field {
}
Field {
name: ifield.name.clone(),
type_: Type::from_idl(&ifield.type_, ns, &builtin_types),
type_: Type::from_idl(&ifield.type_, ns, builtin_types),
optional: ifield.optional,
// FIXME add options
//options: ifield.options
Expand Down
24 changes: 12 additions & 12 deletions src/schema/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ impl Type {
"Option" => Self::Option(Box::new(Type::from_idl(
&ityperef.generics[0],
ns,
&builtin_types,
builtin_types,
))),
"Result" => Self::Result(
Box::new(Type::from_idl(&ityperef.generics[0], ns, &builtin_types)),
Box::new(Type::from_idl(&ityperef.generics[1], ns, &builtin_types)),
Box::new(Type::from_idl(&ityperef.generics[0], ns, builtin_types)),
Box::new(Type::from_idl(&ityperef.generics[1], ns, builtin_types)),
),
name => match builtin_types.get(name) {
Some(value) => Self::Builtin(value.to_owned()),
None => Self::Ref(TypeRef::from_idl(ityperef, ns, &builtin_types)),
None => Self::Ref(TypeRef::from_idl(ityperef, ns, builtin_types)),
},
}
}
Expand All @@ -121,17 +121,17 @@ impl Type {
builtin_types: &HashMap<String, String>,
) -> Self {
match itype {
idl::Type::Ref(ityperef) => Self::from_idl_ref(&ityperef, &ns, &builtin_types),
idl::Type::Ref(ityperef) => Self::from_idl_ref(ityperef, ns, builtin_types),
idl::Type::Array(item_type) => Self::Array(Box::new(Array {
item_type: Self::from_idl(item_type, ns, &builtin_types),
item_type: Self::from_idl(item_type, ns, builtin_types),
length: Range {
start: None,
end: None,
}, // FIXME
})),
idl::Type::Map(key_type, value_type) => Self::Map(Box::new(Map {
key_type: Self::from_idl(key_type, ns, &builtin_types),
value_type: Self::from_idl(value_type, ns, &builtin_types),
key_type: Self::from_idl(key_type, ns, builtin_types),
value_type: Self::from_idl(value_type, ns, builtin_types),
length: Range {
start: None,
end: None,
Expand Down Expand Up @@ -198,7 +198,7 @@ impl TypeRef {
generics: ityperef
.generics
.iter()
.map(|itype| Type::from_idl(itype, ns, &builtin_types))
.map(|itype| Type::from_idl(itype, ns, builtin_types))
.collect(),
}
}
Expand All @@ -216,15 +216,15 @@ impl TypeRef {
}
match ud_type {
UserDefinedType::Enum(enum_) => TypeRef::Enum(EnumRef {
enum_: Rc::downgrade(&enum_),
enum_: Rc::downgrade(enum_),
generics: generics.clone(),
}),
UserDefinedType::Struct(struct_) => TypeRef::Struct(StructRef {
struct_: Rc::downgrade(&struct_),
struct_: Rc::downgrade(struct_),
generics: generics.clone(),
}),
UserDefinedType::Fieldset(fieldset) => TypeRef::Fieldset(FieldsetRef {
fieldset: Rc::downgrade(&fieldset),
fieldset: Rc::downgrade(fieldset),
generics: generics.clone(),
}),
}
Expand Down

0 comments on commit 414b483

Please sign in to comment.