Scala format is causing issues when saving my main.js file in play

559 Views Asked by At

original:

 <script src="@routes.Assets.versioned("javascripts/main.js")" type="text/javascript"></script>

Scala formatted:

<script src="@routes.Assets.versioned(" javascripts/main.js")" type="text/javascript"></script>

It is adding a space where the filename is, how can I fix this?

Is it better to have scala fmt somehow ignore js files?

2

There are 2 best solutions below

0
On

Try to exclude js files for scalafmt. Can you try this to add to .scalafmt.conf:

project.excludeFilters = [
    "public/javascripts/.*"
    ".*\\.js"
    ".*html.*"
]

But I'm not sure, I can't test it now. Note, scalafmt won't fix broken format after adding these lines. You should do it manually

UPDATE: I could reproduce that issue on my machine also, but scalafmt is not changing html files. But Intellij Idea does, you can disable them for a scpefic block or entire file by adding this on top of your file

// @formatter:off

Source

0
On

It is the editor formatter that tries to space out attributes. Not the scala formatter.

Quick workaround is to use single quotes for the attributes.

<script src='@routes.Assets.versioned("javascripts/main.js")' type="text/javascript"></script>