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?
json javascript code-formatting sublimetext sublimetext3
ecbrodie
source share