javascriptvisual-studio-codejs-beautify

How to Prevent the Beautify Extension from Formatting Inline Javascript?


I want the ESLint extension to be the only formatter inside inline Javascript. Beautify just screws it up and I have to correct it manually.

I have added these lines to my .jsbeautifyrc file:

    "format.contentUnformatted": "script",
    "format.unformatted": "script", 

But it has no effect: Beautify still formats every line in the html file. What am I overlooking?


Solution

  • According to documentation it should be something like:

    {
      "unformatted": ["script"]
    }
    

    If that does not work, then maybe with the language setting this might work.

    You can control which file types, extensions, or specific file names should be beautified with the beautify.language setting.

    {
     "beautify.language": {
       "js": {
         "type": ["javascript", "json"],
         "filename": [".jshintrc", ".jsbeautifyrc"]
         // "ext": ["js", "json"]
         // ^^ to set extensions to be beautified using the javascript beautifier
       },
       "css": ["css", "scss"],
       "html": ["htm", "html"]
       // ^^ providing just an array sets the VS Code file type
     }
    }
    

    Above configuration should enable formatting only on specified .js files.

    Good luck.