mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix clippy warnings
This commit is contained in:
@ -25,9 +25,8 @@ impl DartEventCodeGen {
|
||||
for (index, render_ctx) in event_render_ctx.into_iter().enumerate() {
|
||||
let mut event_template = EventTemplate::new();
|
||||
|
||||
match event_template.render(render_ctx, index) {
|
||||
Some(content) => render_result.push_str(content.as_ref()),
|
||||
None => {}
|
||||
if let Some(content) = event_template.render(render_ctx, index) {
|
||||
render_result.push_str(content.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +88,7 @@ pub fn parse_event_crate(event_crate: &DartEventCrate) -> Vec<EventASTContext> {
|
||||
ctxt.check().unwrap();
|
||||
attrs
|
||||
.iter()
|
||||
.filter(|attr| attr.attrs.event_attrs.ignore == false)
|
||||
.filter(|attr| !attr.attrs.event_attrs.ignore)
|
||||
.enumerate()
|
||||
.map(|(_index, attr)| EventASTContext::from(&attr.attrs))
|
||||
.collect::<Vec<_>>()
|
||||
@ -103,30 +102,30 @@ pub fn parse_event_crate(event_crate: &DartEventCrate) -> Vec<EventASTContext> {
|
||||
.collect::<Vec<EventASTContext>>()
|
||||
}
|
||||
|
||||
pub fn ast_to_event_render_ctx(ast: &Vec<EventASTContext>) -> Vec<EventRenderContext> {
|
||||
pub fn ast_to_event_render_ctx(ast: &[EventASTContext]) -> Vec<EventRenderContext> {
|
||||
ast.iter()
|
||||
.map(|event_ast| {
|
||||
let input_deserializer = match event_ast.event_input {
|
||||
Some(ref event_input) => Some(event_input.get_ident().unwrap().to_string()),
|
||||
None => None,
|
||||
};
|
||||
let input_deserializer = event_ast
|
||||
.event_input
|
||||
.as_ref()
|
||||
.map(|event_input| event_input.get_ident().unwrap().to_string());
|
||||
|
||||
let output_deserializer = match event_ast.event_output {
|
||||
Some(ref event_output) => Some(event_output.get_ident().unwrap().to_string()),
|
||||
None => None,
|
||||
};
|
||||
let output_deserializer = event_ast
|
||||
.event_output
|
||||
.as_ref()
|
||||
.map(|event_output| event_output.get_ident().unwrap().to_string());
|
||||
// eprintln!(
|
||||
// "😁 {:?} / {:?}",
|
||||
// event_ast.event_input, event_ast.event_output
|
||||
// );
|
||||
|
||||
return EventRenderContext {
|
||||
EventRenderContext {
|
||||
input_deserializer,
|
||||
output_deserializer,
|
||||
error_deserializer: event_ast.event_error.clone(),
|
||||
event: event_ast.event.to_string(),
|
||||
event_ty: event_ast.event_ty.to_string(),
|
||||
};
|
||||
}
|
||||
})
|
||||
.collect::<Vec<EventRenderContext>>()
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ pub struct EventTemplate {
|
||||
tera_context: Context,
|
||||
}
|
||||
|
||||
pub const DART_IMPORTED: &'static str = r#"
|
||||
pub const DART_IMPORTED: &str = r#"
|
||||
/// Auto gen code from rust ast, do not edit
|
||||
part of 'dispatch.dart';
|
||||
"#;
|
||||
@ -21,9 +21,9 @@ pub struct EventRenderContext {
|
||||
#[allow(dead_code)]
|
||||
impl EventTemplate {
|
||||
pub fn new() -> Self {
|
||||
return EventTemplate {
|
||||
EventTemplate {
|
||||
tera_context: Context::new(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&mut self, ctx: EventRenderContext, index: usize) -> Option<String> {
|
||||
|
@ -1,3 +1,4 @@
|
||||
#![allow(clippy::module_inception)]
|
||||
mod dart_event;
|
||||
mod event_template;
|
||||
|
||||
|
@ -33,7 +33,7 @@ fn parse_files_protobuf(proto_crate_path: &str, proto_output_dir: &str) -> Vec<P
|
||||
.into_iter()
|
||||
.filter_entry(|e| !is_hidden(e))
|
||||
.filter_map(|e| e.ok())
|
||||
.filter(|e| e.file_type().is_dir() == false)
|
||||
.filter(|e| !e.file_type().is_dir())
|
||||
.map(|e| {
|
||||
let path = e.path().to_str().unwrap().to_string();
|
||||
let file_name = e.path().file_stem().unwrap().to_str().unwrap().to_string();
|
||||
@ -64,7 +64,7 @@ fn parse_files_protobuf(proto_crate_path: &str, proto_output_dir: &str) -> Vec<P
|
||||
|
||||
let s = struct_template.render().unwrap();
|
||||
proto_file_content.push_str(s.as_ref());
|
||||
proto_file_content.push_str("\n");
|
||||
proto_file_content.push('\n');
|
||||
});
|
||||
|
||||
let enums = get_ast_enums(&ast);
|
||||
@ -73,7 +73,7 @@ fn parse_files_protobuf(proto_crate_path: &str, proto_output_dir: &str) -> Vec<P
|
||||
enum_template.set_message_enum(&e);
|
||||
let s = enum_template.render().unwrap();
|
||||
proto_file_content.push_str(s.as_ref());
|
||||
proto_file_content.push_str("\n");
|
||||
proto_file_content.push('\n');
|
||||
});
|
||||
|
||||
if !enums.is_empty() || !structs.is_empty() {
|
||||
@ -95,7 +95,7 @@ pub fn parse_or_init_proto_file(path: &str) -> String {
|
||||
let mut proto_file_content = String::new();
|
||||
let imported_content = find_proto_file_import(path);
|
||||
proto_file_content.push_str(imported_content.as_ref());
|
||||
proto_file_content.push_str("\n");
|
||||
proto_file_content.push('\n');
|
||||
proto_file_content
|
||||
}
|
||||
|
||||
@ -105,8 +105,8 @@ pub fn get_ast_structs(ast: &syn::File) -> Vec<Struct> {
|
||||
// file.write_all(content.as_bytes()).unwrap();
|
||||
let ctxt = Ctxt::new();
|
||||
let mut proto_structs: Vec<Struct> = vec![];
|
||||
ast.items.iter().for_each(|item| match item {
|
||||
Item::Struct(item_struct) => {
|
||||
ast.items.iter().for_each(|item| {
|
||||
if let Item::Struct(item_struct) = item {
|
||||
let (_, fields) = struct_from_ast(&ctxt, &item_struct.fields);
|
||||
|
||||
if fields
|
||||
@ -121,7 +121,6 @@ pub fn get_ast_structs(ast: &syn::File) -> Vec<Struct> {
|
||||
});
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
});
|
||||
ctxt.check().unwrap();
|
||||
proto_structs
|
||||
@ -133,20 +132,13 @@ pub fn get_ast_enums(ast: &syn::File) -> Vec<FlowyEnum> {
|
||||
|
||||
ast.items.iter().for_each(|item| {
|
||||
// https://docs.rs/syn/1.0.54/syn/enum.Item.html
|
||||
match item {
|
||||
Item::Enum(item_enum) => {
|
||||
let attrs = flowy_ast::enum_from_ast(
|
||||
&ctxt,
|
||||
&item_enum.ident,
|
||||
&item_enum.variants,
|
||||
&ast.attrs,
|
||||
);
|
||||
flowy_enums.push(FlowyEnum {
|
||||
name: item_enum.ident.to_string(),
|
||||
attrs,
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
if let Item::Enum(item_enum) = item {
|
||||
let attrs =
|
||||
flowy_ast::enum_from_ast(&ctxt, &item_enum.ident, &item_enum.variants, &ast.attrs);
|
||||
flowy_enums.push(FlowyEnum {
|
||||
name: item_enum.ident.to_string(),
|
||||
attrs,
|
||||
});
|
||||
}
|
||||
});
|
||||
ctxt.check().unwrap();
|
||||
@ -182,18 +174,14 @@ fn find_proto_file_import(path: &str) -> String {
|
||||
|
||||
content.lines().for_each(|line| {
|
||||
////Result<Option<Match<'t>>>
|
||||
if let Ok(some_line) = SYNTAX_REGEX.find(line) {
|
||||
if let Some(m) = some_line {
|
||||
result.push_str(m.as_str());
|
||||
result.push_str("\n");
|
||||
}
|
||||
if let Ok(Some(m)) = SYNTAX_REGEX.find(line) {
|
||||
result.push_str(m.as_str());
|
||||
result.push('\n');
|
||||
}
|
||||
|
||||
if let Ok(some_line) = IMPORT_REGEX.find(line) {
|
||||
if let Some(m) = some_line {
|
||||
result.push_str(m.as_str());
|
||||
result.push_str("\n");
|
||||
}
|
||||
if let Ok(Some(m)) = IMPORT_REGEX.find(line) {
|
||||
result.push_str(m.as_str());
|
||||
result.push('\n');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -27,7 +27,7 @@ impl ProtoGen {
|
||||
}
|
||||
}
|
||||
|
||||
fn write_proto_files(crate_infos: &Vec<CrateProtoInfo>) {
|
||||
fn write_proto_files(crate_infos: &[CrateProtoInfo]) {
|
||||
for crate_info in crate_infos {
|
||||
let dir = crate_info.inner.proto_file_output_dir();
|
||||
crate_info.files.iter().for_each(|info| {
|
||||
@ -41,7 +41,7 @@ fn write_proto_files(crate_infos: &Vec<CrateProtoInfo>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn write_rust_crate_mod_file(crate_infos: &Vec<CrateProtoInfo>) {
|
||||
fn write_rust_crate_mod_file(crate_infos: &[CrateProtoInfo]) {
|
||||
for crate_info in crate_infos {
|
||||
let mod_path = crate_info.inner.proto_model_mod_file();
|
||||
match OpenOptions::new()
|
||||
@ -56,7 +56,7 @@ fn write_rust_crate_mod_file(crate_infos: &Vec<CrateProtoInfo>) {
|
||||
mod_file_content.push_str("// Auto-generated, do not edit \n");
|
||||
walk_dir(
|
||||
crate_info.inner.proto_file_output_dir().as_ref(),
|
||||
|e| e.file_type().is_dir() == false,
|
||||
|e| !e.file_type().is_dir(),
|
||||
|_, name| {
|
||||
let c = format!("\nmod {}; \npub use {}::*; \n", &name, &name);
|
||||
mod_file_content.push_str(c.as_ref());
|
||||
@ -72,7 +72,7 @@ fn write_rust_crate_mod_file(crate_infos: &Vec<CrateProtoInfo>) {
|
||||
}
|
||||
|
||||
fn write_flutter_protobuf_package_mod_file(
|
||||
crate_infos: &Vec<CrateProtoInfo>,
|
||||
crate_infos: &[CrateProtoInfo],
|
||||
package_info: &FlutterProtobufInfo,
|
||||
) {
|
||||
let model_dir = package_info.model_dir();
|
||||
@ -91,7 +91,7 @@ fn write_flutter_protobuf_package_mod_file(
|
||||
|
||||
walk_dir(
|
||||
crate_info.inner.proto_file_output_dir().as_ref(),
|
||||
|e| e.file_type().is_dir() == false,
|
||||
|e| !e.file_type().is_dir(),
|
||||
|_, name| {
|
||||
let c = format!("export './{}.pb.dart';\n", &name);
|
||||
mod_file_content.push_str(c.as_ref());
|
||||
@ -108,7 +108,7 @@ fn write_flutter_protobuf_package_mod_file(
|
||||
}
|
||||
}
|
||||
|
||||
fn run_rust_protoc(crate_infos: &Vec<CrateProtoInfo>) {
|
||||
fn run_rust_protoc(crate_infos: &[CrateProtoInfo]) {
|
||||
for crate_info in crate_infos {
|
||||
let rust_out = crate_info.inner.proto_struct_output_dir();
|
||||
let proto_path = crate_info.inner.proto_file_output_dir();
|
||||
@ -130,7 +130,7 @@ fn run_rust_protoc(crate_infos: &Vec<CrateProtoInfo>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn run_flutter_protoc(crate_infos: &Vec<CrateProtoInfo>, package_info: &FlutterProtobufInfo) {
|
||||
fn run_flutter_protoc(crate_infos: &[CrateProtoInfo], package_info: &FlutterProtobufInfo) {
|
||||
let model_dir = package_info.model_dir();
|
||||
if !Path::new(&model_dir).exists() {
|
||||
std::fs::create_dir_all(&model_dir).unwrap();
|
||||
@ -158,11 +158,8 @@ fn run_flutter_protoc(crate_infos: &Vec<CrateProtoInfo>, package_info: &FlutterP
|
||||
}
|
||||
|
||||
fn remove_everything_in_dir(dir: &str) {
|
||||
if Path::new(dir).exists() {
|
||||
if std::fs::remove_dir_all(dir).is_err()
|
||||
{
|
||||
panic!("Reset protobuf directory failed")
|
||||
};
|
||||
if Path::new(dir).exists() && std::fs::remove_dir_all(dir).is_err() {
|
||||
panic!("Reset protobuf directory failed")
|
||||
}
|
||||
std::fs::create_dir_all(dir).unwrap();
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ pub fn parse_crate_info_from_path(root: &str) -> Vec<ProtobufCrate> {
|
||||
.filter_map(|e| e.ok())
|
||||
.filter(|e| is_crate_dir(e))
|
||||
.flat_map(|e| parse_crate_config_from(&e))
|
||||
.map(|crate_config| ProtobufCrate::from_config(crate_config))
|
||||
.map(ProtobufCrate::from_config)
|
||||
.collect::<Vec<ProtobufCrate>>()
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,11 @@ pub struct ProtobufDeriveMeta {
|
||||
impl ProtobufDeriveMeta {
|
||||
pub fn new(structs: Vec<String>, enums: Vec<String>) -> Self {
|
||||
let enums: Vec<_> = enums.into_iter().unique().collect();
|
||||
return ProtobufDeriveMeta {
|
||||
ProtobufDeriveMeta {
|
||||
context: Context::new(),
|
||||
structs,
|
||||
enums,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&mut self) -> Option<String> {
|
||||
@ -37,7 +37,7 @@ impl ProtobufDeriveMeta {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_derive_meta(crate_infos: &Vec<CrateProtoInfo>, derive_meta_dir: &str) {
|
||||
pub fn write_derive_meta(crate_infos: &[CrateProtoInfo], derive_meta_dir: &str) {
|
||||
let file_proto_infos = crate_infos
|
||||
.iter()
|
||||
.map(|ref crate_info| &crate_info.files)
|
||||
@ -58,7 +58,7 @@ pub fn write_derive_meta(crate_infos: &Vec<CrateProtoInfo>, derive_meta_dir: &st
|
||||
let mut derive_template = ProtobufDeriveMeta::new(structs, enums);
|
||||
let new_content = derive_template.render().unwrap();
|
||||
let old_content = read_file(derive_meta_dir).unwrap();
|
||||
if new_content.clone() == old_content {
|
||||
if new_content == old_content {
|
||||
return;
|
||||
}
|
||||
// println!("{}", diff_lines(&old_content, &new_content));
|
||||
|
@ -1,3 +1,4 @@
|
||||
#![allow(clippy::module_inception)]
|
||||
mod derive_meta;
|
||||
|
||||
pub use derive_meta::*;
|
||||
|
@ -10,10 +10,10 @@ pub struct EnumTemplate {
|
||||
#[allow(dead_code)]
|
||||
impl EnumTemplate {
|
||||
pub fn new() -> Self {
|
||||
return EnumTemplate {
|
||||
EnumTemplate {
|
||||
context: Context::new(),
|
||||
items: vec![],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_message_enum(&mut self, flowy_enum: &FlowyEnum) {
|
||||
|
@ -24,10 +24,10 @@ pub struct StructTemplate {
|
||||
#[allow(dead_code)]
|
||||
impl StructTemplate {
|
||||
pub fn new() -> Self {
|
||||
return StructTemplate {
|
||||
StructTemplate {
|
||||
context: Context::new(),
|
||||
fields: vec![],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_message_struct_name(&mut self, name: &str) {
|
||||
@ -46,8 +46,8 @@ impl StructTemplate {
|
||||
mapped_ty = RUST_TYPE_MAP[ty];
|
||||
}
|
||||
|
||||
match field.bracket_category {
|
||||
Some(ref category) => match category {
|
||||
if let Some(ref category) = field.bracket_category {
|
||||
match category {
|
||||
BracketCategory::Opt => match &field.bracket_inner_ty {
|
||||
None => {}
|
||||
Some(inner_ty) => match inner_ty.to_string().as_str() {
|
||||
@ -93,8 +93,7 @@ impl StructTemplate {
|
||||
BracketCategory::Other => self
|
||||
.fields
|
||||
.push(format!("{} {} = {};", mapped_ty, name, index)),
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ pub fn save_content_to_file_with_diff_prompt(content: &str, output_file: &str, _
|
||||
}
|
||||
};
|
||||
if new_content != old_content {
|
||||
print_diff(old_content.clone(), new_content.clone());
|
||||
print_diff(old_content, new_content.clone());
|
||||
write_to_file()
|
||||
// if force_write {
|
||||
// write_to_file()
|
||||
@ -98,8 +98,7 @@ pub fn get_tera(directory: &str) -> Tera {
|
||||
.display()
|
||||
.to_string();
|
||||
let mut template_path = format!("{}/**/*.tera", root_absolute_path);
|
||||
if cfg!(windows)
|
||||
{
|
||||
if cfg!(windows) {
|
||||
// remove "\\?\" prefix on windows
|
||||
template_path = format!("{}/**/*.tera", &root_absolute_path[4..]);
|
||||
}
|
||||
@ -115,7 +114,7 @@ pub fn get_tera(directory: &str) -> Tera {
|
||||
|
||||
pub fn is_crate_dir(e: &walkdir::DirEntry) -> bool {
|
||||
let cargo = e.path().file_stem().unwrap().to_str().unwrap().to_string();
|
||||
cargo == "Cargo".to_string()
|
||||
cargo == *"Cargo"
|
||||
}
|
||||
|
||||
pub fn is_proto_file(e: &walkdir::DirEntry) -> bool {
|
||||
@ -123,14 +122,14 @@ pub fn is_proto_file(e: &walkdir::DirEntry) -> bool {
|
||||
return false;
|
||||
}
|
||||
let ext = e.path().extension().unwrap().to_str().unwrap().to_string();
|
||||
ext == "proto".to_string()
|
||||
ext == *"proto"
|
||||
}
|
||||
|
||||
pub fn is_hidden(entry: &walkdir::DirEntry) -> bool {
|
||||
entry
|
||||
.file_name()
|
||||
.to_str()
|
||||
.map(|s| s.starts_with("."))
|
||||
.map(|s| s.starts_with('.'))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user