chore: deny and fix all clippy rules

This commit is contained in:
Dmitriy Pleshevskiy 2021-04-15 23:54:28 +03:00
parent 151e830157
commit 7ed17d8951
4 changed files with 19 additions and 14 deletions

View file

@ -125,7 +125,7 @@ impl ToTokens for Variable {
let env_name = &self let env_name = &self
.env_name .env_name
.clone() .clone()
.unwrap_or(name.to_string().to_uppercase()); .unwrap_or_else(|| name.to_string().to_uppercase());
let meta = vec_to_token_stream_2(&self.meta); let meta = vec_to_token_stream_2(&self.meta);
let get_variable: TokenStream2 = if self.concat_parts.is_some() { let get_variable: TokenStream2 = if self.concat_parts.is_some() {

View file

@ -1,4 +1,5 @@
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![deny(clippy::all)]
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
mod ast; mod ast;

View file

@ -117,7 +117,7 @@ impl Parse for RootNamespace {
match attr.parse_meta()? { match attr.parse_meta()? {
Meta::List(MetaList { nested, .. }) => { Meta::List(MetaList { nested, .. }) => {
let message = let message =
format!("expected #[config(name = \"...\")] or #[config(unwrap)]"); "expected #[config(name = \"...\")] or #[config(unwrap)]".to_string();
match nested.first().unwrap() { match nested.first().unwrap() {
NestedMeta::Meta(Meta::NameValue(MetaNameValue { NestedMeta::Meta(Meta::NameValue(MetaNameValue {
path, path,
@ -127,7 +127,7 @@ impl Parse for RootNamespace {
if path.is_ident("name") { if path.is_ident("name") {
name = Some(Ident::new(&lit_str.value(), Span::call_site())); name = Some(Ident::new(&lit_str.value(), Span::call_site()));
} else { } else {
Err(Error::new_spanned(attr, message))?; return Err(Error::new_spanned(attr, message));
} }
} }
NestedMeta::Meta(Meta::Path(path)) => { NestedMeta::Meta(Meta::Path(path)) => {
@ -135,17 +135,17 @@ impl Parse for RootNamespace {
name = None; name = None;
with_module = false; with_module = false;
} else { } else {
Err(Error::new_spanned(attr, message))?; return Err(Error::new_spanned(attr, message));
} }
} }
_ => { _ => {
Err(Error::new_spanned(attr, message))?; return Err(Error::new_spanned(attr, message));
} }
} }
} }
_ => { _ => {
let message = format!("expected #[config(...)]"); let message = "expected #[config(...)]".to_string();
Err(Error::new_spanned(attr, message))?; return Err(Error::new_spanned(attr, message));
} }
} }
} else { } else {
@ -166,7 +166,7 @@ impl Parse for RootNamespace {
let prefix = String::new(); let prefix = String::new();
let namespaces = namespaces let namespaces = namespaces
.into_iter() .into_iter()
.map(fill_env_prefix(prefix.clone())) .map(fill_env_prefix(prefix))
.collect(); .collect();
Ok(RootNamespace { Ok(RootNamespace {
@ -231,7 +231,10 @@ impl Parse for Variable {
if content.peek(Ident::peek_any) { if content.peek(Ident::peek_any) {
let concat_var: Variable = content.parse()?; let concat_var: Variable = content.parse()?;
let name = &concat_var.name; let name = &concat_var.name;
let env_name = &concat_var.env_name.clone().unwrap_or(name.to_string()); let env_name = &concat_var
.env_name
.clone()
.unwrap_or_else(|| name.to_string());
let get_variable = if concat_var.initial.is_some() { let get_variable = if concat_var.initial.is_some() {
let initial = concat_var.initial.as_ref().unwrap(); let initial = concat_var.initial.as_ref().unwrap();
@ -245,8 +248,10 @@ impl Parse for Variable {
let part: Lit = content.parse()?; let part: Lit = content.parse()?;
tmp_vec.push(quote!(#part.to_string())); tmp_vec.push(quote!(#part.to_string()));
} }
content.parse::<Comma>().ok(); content.parse::<Comma>().ok();
} }
concat_parts = Some(tmp_vec); concat_parts = Some(tmp_vec);
} else { } else {
initial = input initial = input

View file

@ -2,7 +2,9 @@ use proc_macro2::TokenStream as TokenStream2;
use quote::ToTokens; use quote::ToTokens;
use syn::{Path, Type}; use syn::{Path, Type};
pub fn vec_to_token_stream_2<T>(input: &Vec<T>) -> Vec<TokenStream2> const OPTION_PATH_IDENTS: &[&str] = &["Option|", "std|option|Option|", "core|option|Option|"];
pub fn vec_to_token_stream_2<T>(input: &[T]) -> Vec<TokenStream2>
where where
T: ToTokens, T: ToTokens,
{ {
@ -21,10 +23,7 @@ fn path_ident(path: &Path) -> String {
} }
fn is_option_path_ident(path_ident: String) -> bool { fn is_option_path_ident(path_ident: String) -> bool {
vec!["Option|", "std|option|Option|", "core|option|Option|"] OPTION_PATH_IDENTS.iter().any(|s| path_ident == *s)
.into_iter()
.find(|s| &path_ident == *s)
.is_some()
} }
pub fn is_option_type(ty: &Type) -> bool { pub fn is_option_type(ty: &Type) -> bool {