From 3134a6a07a454c79fa4aae5c53bf742239a2816b Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Mon, 14 Aug 2023 09:42:42 +0200 Subject: [PATCH] Use @generated in header to ignore generated files in rustfmt Related: https://github.com/rust-lang/rustfmt/pull/4296 --- src/parser.rs | 16 ++++++++++------ test/autogenerated_all/models/todos/generated.rs | 6 +++--- .../models/todos/generated.rs | 6 +++--- .../models/todos/generated.rs | 6 +++--- .../models/todos/generated.rs | 6 +++--- .../models/todos/generated.rs | 4 ++-- .../models/users/generated.rs | 6 +++--- test/simple_table/models/todos/generated.rs | 6 +++--- .../simple_table_async/models/todos/generated.rs | 6 +++--- .../models/fang_tasks/generated.rs | 6 +++--- 10 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 14b9d730..13ff0d12 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4,7 +4,7 @@ use syn::Item::Macro; use crate::{code, GenerationConfig, TableOptions}; -pub const FILE_SIGNATURE: &str = "/* This file is generated and managed by dsync */"; +pub const FILE_SIGNATURE: &str = "/* @generated and managed by dsync */"; // TODO: handle postgres array types // TODO: handle postgres tuple/record types @@ -150,7 +150,7 @@ fn handle_table_macro(macro_item: syn::ItemMacro, _config: &GenerationConfig) -> let mut table_columns: Vec = vec![]; let mut skip_until_semicolon = false; - + for item in macro_item.mac.tokens.into_iter() { if skip_until_semicolon { if let proc_macro2::TokenTree::Punct(punct) = item { @@ -160,7 +160,7 @@ fn handle_table_macro(macro_item: syn::ItemMacro, _config: &GenerationConfig) -> } continue; } - + match &item { proc_macro2::TokenTree::Ident(ident) => { // skip any "use" statements @@ -168,7 +168,7 @@ fn handle_table_macro(macro_item: syn::ItemMacro, _config: &GenerationConfig) -> skip_until_semicolon = true; continue; } - + table_name_ident = Some(ident.clone()); } proc_macro2::TokenTree::Group(group) => { @@ -229,7 +229,11 @@ fn handle_table_macro(macro_item: syn::ItemMacro, _config: &GenerationConfig) -> } } - if column_name.is_some() || column_type.is_some() || column_nullable || column_unsigned { + if column_name.is_some() + || column_type.is_some() + || column_nullable + || column_unsigned + { // looks like a column was in the middle of being parsed, let's panic! panic!( "Unsupported schema format! (It seems a column was partially defined)" @@ -270,7 +274,7 @@ fn handle_table_macro(macro_item: syn::ItemMacro, _config: &GenerationConfig) -> // // The docs page for sql_types is comprehensive but it hides some alias types like Int4, Float8, etc.: // https://docs.rs/diesel/latest/diesel/sql_types/index.html -fn schema_type_to_rust_type(schema_type: String) -> String { +fn schema_type_to_rust_type(schema_type: String) -> String { match schema_type.to_lowercase().as_str() { "unsigned" => panic!("Unsigned types are not yet supported, please open an issue if you need this feature!"), // TODO: deal with this later "inet" => panic!("Unsigned types are not yet supported, please open an issue if you need this feature!"), // TODO: deal with this later diff --git a/test/autogenerated_all/models/todos/generated.rs b/test/autogenerated_all/models/todos/generated.rs index f9fb58f3..7b54e7eb 100644 --- a/test/autogenerated_all/models/todos/generated.rs +++ b/test/autogenerated_all/models/todos/generated.rs @@ -1,10 +1,10 @@ -/* This file is generated and managed by dsync */ +/* @generated and managed by dsync */ use crate::diesel::*; use crate::schema::*; use diesel::QueryResult; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; type Connection = diesel::r2d2::PooledConnection>; @@ -16,7 +16,7 @@ pub struct Todo { } -#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)] +#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodo { pub created_at: Option, diff --git a/test/autogenerated_attributes/models/todos/generated.rs b/test/autogenerated_attributes/models/todos/generated.rs index b4f70082..703c5cf1 100644 --- a/test/autogenerated_attributes/models/todos/generated.rs +++ b/test/autogenerated_attributes/models/todos/generated.rs @@ -1,10 +1,10 @@ -/* This file is generated and managed by dsync */ +/* @generated and managed by dsync */ use crate::diesel::*; use crate::schema::*; use diesel::QueryResult; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; type Connection = diesel::r2d2::PooledConnection>; @@ -21,7 +21,7 @@ pub struct CreateTodo { pub id: i32, } -#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)] +#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodo { pub created_at: Option, diff --git a/test/autogenerated_primary_keys/models/todos/generated.rs b/test/autogenerated_primary_keys/models/todos/generated.rs index f13037f9..1011c5bd 100644 --- a/test/autogenerated_primary_keys/models/todos/generated.rs +++ b/test/autogenerated_primary_keys/models/todos/generated.rs @@ -1,10 +1,10 @@ -/* This file is generated and managed by dsync */ +/* @generated and managed by dsync */ use crate::diesel::*; use crate::schema::*; use diesel::QueryResult; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; type Connection = diesel::r2d2::PooledConnection>; @@ -21,7 +21,7 @@ pub struct CreateTodo { pub text: String, } -#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)] +#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodo { pub text: Option, diff --git a/test/cleanup_generated_content/models/todos/generated.rs b/test/cleanup_generated_content/models/todos/generated.rs index 120cc801..70796a18 100644 --- a/test/cleanup_generated_content/models/todos/generated.rs +++ b/test/cleanup_generated_content/models/todos/generated.rs @@ -1,10 +1,10 @@ -/* This file is generated and managed by dsync */ +/* @generated and managed by dsync */ use crate::diesel::*; use crate::schema::*; use diesel::QueryResult; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; type Connection = diesel::r2d2::PooledConnection>; @@ -26,7 +26,7 @@ pub struct CreateTodo { pub completed: bool, } -#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)] +#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodo { pub text: Option, diff --git a/test/manual_primary_keys/models/todos/generated.rs b/test/manual_primary_keys/models/todos/generated.rs index 274c4ecf..296b0897 100644 --- a/test/manual_primary_keys/models/todos/generated.rs +++ b/test/manual_primary_keys/models/todos/generated.rs @@ -1,10 +1,10 @@ -/* This file is generated and managed by dsync */ +/* @generated and managed by dsync */ use crate::diesel::*; use crate::schema::*; use diesel::QueryResult; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; type Connection = diesel::r2d2::PooledConnection>; diff --git a/test/multiple_primary_keys/models/users/generated.rs b/test/multiple_primary_keys/models/users/generated.rs index bea7a5f8..97f3def1 100644 --- a/test/multiple_primary_keys/models/users/generated.rs +++ b/test/multiple_primary_keys/models/users/generated.rs @@ -1,10 +1,10 @@ -/* This file is generated and managed by dsync */ +/* @generated and managed by dsync */ use crate::diesel::*; use crate::schema::*; use diesel::QueryResult; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; type Connection = diesel::r2d2::PooledConnection>; @@ -24,7 +24,7 @@ pub struct CreateUser { pub secret: String, } -#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)] +#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)] #[diesel(table_name=users)] pub struct UpdateUser { pub secret: Option, diff --git a/test/simple_table/models/todos/generated.rs b/test/simple_table/models/todos/generated.rs index 15a2f939..60f4d44b 100644 --- a/test/simple_table/models/todos/generated.rs +++ b/test/simple_table/models/todos/generated.rs @@ -1,10 +1,10 @@ -/* This file is generated and managed by dsync */ +/* @generated and managed by dsync */ use crate::diesel::*; use crate::schema::*; use diesel::QueryResult; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; type Connection = diesel::r2d2::PooledConnection>; @@ -27,7 +27,7 @@ pub struct CreateTodo { pub completed: bool, } -#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)] +#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodo { pub unsigned: Option, diff --git a/test/simple_table_async/models/todos/generated.rs b/test/simple_table_async/models/todos/generated.rs index 3825307e..8634790b 100644 --- a/test/simple_table_async/models/todos/generated.rs +++ b/test/simple_table_async/models/todos/generated.rs @@ -1,12 +1,12 @@ -/* This file is generated and managed by dsync */ +/* @generated and managed by dsync */ use crate::diesel::*; use crate::schema::*; use diesel::QueryResult; + use serde::{Deserialize, Serialize}; use diesel_async::RunQueryDsl; - type Connection = diesel_async::pooled_connection::deadpool::Object; #[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Selectable)] @@ -28,7 +28,7 @@ pub struct CreateTodo { pub completed: bool, } -#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)] +#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodo { pub unsigned: Option, diff --git a/test/use_statements/models/fang_tasks/generated.rs b/test/use_statements/models/fang_tasks/generated.rs index 46cc96f8..35b38bde 100644 --- a/test/use_statements/models/fang_tasks/generated.rs +++ b/test/use_statements/models/fang_tasks/generated.rs @@ -1,10 +1,10 @@ -/* This file is generated and managed by dsync */ +/* @generated and managed by dsync */ use crate::diesel::*; use crate::schema::*; use diesel::QueryResult; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; type Connection = diesel::r2d2::PooledConnection>; @@ -38,7 +38,7 @@ pub struct CreateFangTask { pub updated_at: chrono::DateTime, } -#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)] +#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)] #[diesel(table_name=fang_tasks)] pub struct UpdateFangTask { pub metadata: Option,