mirror of
https://github.com/beautifier/js-beautify.git
synced 2025-02-07 13:27:43 +00:00
Added comma separation CLI option for brace_style
Removed brace_preserve_inline from everywhere Correctly validates CLI arguments in both Python and Javascript
This commit is contained in:
parent
510a88750b
commit
1509a1fa54
@ -43,7 +43,7 @@ Example:
|
||||
"max_preserve_newlines": 10,
|
||||
"jslint_happy": false,
|
||||
"space_after_anon_function": false,
|
||||
"brace_style": "collapse-preserve-inline",
|
||||
"brace_style": "collapse,preserve-inline",
|
||||
"keep_array_indentation": false,
|
||||
"keep_function_indentation": false,
|
||||
"space_before_conditional": true,
|
||||
|
@ -106,8 +106,7 @@ Beautifier Options:
|
||||
-P, --space-in-paren Add padding spaces within paren, ie. f( a, b )
|
||||
-j, --jslint-happy Enable jslint-stricter mode
|
||||
-a, --space-after-anon-function Add a space before an anonymous function's parens, ie. function ()
|
||||
-b, --brace-style [collapse|expand|end-expand|none] ["collapse"]
|
||||
-i, --brace-preserve-inline Preserve line-breaks of braces that appear on the same line [false]
|
||||
-b, --brace-style [collapse|expand|end-expand|none][,preserve-inline] ["collapse"]
|
||||
-B, --break-chained-methods Break chained method calls across subsequent lines
|
||||
-k, --keep-array-indentation Preserve array indentation
|
||||
-x, --unescape-strings Decode printable characters encoded in xNN notation
|
||||
@ -133,7 +132,6 @@ These largely correspond to the underscored option keys for both library interfa
|
||||
"jslint_happy": false,
|
||||
"space_after_anon_function": false,
|
||||
"brace_style": "collapse",
|
||||
"brace_preserve_inline": false,
|
||||
"keep_array_indentation": false,
|
||||
"keep_function_indentation": false,
|
||||
"space_before_conditional": true,
|
||||
|
@ -8,7 +8,6 @@
|
||||
"jslint_happy": false,
|
||||
"space_after_anon_function": false,
|
||||
"brace_style": "collapse",
|
||||
"brace_preserve_inline": false,
|
||||
"keep_array_indentation": false,
|
||||
"keep_function_indentation": false,
|
||||
"space_before_conditional": true,
|
||||
|
@ -61,10 +61,9 @@
|
||||
space_after_anon_function (default false) - should the space before an anonymous function's parens be added, "function()" vs "function ()",
|
||||
NOTE: This option is overriden by jslint_happy (i.e. if jslint_happy is true, space_after_anon_function is true by design)
|
||||
|
||||
brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none"
|
||||
brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "none" | any of the former + ",preserve-inline"
|
||||
put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are.
|
||||
|
||||
brace_preserve_inline (default false) - if open and closed braces appear on the same line, then don't touch them
|
||||
preserve-inline will try to preserve inline blocks of curly braces
|
||||
|
||||
space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
|
||||
|
||||
@ -301,22 +300,26 @@ if (!Object.values) {
|
||||
options = options ? options : {};
|
||||
opt = {};
|
||||
|
||||
// compatibility
|
||||
if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
|
||||
opt.brace_style = options.braces_on_own_line ? "expand" : "collapse";
|
||||
// compatibility, re
|
||||
if (options.brace_style === "expand-strict") { //graceful handling of deprecated option
|
||||
options.brace_style = "expand";
|
||||
}
|
||||
opt.brace_style = options.brace_style ? options.brace_style : (opt.brace_style ? opt.brace_style : "collapse");
|
||||
else if (options.brace_style === "collapse-preserve-inline") { //graceful handling of deprecated option
|
||||
options.brace_style = "collapse,preserve-inline";
|
||||
}
|
||||
else if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
|
||||
options.brace_style = options.braces_on_own_line ? "expand" : "collapse";
|
||||
}
|
||||
else if(!options.brace_style) //Nothing exists to set it
|
||||
{
|
||||
options.brace_style = "collapse";
|
||||
}
|
||||
|
||||
|
||||
var brace_style_split = options.brace_style.split(/[^a-zA-Z0-9_\-]+/);
|
||||
opt.brace_style = brace_style_split[0];
|
||||
opt.brace_preserve_inline = brace_style_split[1] ? brace_style_split[1] : false;
|
||||
|
||||
// graceful handling of deprecated option
|
||||
if (opt.brace_style === "expand-strict") {
|
||||
opt.brace_style = "expand";
|
||||
}
|
||||
if (opt.brace_style === "collapse-preserve-inline") {
|
||||
opt.brace_style = "collapse";
|
||||
opt.brace_preserve_inline = true;
|
||||
}
|
||||
|
||||
opt.brace_preserve_inline = (options.brace_preserve_inline === undefined) ? false : options.brace_preserve_inline;
|
||||
opt.indent_size = options.indent_size ? parseInt(options.indent_size, 10) : 4;
|
||||
opt.indent_char = options.indent_char ? options.indent_char : ' ';
|
||||
opt.eol = options.eol ? options.eol : 'auto';
|
||||
|
@ -40,8 +40,26 @@ var fs = require('fs'),
|
||||
cc = require('config-chain'),
|
||||
beautify = require('../index'),
|
||||
mkdirp = require('mkdirp'),
|
||||
nopt = require('nopt'),
|
||||
path = require('path'),
|
||||
nopt = require('nopt');
|
||||
nopt.typeDefs["brace_style"] = {
|
||||
type : "brace_style",
|
||||
validate : function(data, key, val) {
|
||||
data[key] = val;
|
||||
// TODO: expand-strict is obsolete, now identical to expand. Remove in future version
|
||||
// TODO: collapse-preserve-inline is obselete, now identical to collapse,preserve-inline = true. Remove in future version
|
||||
var validVals = ["collapse", "collapse-preserve-inline", "expand", "end-expand", "expand-strict", "none"];
|
||||
var valSplit = val.split(/[^a-zA-Z0-9_\-]+/);
|
||||
for(var i=0; i<validVals.length; i++)
|
||||
{
|
||||
if(validVals[i] === val || validVals[i] === valSplit[0] && valSplit[1] === "preserve-inline")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
var path = require('path'),
|
||||
editorconfig = require('editorconfig'),
|
||||
knownOpts = {
|
||||
// Beautifier
|
||||
@ -56,10 +74,7 @@ var fs = require('fs'),
|
||||
"space_in_empty_paren": Boolean,
|
||||
"jslint_happy": Boolean,
|
||||
"space_after_anon_function": Boolean,
|
||||
// TODO: expand-strict is obsolete, now identical to expand. Remove in future version
|
||||
// TODO: collapse-preserve-inline is obselete, now identical to collapse + brace_preserve_inline = true. Remove in future version
|
||||
"brace_style": ["collapse", "collapse-preserve-inline", "expand", "end-expand", "expand-strict", "none"],
|
||||
"brace_preserve_inline": Boolean,
|
||||
"brace_style": "brace_style", //See above for validation
|
||||
"break_chained_methods": Boolean,
|
||||
"keep_array_indentation": Boolean,
|
||||
"unescape_strings": Boolean,
|
||||
@ -110,7 +125,6 @@ var fs = require('fs'),
|
||||
"j": ["--jslint_happy"],
|
||||
"a": ["--space_after_anon_function"],
|
||||
"b": ["--brace_style"],
|
||||
"V": ["--brace_preserve_inline"],
|
||||
"B": ["--break_chained_methods"],
|
||||
"k": ["--keep_array_indentation"],
|
||||
"x": ["--unescape_strings"],
|
||||
@ -306,8 +320,7 @@ function usage(err) {
|
||||
msg.push(' -E, --space-in-empty-paren Add a single space inside empty paren, ie. f( )');
|
||||
msg.push(' -j, --jslint-happy Enable jslint-stricter mode');
|
||||
msg.push(' -a, --space-after-anon-function Add a space before an anonymous function\'s parens, ie. function ()');
|
||||
msg.push(' -b, --brace-style [collapse|expand|end-expand|none] ["collapse"]');
|
||||
msg.push(' -V, --brace_preserve_inline Preserve line-breaks of braces that appear on the same line [false]');
|
||||
msg.push(' -b, --brace-style [collapse|expand|end-expand|none][,preserve-inline] [collapse,preserve-inline]');
|
||||
msg.push(' -B, --break-chained-methods Break chained method calls across subsequent lines');
|
||||
msg.push(' -k, --keep-array-indentation Preserve array indentation');
|
||||
msg.push(' -x, --unescape-strings Decode printable characters encoded in xNN notation');
|
||||
|
@ -29,7 +29,6 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
default_opts.jslint_happy = false;
|
||||
default_opts.keep_array_indentation = false;
|
||||
default_opts.brace_style = 'collapse';
|
||||
default_opts.brace_preserve_inline = false;
|
||||
default_opts.operator_position = 'before-newline';
|
||||
|
||||
function reset_options()
|
||||
@ -343,28 +342,28 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
reset_options();
|
||||
//============================================================
|
||||
// Brace style permutations - (ibo = "", iao = "", ibc = "", iac = "", obo = " ", oao = " ", obc = " ", oac = " ")
|
||||
opts.brace_preserve_inline = true;
|
||||
opts.brace_style = 'collapse,preserve-inline';
|
||||
bt('var a ={a: 2};\nvar a ={a: 2};', 'var a = { a: 2 };\nvar a = { a: 2 };');
|
||||
bt('//case 1\nif (a == 1){}\n//case 2\nelse if (a == 2){}', '//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}');
|
||||
bt('if(1){2}else{3}', 'if (1) { 2 } else { 3 }');
|
||||
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', 'try { a(); } catch (b) { c(); } catch (d) {} finally { e(); }');
|
||||
|
||||
// Brace style permutations - (ibo = "\n", iao = "\n", ibc = "\n", iac = "\n", obo = " ", oao = "\n ", obc = "\n", oac = " ")
|
||||
opts.brace_preserve_inline = true;
|
||||
opts.brace_style = 'collapse,preserve-inline';
|
||||
bt('var a =\n{\na: 2\n}\n;\nvar a =\n{\na: 2\n}\n;', 'var a = {\n a: 2\n};\nvar a = {\n a: 2\n};');
|
||||
bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}', '//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}');
|
||||
bt('if(1)\n{\n2\n}\nelse\n{\n3\n}', 'if (1) {\n 2\n} else {\n 3\n}');
|
||||
bt('try\n{\na();\n}\ncatch(b)\n{\nc();\n}\ncatch(d)\n{}\nfinally\n{\ne();\n}', 'try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}');
|
||||
|
||||
// Brace style permutations - (ibo = "", iao = "", ibc = "", iac = "", obo = " ", oao = "\n ", obc = "\n", oac = " ")
|
||||
opts.brace_preserve_inline = false;
|
||||
opts.brace_style = 'collapse';
|
||||
bt('var a ={a: 2};\nvar a ={a: 2};', 'var a = {\n a: 2\n};\nvar a = {\n a: 2\n};');
|
||||
bt('//case 1\nif (a == 1){}\n//case 2\nelse if (a == 2){}', '//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}');
|
||||
bt('if(1){2}else{3}', 'if (1) {\n 2\n} else {\n 3\n}');
|
||||
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', 'try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}');
|
||||
|
||||
// Brace style permutations - (ibo = "\n", iao = "\n", ibc = "\n", iac = "\n", obo = " ", oao = "\n ", obc = "\n", oac = " ")
|
||||
opts.brace_preserve_inline = false;
|
||||
opts.brace_style = 'collapse';
|
||||
bt('var a =\n{\na: 2\n}\n;\nvar a =\n{\na: 2\n}\n;', 'var a = {\n a: 2\n};\nvar a = {\n a: 2\n};');
|
||||
bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}', '//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}');
|
||||
bt('if(1)\n{\n2\n}\nelse\n{\n3\n}', 'if (1) {\n 2\n} else {\n 3\n}');
|
||||
@ -2206,9 +2205,8 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
|
||||
reset_options();
|
||||
//============================================================
|
||||
// brace_preserve_inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
opts.brace_style = 'collapse';
|
||||
opts.brace_preserve_inline = true;
|
||||
// brace_style ,preserve-inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
opts.brace_style = 'collapse,preserve-inline';
|
||||
bt('import { asdf } from "asdf";');
|
||||
bt('function inLine() { console.log("oh em gee"); }');
|
||||
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }');
|
||||
@ -2248,9 +2246,8 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
' var obj = {\n a: function() { console.log("test"); },\n' +
|
||||
' b() {\n console.log("test2");\n }\n };\n}');
|
||||
|
||||
// brace_preserve_inline tests - (obo = "\n", obot = " ", oao = "\n", oaot = " ", obc = "\n", oac = "\n", oact = " ")
|
||||
opts.brace_style = 'expand';
|
||||
opts.brace_preserve_inline = true;
|
||||
// brace_style ,preserve-inline tests - (obo = "\n", obot = " ", oao = "\n", oaot = " ", obc = "\n", oac = "\n", oact = " ")
|
||||
opts.brace_style = 'expand,preserve-inline';
|
||||
bt('import { asdf } from "asdf";');
|
||||
bt('function inLine() { console.log("oh em gee"); }');
|
||||
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }');
|
||||
@ -2290,9 +2287,8 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
' var obj = {\n a: function() { console.log("test"); },\n' +
|
||||
' b()\n {\n console.log("test2");\n }\n };\n}');
|
||||
|
||||
// brace_preserve_inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = "\n", oact = " ")
|
||||
opts.brace_style = 'end-expand';
|
||||
opts.brace_preserve_inline = true;
|
||||
// brace_style ,preserve-inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = "\n", oact = " ")
|
||||
opts.brace_style = 'end-expand,preserve-inline';
|
||||
bt('import { asdf } from "asdf";');
|
||||
bt('function inLine() { console.log("oh em gee"); }');
|
||||
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }');
|
||||
@ -2332,9 +2328,8 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
' var obj = {\n a: function() { console.log("test"); },\n' +
|
||||
' b() {\n console.log("test2");\n }\n };\n}');
|
||||
|
||||
// brace_preserve_inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
opts.brace_style = 'none';
|
||||
opts.brace_preserve_inline = true;
|
||||
// brace_style ,preserve-inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
opts.brace_style = 'none,preserve-inline';
|
||||
bt('import { asdf } from "asdf";');
|
||||
bt('function inLine() { console.log("oh em gee"); }');
|
||||
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }');
|
||||
@ -2374,7 +2369,7 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
' var obj = {\n a: function() { console.log("test"); },\n' +
|
||||
' b() {\n console.log("test2");\n }\n };\n}');
|
||||
|
||||
// brace_preserve_inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
// brace_style ,preserve-inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
opts.brace_style = 'collapse-preserve-inline';
|
||||
bt('import { asdf } from "asdf";');
|
||||
bt('function inLine() { console.log("oh em gee"); }');
|
||||
@ -2419,8 +2414,7 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
reset_options();
|
||||
//============================================================
|
||||
// Destructured and related
|
||||
opts.brace_style = 'collapse';
|
||||
opts.brace_preserve_inline = true;
|
||||
opts.brace_style = 'collapse,preserve-inline';
|
||||
|
||||
// Issue 382 - import destructured
|
||||
bt(
|
||||
|
@ -7,8 +7,7 @@
|
||||
"max_preserve_newlines": 10,
|
||||
"jslint_happy": false,
|
||||
"space_after_anon_function": false,
|
||||
"brace_style": "collapse",
|
||||
"brace_preserve_inline": true,
|
||||
"brace_style": "collapse,preserve-inline",
|
||||
"keep_array_indentation": false,
|
||||
"keep_function_indentation": false,
|
||||
"space_before_conditional": true,
|
||||
|
@ -74,7 +74,6 @@ class BeautifierOptions:
|
||||
self.jslint_happy = False
|
||||
self.space_after_anon_function = False
|
||||
self.brace_style = 'collapse'
|
||||
self.brace_preserve_inline = False
|
||||
self.keep_array_indentation = False
|
||||
self.keep_function_indentation = False
|
||||
self.eval_code = False
|
||||
@ -102,7 +101,6 @@ jslint_happy = %s
|
||||
space_after_anon_function = %s
|
||||
indent_with_tabs = %s
|
||||
brace_style = %s
|
||||
brace_preserve_inline = %s
|
||||
keep_array_indentation = %s
|
||||
eval_code = %s
|
||||
wrap_line_length = %s
|
||||
@ -116,7 +114,6 @@ unescape_strings = %s
|
||||
self.space_after_anon_function,
|
||||
self.indent_with_tabs,
|
||||
self.brace_style,
|
||||
self.brace_preserve_inline,
|
||||
self.keep_array_indentation,
|
||||
self.eval_code,
|
||||
self.wrap_line_length,
|
||||
@ -338,8 +335,7 @@ Output options:
|
||||
-E, --space-in-empty-paren Add a single space inside empty paren, ie. f( )
|
||||
-j, --jslint-happy More jslint-compatible output
|
||||
-a, --space_after_anon_function Add a space before an anonymous function's parens, ie. function ()
|
||||
-b, --brace-style=collapse Brace style (collapse, expand, end-expand)
|
||||
-V, --brace-preserve-inline Preserve line-breaks of braces that appear on the same line
|
||||
-b, --brace-style=collapse Brace style (collapse, expand, end-expand, none)(,preserve-inline)
|
||||
-k, --keep-array-indentation Keep array indentation.
|
||||
-r, --replace Write output in-place, replacing input
|
||||
-o, --outfile=FILE Specify a file to output to (default stdout)
|
||||
@ -450,12 +446,18 @@ class Beautifier:
|
||||
|
||||
#Compat with old form
|
||||
if self.opts.brace_style == 'collapse-preserve-inline':
|
||||
self.opts.brace_style = 'collapse'
|
||||
self.opts.brace_preserve_inline = True
|
||||
|
||||
self.opts.brace_style = 'collapse,preserve-inline'
|
||||
|
||||
split = re.compile("[^a-zA-Z0-9_\-]+").split(self.opts.brace_style)
|
||||
self.opts.brace_style = split[0]
|
||||
self.opts.brace_preserve_inline = (True if bool(split[1] == 'preserve-inline') else None) if len(split) > 1 else False
|
||||
|
||||
if self.opts.brace_style not in ['expand', 'collapse', 'end-expand', 'none']:
|
||||
raise(Exception('opts.brace_style must be "expand", "collapse", "end-expand", or "none".'))
|
||||
|
||||
if self.opts.brace_preserve_inline == None:
|
||||
raise(Exception('opts.brace_style second item must be "preserve-inline"'))
|
||||
|
||||
s = self.blank_state(s)
|
||||
|
||||
input = self.unpack(s, self.opts.eval_code)
|
||||
@ -2154,7 +2156,7 @@ def main():
|
||||
opts, args = getopt.getopt(argv, "s:c:e:o:rdEPjabVkil:xhtfvXnCO:w:",
|
||||
['indent-size=','indent-char=','eol=''outfile=', 'replace', 'disable-preserve-newlines',
|
||||
'space-in-paren', 'space-in-empty-paren', 'jslint-happy', 'space-after-anon-function',
|
||||
'brace-style=', 'brace_preserve_inline', 'keep-array-indentation', 'indent-level=', 'unescape-strings',
|
||||
'brace-style=', 'keep-array-indentation', 'indent-level=', 'unescape-strings',
|
||||
'help', 'usage', 'stdin', 'eval-code', 'indent-with-tabs', 'keep-function-indentation', 'version',
|
||||
'e4x', 'end-with-newline','comma-first','operator-position=','wrap-line-length','editorconfig'])
|
||||
except getopt.GetoptError as ex:
|
||||
@ -2200,8 +2202,6 @@ def main():
|
||||
js_options.eval_code = True
|
||||
elif opt in ('--brace-style', '-b'):
|
||||
js_options.brace_style = arg
|
||||
elif opt in ('--brace-preserve-inline', '-V'):
|
||||
js_options.brace_preserve_inline = True
|
||||
elif opt in ('--unescape-strings', '-x'):
|
||||
js_options.unescape_strings = True
|
||||
elif opt in ('--e4x', '-X'):
|
||||
|
@ -29,7 +29,6 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
default_options.jslint_happy = False
|
||||
default_options.keep_array_indentation = False
|
||||
default_options.brace_style = 'collapse'
|
||||
default_options.brace_preserve_inline = False
|
||||
default_options.indent_level = 0
|
||||
default_options.break_chained_methods = False
|
||||
default_options.eol = '\n'
|
||||
@ -40,7 +39,6 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
default_options.jslint_happy = false
|
||||
default_options.keep_array_indentation = false
|
||||
default_options.brace_style = 'collapse'
|
||||
default_options.brace_preserve_inline = false
|
||||
default_options.operator_position = 'before-newline'
|
||||
|
||||
cls.default_options = default_options
|
||||
@ -179,28 +177,28 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
self.reset_options();
|
||||
#============================================================
|
||||
# Brace style permutations - (ibo = "", iao = "", ibc = "", iac = "", obo = " ", oao = " ", obc = " ", oac = " ")
|
||||
self.options.brace_preserve_inline = true
|
||||
self.options.brace_style = 'collapse,preserve-inline'
|
||||
bt('var a ={a: 2};\nvar a ={a: 2};', 'var a = { a: 2 };\nvar a = { a: 2 };')
|
||||
bt('//case 1\nif (a == 1){}\n//case 2\nelse if (a == 2){}', '//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}')
|
||||
bt('if(1){2}else{3}', 'if (1) { 2 } else { 3 }')
|
||||
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', 'try { a(); } catch (b) { c(); } catch (d) {} finally { e(); }')
|
||||
|
||||
# Brace style permutations - (ibo = "\n", iao = "\n", ibc = "\n", iac = "\n", obo = " ", oao = "\n ", obc = "\n", oac = " ")
|
||||
self.options.brace_preserve_inline = true
|
||||
self.options.brace_style = 'collapse,preserve-inline'
|
||||
bt('var a =\n{\na: 2\n}\n;\nvar a =\n{\na: 2\n}\n;', 'var a = {\n a: 2\n};\nvar a = {\n a: 2\n};')
|
||||
bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}', '//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}')
|
||||
bt('if(1)\n{\n2\n}\nelse\n{\n3\n}', 'if (1) {\n 2\n} else {\n 3\n}')
|
||||
bt('try\n{\na();\n}\ncatch(b)\n{\nc();\n}\ncatch(d)\n{}\nfinally\n{\ne();\n}', 'try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}')
|
||||
|
||||
# Brace style permutations - (ibo = "", iao = "", ibc = "", iac = "", obo = " ", oao = "\n ", obc = "\n", oac = " ")
|
||||
self.options.brace_preserve_inline = false
|
||||
self.options.brace_style = 'collapse'
|
||||
bt('var a ={a: 2};\nvar a ={a: 2};', 'var a = {\n a: 2\n};\nvar a = {\n a: 2\n};')
|
||||
bt('//case 1\nif (a == 1){}\n//case 2\nelse if (a == 2){}', '//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}')
|
||||
bt('if(1){2}else{3}', 'if (1) {\n 2\n} else {\n 3\n}')
|
||||
bt('try{a();}catch(b){c();}catch(d){}finally{e();}', 'try {\n a();\n} catch (b) {\n c();\n} catch (d) {} finally {\n e();\n}')
|
||||
|
||||
# Brace style permutations - (ibo = "\n", iao = "\n", ibc = "\n", iac = "\n", obo = " ", oao = "\n ", obc = "\n", oac = " ")
|
||||
self.options.brace_preserve_inline = false
|
||||
self.options.brace_style = 'collapse'
|
||||
bt('var a =\n{\na: 2\n}\n;\nvar a =\n{\na: 2\n}\n;', 'var a = {\n a: 2\n};\nvar a = {\n a: 2\n};')
|
||||
bt('//case 1\nif (a == 1)\n{}\n//case 2\nelse if (a == 2)\n{}', '//case 1\nif (a == 1) {}\n//case 2\nelse if (a == 2) {}')
|
||||
bt('if(1)\n{\n2\n}\nelse\n{\n3\n}', 'if (1) {\n 2\n} else {\n 3\n}')
|
||||
@ -2042,9 +2040,8 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
|
||||
self.reset_options();
|
||||
#============================================================
|
||||
# brace_preserve_inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
self.options.brace_style = 'collapse'
|
||||
self.options.brace_preserve_inline = true
|
||||
# brace_style ,preserve-inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
self.options.brace_style = 'collapse,preserve-inline'
|
||||
bt('import { asdf } from "asdf";')
|
||||
bt('function inLine() { console.log("oh em gee"); }')
|
||||
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }')
|
||||
@ -2084,9 +2081,8 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
' var obj = {\n a: function() { console.log("test"); },\n' +
|
||||
' b() {\n console.log("test2");\n }\n };\n}')
|
||||
|
||||
# brace_preserve_inline tests - (obo = "\n", obot = " ", oao = "\n", oaot = " ", obc = "\n", oac = "\n", oact = " ")
|
||||
self.options.brace_style = 'expand'
|
||||
self.options.brace_preserve_inline = true
|
||||
# brace_style ,preserve-inline tests - (obo = "\n", obot = " ", oao = "\n", oaot = " ", obc = "\n", oac = "\n", oact = " ")
|
||||
self.options.brace_style = 'expand,preserve-inline'
|
||||
bt('import { asdf } from "asdf";')
|
||||
bt('function inLine() { console.log("oh em gee"); }')
|
||||
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }')
|
||||
@ -2126,9 +2122,8 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
' var obj = {\n a: function() { console.log("test"); },\n' +
|
||||
' b()\n {\n console.log("test2");\n }\n };\n}')
|
||||
|
||||
# brace_preserve_inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = "\n", oact = " ")
|
||||
self.options.brace_style = 'end-expand'
|
||||
self.options.brace_preserve_inline = true
|
||||
# brace_style ,preserve-inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = "\n", oact = " ")
|
||||
self.options.brace_style = 'end-expand,preserve-inline'
|
||||
bt('import { asdf } from "asdf";')
|
||||
bt('function inLine() { console.log("oh em gee"); }')
|
||||
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }')
|
||||
@ -2168,9 +2163,8 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
' var obj = {\n a: function() { console.log("test"); },\n' +
|
||||
' b() {\n console.log("test2");\n }\n };\n}')
|
||||
|
||||
# brace_preserve_inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
self.options.brace_style = 'none'
|
||||
self.options.brace_preserve_inline = true
|
||||
# brace_style ,preserve-inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
self.options.brace_style = 'none,preserve-inline'
|
||||
bt('import { asdf } from "asdf";')
|
||||
bt('function inLine() { console.log("oh em gee"); }')
|
||||
bt('if (cancer) { console.log("Im sorry but you only have so long to live..."); }')
|
||||
@ -2210,7 +2204,7 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
' var obj = {\n a: function() { console.log("test"); },\n' +
|
||||
' b() {\n console.log("test2");\n }\n };\n}')
|
||||
|
||||
# brace_preserve_inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
# brace_style ,preserve-inline tests - (obo = " ", obot = "", oao = "\n", oaot = " ", obc = "\n", oac = " ", oact = "")
|
||||
self.options.brace_style = 'collapse-preserve-inline'
|
||||
bt('import { asdf } from "asdf";')
|
||||
bt('function inLine() { console.log("oh em gee"); }')
|
||||
@ -2255,8 +2249,7 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
self.reset_options();
|
||||
#============================================================
|
||||
# Destructured and related
|
||||
self.options.brace_style = 'collapse'
|
||||
self.options.brace_preserve_inline = true
|
||||
self.options.brace_style = 'collapse,preserve-inline'
|
||||
|
||||
# Issue 382 - import destructured
|
||||
bt(
|
||||
|
@ -26,7 +26,6 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
default_options.jslint_happy = False
|
||||
default_options.keep_array_indentation = False
|
||||
default_options.brace_style = 'collapse'
|
||||
default_options.brace_preserve_inline = False
|
||||
default_options.indent_level = 0
|
||||
default_options.break_chained_methods = False
|
||||
default_options.eol = '\n'
|
||||
|
@ -8,7 +8,6 @@ exports.test_data = {
|
||||
{ name: "jslint_happy", value: "false" },
|
||||
{ name: "keep_array_indentation", value: "false" },
|
||||
{ name: "brace_style", value: "'collapse'" },
|
||||
{ name: "brace_preserve_inline", value: "false" },
|
||||
{ name: "operator_position", value: "'before-newline'" }
|
||||
],
|
||||
groups: [{
|
||||
@ -107,10 +106,10 @@ exports.test_data = {
|
||||
description: "",
|
||||
template: "< >",
|
||||
matrix: [
|
||||
// brace_preserve_inline true - Should preserve if no newlines
|
||||
// brace_style collapse,preserve-inline - Should preserve if no newlines
|
||||
{
|
||||
options: [
|
||||
{ name: "brace_preserve_inline", value: "true" }
|
||||
{ name: "brace_style", value: "'collapse,preserve-inline'" }
|
||||
],
|
||||
ibo: '',
|
||||
iao: '',
|
||||
@ -123,7 +122,7 @@ exports.test_data = {
|
||||
},
|
||||
{
|
||||
options: [
|
||||
{ name: "brace_preserve_inline", value: "true" }
|
||||
{ name: "brace_style", value: "'collapse,preserve-inline'" }
|
||||
],
|
||||
ibo: '\\n',
|
||||
iao: '\\n',
|
||||
@ -135,10 +134,10 @@ exports.test_data = {
|
||||
oac: ' '
|
||||
},
|
||||
|
||||
// brace_preserve_inline false - Shouldn't preserve if no newlines (uses collapse styling)
|
||||
// brace_style collapse - Shouldn't preserve if no newlines (uses collapse styling)
|
||||
{
|
||||
options: [
|
||||
{ name: "brace_preserve_inline", value: "false" }
|
||||
{ name: "brace_style", value: "'collapse'" }
|
||||
],
|
||||
ibo: '',
|
||||
iao: '',
|
||||
@ -151,7 +150,7 @@ exports.test_data = {
|
||||
},
|
||||
{
|
||||
options: [
|
||||
{ name: "brace_preserve_inline", value: "false" }
|
||||
{ name: "brace_style", value: "'collapse'" }
|
||||
],
|
||||
ibo: '\\n',
|
||||
iao: '\\n',
|
||||
@ -1959,16 +1958,14 @@ exports.test_data = {
|
||||
]
|
||||
}, {
|
||||
//Relies on the tab being four spaces as default for the tests
|
||||
name: "brace_preserve_inline tests",
|
||||
description: "brace_preserve_inline with different brace_styles",
|
||||
options: [{ name: "brace_preserve_inline", value: "true" }],
|
||||
name: "brace_style ,preserve-inline tests",
|
||||
description: "brace_style *,preserve-inline varying different brace_styles",
|
||||
template: "< >",
|
||||
matrix: [
|
||||
//test for all options of brace_style
|
||||
{
|
||||
options: [
|
||||
{ name: "brace_style", value: "'collapse'" },
|
||||
{ name: "brace_preserve_inline", value: "true" }
|
||||
{ name: "brace_style", value: "'collapse,preserve-inline'" }
|
||||
],
|
||||
obo: ' ', obot: '',//Output Before Open curlybrace & Tab character
|
||||
oao: '\\n', oaot: ' ', //Output After Open curlybrace & corresponding Tab
|
||||
@ -1977,8 +1974,7 @@ exports.test_data = {
|
||||
},
|
||||
{
|
||||
options: [
|
||||
{ name: "brace_style", value: "'expand'" },
|
||||
{ name: "brace_preserve_inline", value: "true" }
|
||||
{ name: "brace_style", value: "'expand,preserve-inline'" }
|
||||
],
|
||||
obo: '\\n', obot: ' ',
|
||||
oao: '\\n', oaot: ' ',
|
||||
@ -1987,8 +1983,7 @@ exports.test_data = {
|
||||
},
|
||||
{
|
||||
options: [
|
||||
{ name: "brace_style", value: "'end-expand'" },
|
||||
{ name: "brace_preserve_inline", value: "true" }
|
||||
{ name: "brace_style", value: "'end-expand,preserve-inline'" }
|
||||
],
|
||||
obo: ' ', obot: '',
|
||||
oao: '\\n', oaot: ' ',
|
||||
@ -1999,8 +1994,7 @@ exports.test_data = {
|
||||
//None tries not to touch brace style so all the tests in this
|
||||
//matrix were formatted as if they were collapse
|
||||
options: [
|
||||
{ name: "brace_style", value: "'none'" },
|
||||
{ name: "brace_preserve_inline", value: "true" }
|
||||
{ name: "brace_style", value: "'none,preserve-inline'" }
|
||||
],
|
||||
obo: ' ', obot: '',
|
||||
oao: '\\n', oaot: ' ',
|
||||
@ -2101,9 +2095,8 @@ exports.test_data = {
|
||||
name: "Destructured and related",
|
||||
description: "Ensure specific bugs do not recur",
|
||||
options: [
|
||||
{ name: "brace_style", value: "'collapse'" },
|
||||
{ name: "brace_preserve_inline", value: "true" }
|
||||
], //Issue 1052, now brace_preserve_inline instead of brace_style
|
||||
{ name: "brace_style", value: "'collapse,preserve-inline'" }
|
||||
], //Issue 1052, now collapse,preserve-inline instead of collapse-preserve-inline
|
||||
tests: [{
|
||||
comment: "Issue 382 - import destructured ",
|
||||
unchanged: [
|
||||
|
Loading…
x
Reference in New Issue
Block a user