Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert newline at end of generated files #321

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ts-rs/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub(crate) fn export_to<T: TS + ?Sized + 'static, P: AsRef<Path>>(
use std::io::Write;
let mut file = File::create(path)?;
file.write_all(buffer.as_bytes())?;
file.write_all(b"\n")?;
lucperkins marked this conversation as resolved.
Show resolved Hide resolved
file.sync_data()?;
}

Expand Down
34 changes: 24 additions & 10 deletions ts-rs/tests/integration/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fn export_a() {
" */\n",
" name: string;\n",
"};\n",
"\n",
lucperkins marked this conversation as resolved.
Show resolved Hide resolved
)
} else {
concat!(
Expand All @@ -132,7 +133,8 @@ fn export_a() {
" *\n",
" * Testing\n",
" */\n",
"name: string, };"
"name: string, };",
"\n",
)
};

Expand Down Expand Up @@ -162,6 +164,7 @@ fn export_b() {
" */\n",
" name: string;\n",
"};\n",
"\n",
)
} else {
concat!(
Expand All @@ -179,6 +182,7 @@ fn export_b() {
" * Testing\n",
" */\n",
"name: string, };",
"\n",
)
};

Expand All @@ -200,7 +204,8 @@ fn export_c() {
" *\n",
" * Testing\n",
" */\n",
"export type C = Record<string, never>;\n"
"export type C = Record<string, never>;\n",
"\n",
)
} else {
concat!(
Expand All @@ -211,7 +216,8 @@ fn export_c() {
" *\n",
" * Testing\n",
" */\n",
"export type C = Record<string, never>;"
"export type C = Record<string, never>;",
"\n",
)
};

Expand All @@ -233,7 +239,8 @@ fn export_d() {
" *\n",
" * Testing\n",
" */\n",
"export type D = null;\n"
"export type D = null;\n",
"\n",
)
} else {
concat!(
Expand All @@ -244,7 +251,8 @@ fn export_d() {
" *\n",
" * Testing\n",
" */\n",
"export type D = null;"
"export type D = null;",
"\n",
)
};
let actual_content = fs::read_to_string(D::default_output_path().unwrap()).unwrap();
Expand All @@ -265,7 +273,8 @@ fn export_e() {
" *\n",
" * Testing\n",
" */\n",
"export type E = never;\n"
"export type E = never;\n",
"\n",
)
} else {
concat!(
Expand All @@ -276,7 +285,8 @@ fn export_e() {
" *\n",
" * Testing\n",
" */\n",
"export type E = never;"
"export type E = never;",
"\n",
)
};

Expand Down Expand Up @@ -307,7 +317,8 @@ fn export_f() {
" */\n",
" variant_field: number;\n",
" };\n",
"};\n"
"};\n",
"\n",
)
} else {
concat!(
Expand All @@ -324,7 +335,8 @@ fn export_f() {
" *\n",
" * Testing\n",
" */\n",
"variant_field: number, } };"
"variant_field: number, } };",
"\n",
)
};

Expand Down Expand Up @@ -356,7 +368,8 @@ fn export_g() {
" */\n",
" variant_field: number;\n",
" };\n",
" });\n"
" });\n",
"\n",
)
} else {
concat!(
Expand All @@ -373,6 +386,7 @@ fn export_g() {
" * Testing\n",
" */\n",
"variant_field: number, } });",
"\n",
)
};

Expand Down
12 changes: 8 additions & 4 deletions ts-rs/tests/integration/export_manually.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ fn export_manually() {
let expected_content = if cfg!(feature = "format") {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"export type User = { name: string; age: number; active: boolean };\n"
"export type User = { name: string; age: number; active: boolean };\n",
"\n",
)
} else {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
"\nexport type User = { name: string, age: number, active: boolean, };"
"\nexport type User = { name: string, age: number, active: boolean, };",
"\n",
)
};

Expand All @@ -48,12 +50,14 @@ fn export_manually_dir() {
let expected_content = if cfg!(feature = "format") {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
"export type UserDir = { name: string; age: number; active: boolean };\n"
"export type UserDir = { name: string; age: number; active: boolean };\n",
"\n",
)
} else {
concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
"\nexport type UserDir = { name: string, age: number, active: boolean, };"
"\nexport type UserDir = { name: string, age: number, active: boolean, };",
"\n",
)
};

Expand Down
14 changes: 8 additions & 6 deletions ts-rs/tests/integration/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn test_def() {
"\n",
"export type TestEnum = { \"C\": { value: TestTypeB<number> } } | {\n",
" \"A1\": { value: TestTypeA<number> };\n",
"} | { \"A2\": { value: TestTypeA<number> } };\n"

"} | { \"A2\": { value: TestTypeA<number> } };\n",
"\n",
),
(true, false) => concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
Expand All @@ -46,22 +46,24 @@ fn test_def() {
"\n",
"export type TestEnum = { \"C\": { value: TestTypeB<number> } } | {\n",
" \"A1\": { value: TestTypeA<number> };\n",
"} | { \"A2\": { value: TestTypeA<number> } };\n"

"} | { \"A2\": { value: TestTypeA<number> } };\n",
"\n",
),
(false, true) => concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
"import type { TestTypeA } from \"./ts_rs_test_type_a.js\";\n",
"import type { TestTypeB } from \"./ts_rs_test_type_b.js\";\n",
"\n",
"export type TestEnum = { \"C\": { value: TestTypeB<number>, } } | { \"A1\": { value: TestTypeA<number>, } } | { \"A2\": { value: TestTypeA<number>, } };"
"export type TestEnum = { \"C\": { value: TestTypeB<number>, } } | { \"A1\": { value: TestTypeA<number>, } } | { \"A2\": { value: TestTypeA<number>, } };",
"\n",
),
(false, false) => concat!(
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
"import type { TestTypeA } from \"./ts_rs_test_type_a\";\n",
"import type { TestTypeB } from \"./ts_rs_test_type_b\";\n",
"\n",
"export type TestEnum = { \"C\": { value: TestTypeB<number>, } } | { \"A1\": { value: TestTypeA<number>, } } | { \"A2\": { value: TestTypeA<number>, } };"
"export type TestEnum = { \"C\": { value: TestTypeB<number>, } } | { \"A1\": { value: TestTypeA<number>, } } | { \"A2\": { value: TestTypeA<number>, } };",
"\n",
),
};

Expand Down