Recently I had the issue in a Symfony project that my <script> code was not formatted correctly in .html.twig files using vscode-twig-language-2 formatter.
Searching for an existing issue or hint on configuration I found this issue. The comment by @ianshea did the trick as workaround!
<!-- parse-ignore-start --> + <!-- parse-ignore-end --> excludes the part from formatting entirely.
{# I am a .html.twig file ;) #}
<!-- parse-ignore-start -->
<script>
// Your script here
</script>
<!-- parse-ignore-end -->
See: https://github.com/mblode/vscode-twig-language-2/issues/69#issuecomment…
Hopefully one day the formatter will also be able to handle scripts formatting itself.