HookyQR / VSCodeBeautify

Enable js-beautify (https://github.com/beautify-web/js-beautify) in VS Code
MIT License
607 stars 178 forks source link

Beautify Adds Unwanted Space after "&" #370

Open guitargeek534 opened 3 years ago

guitargeek534 commented 3 years ago

I would like to know what to change/add to my settings to prevent a space from being added after a "&" and a ";" in xml codes like "&& < >".

Thank you!

User Settings:

{
    "workbench.colorTheme": "Material Theme High Contrast",
    "liveSassCompile.settings.formats,": [
        {
            "format": "expanded",
            "extensionName": ".css",
            "savePath": "~\\..\\css"
        }
    ],
    "liveSassCompile.settings.generateMap": false,
    // "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.defaultFormatter": "HookyQR.beautify",
    "[html]": {
        "editor.defaultFormatter": "HookyQR.beautify"
    },
    "window.zoomLevel": 0,
    "bookmarks.wrapNavigation": false,
    "html.format.wrapLineLength": 0,
    "html.format.wrapAttributes": "preserve-aligned",
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    "prettier.printWidth": 0,
    "prettier.stylelintIntegration": true,
    // "beautify.language": {
    //     "html": ["html", "php", "erb"],
    //     "css": [],
    //     "js": []
    // }
}

Workspace Settings:

{
    "editor.wordWrapColumn": 999,
    "editor.accessibilitySupport": "off"
}

.jsbeautifyrc

{
"beautify.config": "",
    "beautify.ignore": "",
    "beautify.language": {

        "js": {
            "type": [
                "javascript",
                "json",
                "jsonc"
            ],
            "filename": [
                ".jshintrc",
                ".jsbeautifyrc"
            ]
        },
        "css": [
            "css",
            "less",
            "scss"
        ],
        "html": [
            "htm",
            "html"
        ]
    },
    // "beautify.language": {
    //     "html": ["html", "php", "erb"],
    //     "css": [],
    //     "js": []
    // }
}

Action performed

Format javascript file with HookyQR.beautifyFile command

function pad3(number) {
var length = 3;
var str = '' + number;
while (str.length < length) {
  str = '0' + str;
}
return str;
}

function IsNumeric(input) {
return (input - 0) == input &&
input.length >
0;
}

Expected results

Expected format to

   function pad3(number) {
      var length = 3;
      var str = '' + number;
      while (str.length < length) {
        str = '0' + str;
      }
      return str;
    }

    function IsNumeric(input) {
      return (input - 0) == input &&
      input.length >
      0;
    }

NOTE - My project requires that I use xml characters/entities for &&, <, and >. So in my code I must write && for &&. < for < and > for >. When I format a space is added after the "&" (see below) which breaks my code.

Actual results

Details of what happened ...

   function pad3(number) {
      var length = 3;
      var str = '' + number;
      while (str.length & lt; length) {
        str = '0' + str;
      }
      return str;
    }

    function IsNumeric(input) {
      return (input - 0) == input & amp; & amp;
      input.length & gt;
      0;
    }