Permalink
Browse files

Merge pull request #230 from hickop/master

Make switch/case same indent level if jslint_happy is activated.
  • Loading branch information...
2 parents ea9acc7 + 39275fc commit 1b4322597bb10452f5d420007d40dba48ca8e107 @bitwiseman bitwiseman committed Apr 10, 2013
View
@@ -1096,7 +1096,7 @@
if (token_text === 'case' || (token_text === 'default' && flags.in_case_statement)) {
print_newline();
- if (flags.case_body) {
+ if (flags.case_body || opt.jslint_happy) {
// switch cases following one another
flags.indentation_level--;
flags.case_body = false;
@@ -340,6 +340,8 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify)
bt('a=typeof(x)', 'a = typeof (x)');
bt('x();\n\nfunction(){}', 'x();\n\nfunction () {}');
bt('function () {\n var a, b, c, d, e = [],\n f;\n}');
+ bt('switch(x) {case 0: case 1: a(); break; default: break}', "switch (x) {\ncase 0:\ncase 1:\n a();\n break;\ndefault:\n break\n}");
+ bt('switch(x){case -1:break;case !y:break;}', 'switch (x) {\ncase -1:\n break;\ncase !y:\n break;\n}');
test_fragment("// comment 1\n(function()", "// comment 1\n(function ()"); // typical greasemonkey start
bt('var o1=$.extend(a);function(){alert(x);}', 'var o1 = $.extend(a);\n\nfunction () {\n alert(x);\n}');
@@ -921,7 +921,7 @@ def handle_word(self, token_text):
if token_text == 'case' or (token_text == 'default' and self.flags.in_case_statement):
self.append_newline()
- if self.flags.case_body:
+ if self.flags.case_body or self.opts.jslint_happy:
self.flags.case_body = False
self.flags.indentation_level -= 1
self.append_token(token_text)
@@ -298,6 +298,8 @@ def test_beautifier(self):
bt('x();\n\nfunction(){}', 'x();\n\nfunction () {}');
bt('function () {\n var a, b, c, d, e = [],\n f;\n}');
+ bt('switch(x) {case 0: case 1: a(); break; default: break}', "switch (x) {\ncase 0:\ncase 1:\n a();\n break;\ndefault:\n break\n}");
+ bt('switch(x){case -1:break;case !y:break;}', 'switch (x) {\ncase -1:\n break;\ncase !y:\n break;\n}');
test_fragment("// comment 1\n(function()", "// comment 1\n(function ()"); # typical greasemonkey start
bt('var o1=$.extend(a);function(){alert(x);}', 'var o1 = $.extend(a);\n\nfunction () {\n alert(x);\n}');
bt('a=typeof(x)', 'a = typeof (x)');

0 comments on commit 1b43225

Please sign in to comment.