Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make switch/case same indent level if jslint_happy is activated. #230

Merged
merged 2 commits into from

2 participants

@hickop

No description provided.

@bitwiseman
Owner

Cool! Add tests and we're good to go.

@bitwiseman bitwiseman merged commit 1b43225 into beautify-web:master

1 check passed

Details default The Travis build passed
@bitwiseman bitwiseman referenced this pull request from a commit
@bitwiseman bitwiseman Add tweak to switch/case tests
Provide counter test using same inputs for jslint_happy = false.

Additional for #230, #213.
44586d7
@bitwiseman
Owner

@hickop - Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  js/lib/beautify.js
@@ -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;
View
2  js/test/beautify-tests.js
@@ -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}');
View
2  python/jsbeautifier/__init__.py
@@ -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)
View
2  python/jsbeautifier/tests/testjsbeautifier.py
@@ -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)');
Something went wrong with that request. Please try again.