1

Let's say you have an example.js file open in SublimeText:

function foo(bar){a=1;b=2;for(var i=0;i<100;i++){console.log(i);};}

How to automatically have an indented code with SublimeText? such as:

function foo(bar) {
    a=1;
    b=2;
    for (var i=0;i<100;i++) {
        console.log(i);
    };
}

I tried Edit > Line > Reindent or CTRL+SHIFT+P Reindent but it does nothing on this code. Why?

How is this possible without a third-party package requiring node.js installed (such as HTML-CSS-JS Prettify)?

Basj
  • 41,386
  • 99
  • 383
  • 673

1 Answers1

3

Since you don't want a Node.js server running just for formatting, and because it works really well for me, I'd recommend checking out JsFormat. I looked through the source, and the only .js files I could find are for testing -- everything else, including the underlying jsbeautifier library, is written in Python, so it'll run as a native plugin.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • Good idea! Sidenote: [here is how](https://stackoverflow.com/a/37182999) to use `jsbeautifier` directly with Python. – Basj Nov 17 '21 at 09:45