Do you know of a JS formatter that will support the ma-first coding style?
var a = 'ape'
, b = 'bat'
, c = 'cat'
, d = 'dog'
, e = 'elf'
, f = 'fly'
, g = 'gnu'
, h = 'hat'
, i = 'ibu'
;
So far, I've looked at JS Beautifier & SourceFormatX but couldn't find an option for it.
Do you know of a JS formatter that will support the ma-first coding style?
var a = 'ape'
, b = 'bat'
, c = 'cat'
, d = 'dog'
, e = 'elf'
, f = 'fly'
, g = 'gnu'
, h = 'hat'
, i = 'ibu'
;
So far, I've looked at JS Beautifier & SourceFormatX but couldn't find an option for it.
Share Improve this question asked Jun 3, 2012 at 16:54 Yuriy NemtsovYuriy Nemtsov 3,9154 gold badges33 silver badges44 bronze badges 4- Thought it might be useful to know, I'm not sure this question is a valid question in Stack Overflow. – gdoron Commented Jun 3, 2012 at 16:56
- @gdoron yeah, I was thinking about putting it on Programmers but it doesn't seem to belong there either. Know of a better place? – Yuriy Nemtsov Commented Jun 3, 2012 at 16:57
-
No, Propose new site at Area 51, "off-topic". I have some questions to ask there too...
:)
– gdoron Commented Jun 3, 2012 at 17:00 - This feature is now available on the official JS Beautifier project. No hacking required. – BitwiseMan Commented Mar 17, 2015 at 0:19
1 Answer
Reset to default 9I modified the jsbeautifier code a little here:
http://jsfiddle/RabTN/29/
press doit
to see the beautified code.
I specifically modified line 1080:
if (flags.var_line) {
if (token_text === ',') {
if (flags.var_line_tainted) {
flags.var_line_reindented = true;
flags.var_line_tainted = false;
print_newline();
print_token();
print_single_space();
break;
} else {
and line 1123
if (token_text === ',') {
if (flags.var_line) {
if (flags.var_line_tainted) {
print_newline();
print_token();
print_single_space();
flags.var_line_tainted = false;
} else {
print_newline();
print_token();
print_single_space();
}
} else if (last_type === 'TK_END_BLOCK' && flags.mode !== "(EXPRESSION)") {
print_token();
if (flags.mode === 'OBJECT' && last_text === '}') {
print_newline();
} else {
print_single_space();
}
} else {
if (flags.mode === 'OBJECT') {
print_newline();
print_token();
print_single_space();
} else {
// EXPR or DO_BLOCK
print_token();
print_single_space();
}
}
break