Skip to content

Commit 4c656f3

Browse files
committed
Use @generated in header to ignore generated files in rustfmt
Related: rust-lang/rustfmt#4296
1 parent 39d3e95 commit 4c656f3

File tree

10 files changed

+36
-32
lines changed

10 files changed

+36
-32
lines changed

src/parser.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use syn::Item::Macro;
44

55
use crate::{code, GenerationConfig, TableOptions};
66

7-
pub const FILE_SIGNATURE: &str = "/* This file is generated and managed by dsync */";
7+
pub const FILE_SIGNATURE: &str = "/* This file is @generated and managed by dsync */";
88

99
// TODO: handle postgres array types
1010
// TODO: handle postgres tuple/record types
@@ -150,7 +150,7 @@ fn handle_table_macro(macro_item: syn::ItemMacro, _config: &GenerationConfig) ->
150150
let mut table_columns: Vec<ParsedColumnMacro> = vec![];
151151

152152
let mut skip_until_semicolon = false;
153-
153+
154154
for item in macro_item.mac.tokens.into_iter() {
155155
if skip_until_semicolon {
156156
if let proc_macro2::TokenTree::Punct(punct) = item {
@@ -160,15 +160,15 @@ fn handle_table_macro(macro_item: syn::ItemMacro, _config: &GenerationConfig) ->
160160
}
161161
continue;
162162
}
163-
163+
164164
match &item {
165165
proc_macro2::TokenTree::Ident(ident) => {
166166
// skip any "use" statements
167167
if ident.to_string().eq("use") {
168168
skip_until_semicolon = true;
169169
continue;
170170
}
171-
171+
172172
table_name_ident = Some(ident.clone());
173173
}
174174
proc_macro2::TokenTree::Group(group) => {
@@ -229,7 +229,11 @@ fn handle_table_macro(macro_item: syn::ItemMacro, _config: &GenerationConfig) ->
229229
}
230230
}
231231

232-
if column_name.is_some() || column_type.is_some() || column_nullable || column_unsigned {
232+
if column_name.is_some()
233+
|| column_type.is_some()
234+
|| column_nullable
235+
|| column_unsigned
236+
{
233237
// looks like a column was in the middle of being parsed, let's panic!
234238
panic!(
235239
"Unsupported schema format! (It seems a column was partially defined)"
@@ -270,7 +274,7 @@ fn handle_table_macro(macro_item: syn::ItemMacro, _config: &GenerationConfig) ->
270274
//
271275
// The docs page for sql_types is comprehensive but it hides some alias types like Int4, Float8, etc.:
272276
// https://docs.rs/diesel/latest/diesel/sql_types/index.html
273-
fn schema_type_to_rust_type(schema_type: String) -> String {
277+
fn schema_type_to_rust_type(schema_type: String) -> String {
274278
match schema_type.to_lowercase().as_str() {
275279
"unsigned" => panic!("Unsigned types are not yet supported, please open an issue if you need this feature!"), // TODO: deal with this later
276280
"inet" => panic!("Unsigned types are not yet supported, please open an issue if you need this feature!"), // TODO: deal with this later

test/autogenerated_all/models/todos/generated.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* This file is generated and managed by dsync */
1+
/* This file is @generated and managed by dsync */
22

33
use crate::diesel::*;
44
use crate::schema::*;
55
use diesel::QueryResult;
6-
use serde::{Deserialize, Serialize};
76

7+
use serde::{Deserialize, Serialize};
88

99
type Connection = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
1010

@@ -16,7 +16,7 @@ pub struct Todo {
1616
}
1717

1818

19-
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)]
19+
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)]
2020
#[diesel(table_name=todos)]
2121
pub struct UpdateTodo {
2222
pub created_at: Option<chrono::NaiveDateTime>,

test/autogenerated_attributes/models/todos/generated.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* This file is generated and managed by dsync */
1+
/* This file is @generated and managed by dsync */
22

33
use crate::diesel::*;
44
use crate::schema::*;
55
use diesel::QueryResult;
6-
use serde::{Deserialize, Serialize};
76

7+
use serde::{Deserialize, Serialize};
88

99
type Connection = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
1010

@@ -21,7 +21,7 @@ pub struct CreateTodo {
2121
pub id: i32,
2222
}
2323

24-
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)]
24+
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)]
2525
#[diesel(table_name=todos)]
2626
pub struct UpdateTodo {
2727
pub created_at: Option<chrono::NaiveDateTime>,

test/autogenerated_primary_keys/models/todos/generated.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* This file is generated and managed by dsync */
1+
/* This file is @generated and managed by dsync */
22

33
use crate::diesel::*;
44
use crate::schema::*;
55
use diesel::QueryResult;
6-
use serde::{Deserialize, Serialize};
76

7+
use serde::{Deserialize, Serialize};
88

99
type Connection = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
1010

@@ -21,7 +21,7 @@ pub struct CreateTodo {
2121
pub text: String,
2222
}
2323

24-
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)]
24+
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)]
2525
#[diesel(table_name=todos)]
2626
pub struct UpdateTodo {
2727
pub text: Option<String>,

test/cleanup_generated_content/models/todos/generated.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* This file is generated and managed by dsync */
1+
/* This file is @generated and managed by dsync */
22

33
use crate::diesel::*;
44
use crate::schema::*;
55
use diesel::QueryResult;
6-
use serde::{Deserialize, Serialize};
76

7+
use serde::{Deserialize, Serialize};
88

99
type Connection = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
1010

@@ -26,7 +26,7 @@ pub struct CreateTodo {
2626
pub completed: bool,
2727
}
2828

29-
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)]
29+
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)]
3030
#[diesel(table_name=todos)]
3131
pub struct UpdateTodo {
3232
pub text: Option<String>,

test/manual_primary_keys/models/todos/generated.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* This file is generated and managed by dsync */
1+
/* This file is @generated and managed by dsync */
22

33
use crate::diesel::*;
44
use crate::schema::*;
55
use diesel::QueryResult;
6-
use serde::{Deserialize, Serialize};
76

7+
use serde::{Deserialize, Serialize};
88

99
type Connection = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
1010

test/multiple_primary_keys/models/users/generated.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* This file is generated and managed by dsync */
1+
/* This file is @generated and managed by dsync */
22

33
use crate::diesel::*;
44
use crate::schema::*;
55
use diesel::QueryResult;
6-
use serde::{Deserialize, Serialize};
76

7+
use serde::{Deserialize, Serialize};
88

99
type Connection = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
1010

@@ -24,7 +24,7 @@ pub struct CreateUser {
2424
pub secret: String,
2525
}
2626

27-
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)]
27+
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)]
2828
#[diesel(table_name=users)]
2929
pub struct UpdateUser {
3030
pub secret: Option<String>,

test/simple_table/models/todos/generated.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* This file is generated and managed by dsync */
1+
/* This file is @generated and managed by dsync */
22

33
use crate::diesel::*;
44
use crate::schema::*;
55
use diesel::QueryResult;
6-
use serde::{Deserialize, Serialize};
76

7+
use serde::{Deserialize, Serialize};
88

99
type Connection = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
1010

@@ -27,7 +27,7 @@ pub struct CreateTodo {
2727
pub completed: bool,
2828
}
2929

30-
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)]
30+
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)]
3131
#[diesel(table_name=todos)]
3232
pub struct UpdateTodo {
3333
pub unsigned: Option<u32>,

test/simple_table_async/models/todos/generated.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/* This file is generated and managed by dsync */
1+
/* This file is @generated and managed by dsync */
22

33
use crate::diesel::*;
44
use crate::schema::*;
55
use diesel::QueryResult;
6+
67
use serde::{Deserialize, Serialize};
78
use diesel_async::RunQueryDsl;
89

9-
1010
type Connection = diesel_async::pooled_connection::deadpool::Object<diesel_async::AsyncPgConnection>;
1111

1212
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Selectable)]
@@ -28,7 +28,7 @@ pub struct CreateTodo {
2828
pub completed: bool,
2929
}
3030

31-
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)]
31+
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)]
3232
#[diesel(table_name=todos)]
3333
pub struct UpdateTodo {
3434
pub unsigned: Option<u32>,

test/use_statements/models/fang_tasks/generated.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* This file is generated and managed by dsync */
1+
/* This file is @generated and managed by dsync */
22

33
use crate::diesel::*;
44
use crate::schema::*;
55
use diesel::QueryResult;
6-
use serde::{Deserialize, Serialize};
76

7+
use serde::{Deserialize, Serialize};
88

99
type Connection = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
1010

@@ -38,7 +38,7 @@ pub struct CreateFangTask {
3838
pub updated_at: chrono::DateTime<chrono::Utc>,
3939
}
4040

41-
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset)]
41+
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Default)]
4242
#[diesel(table_name=fang_tasks)]
4343
pub struct UpdateFangTask {
4444
pub metadata: Option<serde_json::Value>,

0 commit comments

Comments
 (0)