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

[BUG] [Formatter] Repeated indentation of multiline JS string with --format-js #614

Closed
3 tasks done
vEnhance opened this issue Apr 25, 2023 · 5 comments
Closed
3 tasks done
Labels

Comments

@vEnhance
Copy link

System Info

  • OS: Arch Linux
  • Python Version (python --version) = 3.10.10
  • djLint Version (djlint --version) = 1.25.0
  • template language: djhtml

Issue

This was encountered in vEnhance/otis-web#191 (comment) and I am forwarding upstream at the request of @christopherpickering.

The snippet

<script type="text/javascript">
    let s = `
        <p>Text.</p>`;
</script>

is not reformatted properly by djlint with --format-js. Running the command causes the text line to be indented one further level each time.

How To Reproduce

Run djlint --format-js --reformat snippet.html on the snippet above. Example terminal session below as both text and image.

I /tm/djlint >> cat snippet.html                                                            dj🐍 [15:25]
<script type="text/javascript">
    let s = `
        <p>Text.</p>`;
</script>
I /tm/djlint >> djlint --version                                                            dj🐍 [15:25]
djlint, version 1.25.0
I /tm/djlint >> python --version                                                            dj🐍 [15:25]
Python 3.10.10
I /tm/djlint >> djlint --reformat --format-js snippet.html                                  dj🐍 [15:26]

Reformatting 1/1 files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00    


tmp/djlint/snippet.html
───────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -1,4 +1,4 @@

 <script type="text/javascript">
     let s = `
-        <p>Text.</p>`;
+            <p>Text.</p>`;
 </script>

1 file was updated.

I /tm/djlint [1] >> djlint --reformat --format-js snippet.html                              dj🐍 [15:28]

Reformatting 1/1 files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00    


tmp/djlint/snippet.html
───────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -1,4 +1,4 @@

 <script type="text/javascript">
     let s = `
-            <p>Text.</p>`;
+                <p>Text.</p>`;
 </script>

1 file was updated.

image

@vEnhance vEnhance added 🦠 bug Something isn't working 🧽 formatter labels Apr 25, 2023
@welcome
Copy link

welcome bot commented Apr 25, 2023

Thanks for opening your first issue here!

@vEnhance
Copy link
Author

Might be related to #600.

@christopherpickering
Copy link
Contributor

christopherpickering commented Apr 26, 2023

Thanks, I looked into it a bit and it seems like the contents of backtick blocks are not touched by jsbeautifier (good), but djlint wasn't expecting it :) . I'll see what can be done to fix this. Thanks for opening the issue!

@christopherpickering
Copy link
Contributor

Sorry for the delay, this should be fixed by the next release.

christopherpickering pushed a commit that referenced this issue May 8, 2023
## [1.25.1](v1.25.0...v1.25.1) (2023-05-08)

### Bug Fixes

* **js indent:** fixed an issue where literal strings were double indented ([b1e8ab2](b1e8ab2)), closes [#614](#614)
* **set:** added formatting of json/list style set contents ([85aca4c](85aca4c)), closes [#287](#287) [#518](#518) [#370](#370)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.25.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants