Skip to content

Commit

Permalink
feat: preserve formatting of unknown macros (#121)
Browse files Browse the repository at this point in the history
* feat: preserve formatting of unknown macros

* fix workspace versions

* workspace syn & proc_macro2 versions
  • Loading branch information
bram209 authored May 24, 2024
1 parent f8a9ff9 commit f4229d6
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
fetch-depth: 0

- name: Generate a changelog
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ version = "0.1.18"
license = "MIT OR Apache-2.0"

[workspace.dependencies]
leptosfmt-prettyplease = { path = "./prettyplease", version = "0.2.20", features = [
leptosfmt-prettyplease = { path = "./prettyplease", version = "0.1.18", features = [
"verbatim",
] }
leptosfmt-formatter = { path = "./formatter", version = "0.1.18" }
leptosfmt-pretty-printer = { version = "0.1.8" }
leptosfmt-pretty-printer = { version = "0.1.18" }

syn = { version = "2.0.59", features = ["visit", "full", "extra-traits"] }
proc-macro2 = { version = "1.0.80", features = ["span-locations"] }

[patch.crates-io]
leptosfmt-pretty-printer = { path = "./printer" }
4 changes: 2 additions & 2 deletions formatter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ description = "view macro formatter for the Leptos web framework"
leptosfmt-pretty-printer.workspace = true
leptosfmt-prettyplease.workspace = true
rstml = "0.11.2"
syn = { version = "2.0.18", features = ["visit", "full", "extra-traits"] }
proc-macro2 = { version = "1.0.68", features = ["span-locations"] }
syn = { workspace = true }
proc-macro2 = { workspace = true }
thiserror = "1.0.40"
crop = "0.3.0"
serde = { version = "1.0.163", features = ["derive"] }
Expand Down
55 changes: 55 additions & 0 deletions formatter/src/source_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,61 @@ mod tests {
"#);
}

#[test]
fn preserve_formatting_unknown_macros() {
let source = indoc! {r#"
#[component]
pub fn HeaderField() -> impl IntoView {
view! {
<div class="HeaderField start">
<h1>Hello Kanna</h1>
</div>
{
style! {
h1 {
background-color: red;
color: white;
}
@media (orientation: portrait) {
h1 {
background-color: green;
}
}
}
}
}
}"#};

let result = format_file_source(source, &Default::default()).unwrap();
insta::assert_snapshot!(result, @r###"
#[component]
pub fn HeaderField() -> impl IntoView {
view! {
<div class="HeaderField start">
<h1>Hello Kanna</h1>
</div>
{
style! {
h1 {
background-color: red;
color: white;
}
@media (orientation: portrait) {
h1 {
background-color: green;
}
}
}
}
}
}
"###);
}

#[test]
fn fully_qualified_macro_path_overridden() {
let source = indoc! {r#"
Expand Down
2 changes: 1 addition & 1 deletion prettyplease
Submodule prettyplease updated 2 files
+3 −3 Cargo.toml
+8 −2 src/mac.rs
2 changes: 1 addition & 1 deletion printer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "leptosfmt-pretty-printer"
version = "0.1.8"
version = { workspace = true }
edition = "2021"
description = "leptosfmt's pretty printer based on the prettyplease crate"
license = { workspace = true }
Expand Down

0 comments on commit f4229d6

Please sign in to comment.