Sublime JSFormat: configure to not format JSON

I was looking for a website for a good Sublime (3) package to automatically format my source code in different languages, namely JavaScript. I came across this SOF post ( Sublime Text 2: Auto fix indentation for javascript? ) And therefore decided to give JSFormat . So far this has looked pretty good ... unless it handles JSON objects in JS code. For example, suppose I have a function like this:

function foo() { return {name: 'Dave', score: 1000}; } 

It returns a JavaScript object in JSON format, prettu a lot of hash object. I like to write such objects on one line because it is simple and easy to read, especially since it is just a small, ad-hoc object. But, if I had to format this using JSFormat, my function would now look like this:

 function foo() { return { name: 'Dave', score: 1000 }; } 

Maybe it's just me, but I really don't like to represent such simple JSON objects on multiple lines. Yes, usually JavaScript code requiring brackets should contain its content in separate lines from curly braces, for example, in functions, if instructions and loops. Perhaps if the JSON object was a long object that contained functions inside it, such as the jQuery Ajax class, then it makes sense to split the attributes into several lines.

However, regardless of whether my brace bindings make sense, I know that JSFormat supports configuration and there may be a way to configure JSFormat to not separate the attributes of the JSON object across multiple lines if that is not desired. Any ideas?

+7
json javascript code-formatting sublimetext sublimetext3
source share
1 answer

Sorry for the bad news, but ...

JSFormat uses js-beautify , which does not support single-line function definitions. Everything is broken into β€œdecorated” lines, which makes it β€œmore readable."

See the example given for js-beautify ... the example itself is a single line definition. It is not possible to distinguish single-line definitions of the functions that you want to keep from those that you do not have.

If you think about it, the ideal situation for using a decorator is that you want to use a mini-code and make it readable ... This is also one long line of code.

I feel your pain, believe me.

+6
source share

All Articles