Skip to content

Commit

Permalink
Fix incorrect use statements (#137)
Browse files Browse the repository at this point in the history
* Fix incorrect use statements

* Fix new clippy warnings

Co-authored-by: Benoît CORTIER <[email protected]>
  • Loading branch information
Benoît C and CBenoit authored Jan 12, 2021
1 parent 5f3602d commit a4192e3
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion saphir/src/file/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl FromStr for Range {
}
Ok(Range::Bytes(ranges))
}
(Some(unit), Some(range_str)) if unit != "" && range_str != "" => Ok(Range::Unregistered(unit.to_owned(), range_str.to_owned())),
(Some(unit), Some(range_str)) if !unit.is_empty() && !range_str.is_empty() => Ok(Range::Unregistered(unit.to_owned(), range_str.to_owned())),
_ => Err(SaphirError::Other("Bad Format".to_owned())),
}
}
Expand Down
1 change: 1 addition & 0 deletions saphir/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ impl UriPathMatcher {
}

#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum UriPathSegmentMatcher {
Static { segment: String },
Variable { name: Option<String> },
Expand Down
4 changes: 2 additions & 2 deletions saphir_cli/src/openapi/generate/crate_syn_browser/item.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::Module;
use crate::openapi::generate::crate_syn_browser::UseScope;
use lazycell::LazyCell;
use std::fmt::Debug;
use std::fmt::{Debug, Formatter};
use syn::{
export::Formatter, ImplItem as SynImplItem, ImplItemMethod as SynImplItemMethod, Item as SynItem, ItemEnum as SynItemEnum, ItemImpl as SynItemImpl,
ImplItem as SynImplItem, ImplItemMethod as SynImplItemMethod, Item as SynItem, ItemEnum as SynItemEnum, ItemImpl as SynItemImpl,
ItemStruct as SynItemStruct, ItemUse as SynItemUse,
};

Expand Down
6 changes: 4 additions & 2 deletions saphir_cli/src/openapi/generate/crate_syn_browser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{fmt::Debug, path::PathBuf};
use syn::export::{fmt::Display, Formatter};
use std::{
fmt::{Debug, Display, Formatter},
path::PathBuf,
};
use Error::*;

mod browser;
Expand Down
13 changes: 6 additions & 7 deletions saphir_cli/src/openapi/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ use serde_derive::Deserialize;
use std::{
cell::RefCell,
collections::{BTreeMap, HashMap, HashSet},
fmt::{Display, Formatter},
fs::File as FsFile,
io::Read,
path::PathBuf,
str::FromStr,
time::Instant,
};
use structopt::StructOpt;
use syn::{
export::{fmt::Display, Formatter},
Attribute, Fields, Item as SynItem, ItemEnum, ItemStruct, Lit, Meta, NestedMeta, Signature,
};
use syn::{Attribute, Fields, Item as SynItem, ItemEnum, ItemStruct, Lit, Meta, NestedMeta, Signature};

mod controller_info;
mod crate_syn_browser;
Expand Down Expand Up @@ -151,11 +149,12 @@ impl Command for Gen {
type Args = GenArgs;

fn new(args: Self::Args) -> Self {
let mut doc = OpenApi::default();
doc.openapi_version = "3.0.3".to_string();
Self {
args,
doc,
doc: OpenApi {
openapi_version: "3.0.3".to_string(),
..OpenApi::default()
},
operation_ids: RefCell::new(Default::default()),
generated_schema_names: Default::default(),
}
Expand Down
4 changes: 2 additions & 2 deletions saphir_cli/src/openapi/generate/response_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Gen {
Ok(c) => c,
_ => continue,
};
if c < 100 || c >= 600 {
if !(100..600).contains(&c) {
continue;
}
codes.push(c);
Expand Down Expand Up @@ -214,7 +214,7 @@ impl Gen {
Ok(c) => c,
_ => continue,
};
if c < 100 || c >= 600 {
if !(100..600).contains(&c) {
continue;
}
codes.push(c);
Expand Down
3 changes: 1 addition & 2 deletions saphir_macro/src/controller/controller_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::controller::handler::{HandlerAttrs, HandlerRepr};
use proc_macro2::{Ident, TokenStream};
use syn::{AttributeArgs, Error, ItemImpl, Lit, Meta, MetaNameValue, NestedMeta, Result};

use quote::quote;
use syn::export::ToTokens;
use quote::{quote, ToTokens};

#[derive(Debug)]
pub struct ControllerAttr {
Expand Down
10 changes: 5 additions & 5 deletions saphir_macro/src/controller/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::str::FromStr;

use http::Method;
use proc_macro2::{Ident, TokenStream};
use quote::quote_spanned;
use quote::{quote_spanned, ToTokens};
use syn::{
export::ToTokens, spanned::Spanned, Attribute, Error, Expr, FnArg, GenericArgument, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta, MetaNameValue,
NestedMeta, Pat, PatIdent, PatType, Path, PathArguments, PathSegment, Result, ReturnType, Type, TypePath,
spanned::Spanned, Attribute, Error, Expr, FnArg, GenericArgument, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta, MetaNameValue, NestedMeta, Pat, PatIdent,
PatType, Path, PathArguments, PathSegment, Result, ReturnType, Type, TypePath,
};

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -433,7 +433,7 @@ impl HandlerAttrs {
let c: u16 = i
.base10_parse()
.map_err(|_| Error::new_spanned(i, "Invalid status code"))?;
if c < 100 || c >= 600 {
if !(100..600).contains(&c) {
return Err(Error::new_spanned(i, "Invalid status code"));
}
nb_code += 1;
Expand Down Expand Up @@ -522,7 +522,7 @@ impl HandlerAttrs {
let c: u16 = i
.base10_parse()
.map_err(|_| Error::new_spanned(i, "Invalid status code"))?;
if c < 100 || c >= 600 {
if !(100..600).contains(&c) {
return Err(Error::new_spanned(i, "Invalid status code"));
}
nb_code += 1;
Expand Down
4 changes: 2 additions & 2 deletions saphir_macro/src/controller/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use proc_macro2::{Ident, Span, TokenStream};
use syn::{export::ToTokens, spanned::Spanned, AttributeArgs, Error, GenericArgument, ItemImpl, PathArguments, Result, Type};
use syn::{spanned::Spanned, AttributeArgs, Error, GenericArgument, ItemImpl, PathArguments, Result, Type};

use quote::quote;
use quote::{quote, ToTokens};

use crate::controller::{
controller_attr::ControllerAttr,
Expand Down
3 changes: 2 additions & 1 deletion saphir_macro/src/openapi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use proc_macro2::TokenStream;
use syn::{export::ToTokens, AttributeArgs, Error, Item, Lit, Meta, NestedMeta, Result};
use quote::ToTokens;
use syn::{AttributeArgs, Error, Item, Lit, Meta, NestedMeta, Result};

const MISSING_ATRIBUTE: &str = "openapi macro require at least one of the following attributes :
- mime
Expand Down

0 comments on commit a4192e3

Please sign in to comment.