Autoformat <img loading=#"lazy"/> breaks compilation

Take the following element as an example.

 <img
    src="https://i.ibb.co/6WW5vVC/shiptest.jpg"
    alt={"alt"}
    draggable=false
    style={ReactDOM.Style.make(~width="100%", ~height="100%", ())}
    loading=#"lazy"
/>

I saved a file with an element like this in it. The autoformatter has removed the quotes around it and then I get the following compilation error:

lazy is a reserved keyword. Keywords need to be escaped: "lazy"

file after autosave messes with it:

 <img
    loading=#lazy
    // etc etc...
/>

Is there a way to disable this autosave behavior on a per line basis or otherwise work around this? I generally want to keep autoformatting on. For now I’m going to edit this file outside of VSCode to keep the changes in it.

… package.json

        "rescript": "^11.1.4",
        "rescript-relay": "^3.0.1",
        "@rescript/core": "^1.6.1",
        "@rescript/react": "^0.13.0",

In V11 this should not autoformat, since lazy is still a reserved keyword there, but will be only a plain function in V12.

The VSCode extension already ships with a V12 formatter for testing purposes and there seems to be something off with your configuration.

Do you have allowBuiltInFormatter set to true in your VSCode’s settings.json? Also do you have an invalid path set as platformPath? Try to unset them both

"rescript.settings.platformPath": null,
"rescript.settings.allowBuiltInFormatter": false,

If that does not work you may need to point the extension to the correct platform path, e.g.:

"rescript.settings.platformPath": "node_modules/rescript/darwinarm64",

Wow! Thank you!

rescript.settings.platformPath is what fixed this on my machine.

1 Like

We’re going to specialize a few things for v12 and editor tooling anyway, so I think we might be best off reverting the v12 parser/printer to a v11 one. This would fix this issue too, without needing the configuration.

1 Like