Merge pull request #1450 from bitwiseman/jshint

Jshint
This commit is contained in:
Liam Newman 2018-07-10 18:27:48 -07:00 committed by GitHub
commit 88d162c8a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 114 additions and 109 deletions

View File

@ -1,4 +1,6 @@
dist/**
js/bin/**
js/lib/**
js/test/resources/**
node_modules/**
python/**
@ -6,4 +8,6 @@ target/**
tools/**
test/resources/underscore-min.js
test/resources/underscore.js
web/third-party/**
web/lib/**
web/google-analytics.js

View File

@ -6,5 +6,6 @@
"nocomma": true,
"nonbsp": true,
"nonew": true,
"unused": true
"unused": true,
"esversion": 3
}

View File

@ -1,6 +1,6 @@
PROJECT_ROOT=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
BUILD_DIR=$(PROJECT_ROOT)/build
SCRIPT_DIR=$(PROJECT_ROOT)/tools
BUILD_DIR=$(PROJECT_ROOT)build
SCRIPT_DIR=$(PROJECT_ROOT)tools
SHELL=/bin/bash
PYTHON=$(SCRIPT_DIR)/python
NODE=$(SCRIPT_DIR)/node

View File

@ -216,7 +216,7 @@ function set_file_editorconfig_opts(file, config) {
if (eConfigs.max_line_length === "off") {
config.wrap_line_length = 0;
} else {
config.wrap_line_length = parseInt(eConfigs.max_line_length);
config.wrap_line_length = parseInt(eConfigs.max_line_length, 10);
}
}

View File

@ -100,7 +100,7 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
'video', 'wbr', 'text',
// prexisting - not sure of full effect of removing, leaving in
'acronym', 'address', 'big', 'dt', 'ins', 'strike', 'tt',
'acronym', 'address', 'big', 'dt', 'ins', 'strike', 'tt'
];
unformatted = options.unformatted || [];
content_unformatted = options.content_unformatted || [
@ -189,7 +189,7 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
}
}
return false;
},
}
};
// Return true if the given text is composed entirely of whitespace.

View File

@ -55,7 +55,7 @@ exports.test_data = {
{ fragment: true, input: ' .tabs{}', output: ' .tabs {}{{eof}}' },
{ fragment: true, input: ' \n\n.tabs{}\n\n\n\n', output: ' .tabs {}{{eof}}' },
{ fragment: true, input: '\n', output: '{{eof}}' }
],
]
}, {
name: "Empty braces",
description: "",
@ -65,14 +65,14 @@ exports.test_data = {
{ input: '.tabs { }', output: '.tabs {}' },
// When we support preserving newlines this will need to change
{ input: '.tabs \n{\n \n }', output: '.tabs {}' }
],
]
}, {
name: "",
description: "",
tests: [{
input: '#cboxOverlay {\n\tbackground: url(images/overlay.png) repeat 0 0;\n\topacity: 0.9;\n\tfilter: alpha(opacity = 90);\n}',
output: '#cboxOverlay {\n\tbackground: url(images/overlay.png) repeat 0 0;\n\topacity: 0.9;\n\tfilter: alpha(opacity=90);\n}'
}, ],
}]
}, {
name: "Support simple language specific option inheritance/overriding",
description: "Support simple language specific option inheritance/overriding",
@ -83,7 +83,7 @@ exports.test_data = {
{ name: "js", value: "{ 'indent_size': 3 }" },
{ name: "css", value: "{ 'indent_size': 5 }" }
],
c: ' ',
c: ' '
},
{
options: [
@ -217,18 +217,18 @@ exports.test_data = {
{ name: "preserve_newlines", value: "true" }
],
separator_input: '\\n\\n',
separator_output: '\\n\\n',
separator_output: '\\n\\n'
}, {
options: [
{ name: "preserve_newlines", value: "false" }
],
separator_input: '\\n\\n',
separator_output: '\\n',
separator_output: '\\n'
}],
tests: [
{ input: '.div {}{{separator_input}}.span {}', output: '.div {}{{separator_output}}.span {}' },
{ input: '#bla, #foo{\n\tcolor:black;{{separator_input}}\tfont-size: 12px;\n}', output: '#bla,\n#foo {\n\tcolor: black;{{separator_output}}\tfont-size: 12px;\n}' }
],
]
},
{
name: "Preserve Newlines and newline_between_rules",
@ -247,8 +247,8 @@ exports.test_data = {
{ unchanged: 'html {}\n\n/*this is a comment*/' },
{ unchanged: '.div {\n\ta: 1;\n\n\n\tb: 2;\n}\n\n\n\n.span {\n\ta: 1;\n}' },
{ unchanged: '.div {\n\n\n\ta: 1;\n\n\n\tb: 2;\n}\n\n\n\n.span {\n\ta: 1;\n}' },
{ unchanged: '@media screen {\n\t.div {\n\t\ta: 1;\n\n\n\t\tb: 2;\n\t}\n\n\n\n\t.span {\n\t\ta: 1;\n\t}\n}\n\n.div {}\n\n.span {}' },
],
{ unchanged: '@media screen {\n\t.div {\n\t\ta: 1;\n\n\n\t\tb: 2;\n\t}\n\n\n\n\t.span {\n\t\ta: 1;\n\t}\n}\n\n.div {}\n\n.span {}' }
]
}, {
name: "Preserve Newlines and add tabs",
options: [{ name: "preserve_newlines", value: "true" }],
@ -256,7 +256,7 @@ exports.test_data = {
tests: [{
input: '.tool-tip {\n\tposition: relative;\n\n\t\t\n\t.tool-tip-content {\n\t\t&>* {\n\t\t\tmargin-top: 0;\n\t\t}\n\t\t\n\n\t\t.mixin-box-shadow(.2rem .2rem .5rem rgba(0, 0, 0, .15));\n\t\tpadding: 1rem;\n\t\tposition: absolute;\n\t\tz-index: 10;\n\t}\n}',
output: '.tool-tip {\n\tposition: relative;\n\n\n\t.tool-tip-content {\n\t\t&>* {\n\t\t\tmargin-top: 0;\n\t\t}\n\\n\\n\t\t.mixin-box-shadow(.2rem .2rem .5rem rgba(0, 0, 0, .15));\n\t\tpadding: 1rem;\n\t\tposition: absolute;\n\t\tz-index: 10;\n\t}\n}'
}],
}]
}, {
name: "Newline Between Rules",
description: "",
@ -285,8 +285,8 @@ exports.test_data = {
{ input: '@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo@2x.png);\n\t}\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}\n.div{height:15px;}', output: '@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo@2x.png);\n\t}\n\t@font-face {\n\t\tfont-family: "Bitstream Vera Serif Bold";\n\t\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n\t}\n}{{new_rule}}.div {\n\theight: 15px;\n}' },
{ input: '@font-face {\n\tfont-family: "Bitstream Vera Serif Bold";\n\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n}\n@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo.png);\n\t}\n\t@media screen and (min-device-pixel-ratio: 2) {\n\t\t@font-face {\n\t\t\tfont-family: "Helvetica Neue"\n\t\t}\n\t\t#foo:hover {\n\t\t\tbackground-image: url(foo@2x.png);\n\t\t}\n\t}\n}', output: '@font-face {\n\tfont-family: "Bitstream Vera Serif Bold";\n\tsrc: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");\n}{{new_rule}}@media screen {\n\t#foo:hover {\n\t\tbackground-image: url(foo.png);\n\t}\n\t@media screen and (min-device-pixel-ratio: 2) {\n\t\t@font-face {\n\t\t\tfont-family: "Helvetica Neue"\n\t\t}\n\t\t#foo:hover {\n\t\t\tbackground-image: url(foo@2x.png);\n\t\t}\n\t}\n}' },
{ input: 'a:first-child{color:red;div:first-child{color:black;}}\n.div{height:15px;}', output: 'a:first-child {\n\tcolor: red;\n\tdiv:first-child {\n\t\tcolor: black;\n\t}\n}{{new_rule}}.div {\n\theight: 15px;\n}' },
{ input: 'a:first-child{color:red;div:not(.peq){color:black;}}\n.div{height:15px;}', output: 'a:first-child {\n\tcolor: red;\n\tdiv:not(.peq) {\n\t\tcolor: black;\n\t}\n}{{new_rule}}.div {\n\theight: 15px;\n}' },
],
{ input: 'a:first-child{color:red;div:not(.peq){color:black;}}\n.div{height:15px;}', output: 'a:first-child {\n\tcolor: red;\n\tdiv:not(.peq) {\n\t\tcolor: black;\n\t}\n}{{new_rule}}.div {\n\theight: 15px;\n}' }
]
}, {
name: "Functions braces",
description: "",
@ -299,7 +299,7 @@ exports.test_data = {
{ input: '.tabs( ) { }', output: '.tabs() {}' },
{ input: '.tabs (t, t2) \n{\n key: val(p1 ,p2); \n }', output: '.tabs (t, t2) {\n\tkey: val(p1, p2);\n}' },
{ unchanged: '.box-shadow(@shadow: 0 1px 3px rgba(0, 0, 0, .25)) {\n\t-webkit-box-shadow: @shadow;\n\t-moz-box-shadow: @shadow;\n\tbox-shadow: @shadow;\n}' }
],
]
},
{
name: "Comments",
@ -542,9 +542,8 @@ exports.test_data = {
{
input: 'a:first-child{<i>color:red;<i>div:not(.peq){<i>color:black;<i>}<i>}<i>.div{<i>height:15px;<i>}',
output: 'a:first-child {<o>\tcolor: red;<o>\tdiv:not(.peq) {<o>\t\tcolor: black;<o>\t}<o>}<new_rule>.div {<o>\theight: 15px;<o>}'
},
],
}
]
},
{
name: "Handle LESS property name interpolation",
@ -558,8 +557,8 @@ exports.test_data = {
unchanged: 'tag {\n\tdynamic-@{prop}: none;\n}'
},
{ input: 'tag{dynamic-@{prop}:none;}', output: 'tag {\n\tdynamic-@{prop}: none;\n}' },
{ input: 'tag{ dynamic-@{prop}: none;}', output: 'tag {\n\tdynamic-@{prop}: none;\n}' },
],
{ input: 'tag{ dynamic-@{prop}: none;}', output: 'tag {\n\tdynamic-@{prop}: none;\n}' }
]
}, {
name: "Handle LESS property name interpolation, test #631",
description: "",
@ -569,7 +568,7 @@ exports.test_data = {
input: '.generate-columns(@n,@i:1) when (@i =< @n){.column-@{i}{width:(@i * 100% / @n);}.generate-columns(@n,(@i + 1));}',
output: '.generate-columns(@n, @i: 1) when (@i =< @n) {\n\t.column-@{i} {\n\t\twidth: (@i * 100% / @n);\n\t}\n\t.generate-columns(@n, (@i + 1));\n}'
}
],
]
}, {
name: "Handle LESS function parameters",
description: "",
@ -577,7 +576,7 @@ exports.test_data = {
{ input: 'div{.px2rem(width,12);}', output: 'div {\n\t.px2rem(width, 12);\n}' },
//mixin next to 'background: url("...")' should not add a linebreak after the comma
{ unchanged: 'div {\n\tbackground: url("//test.com/dummy.png");\n\t.px2rem(width, 12);\n}' }
],
]
}, {
name: "Psuedo-classes vs Variables",
description: "",
@ -588,7 +587,7 @@ exports.test_data = {
output: '@page: first {}'
},
{ unchanged: '@page: first {}' }
],
]
}, {
name: "SASS/SCSS",
description: "",
@ -614,11 +613,11 @@ exports.test_data = {
'\t&:not(:first-of-type) {',
'\t\tbackground: red;',
'\t}',
'}',
'}'
]
}
],
]
}, {
name: "Proper handling of colon in selectors",
description: "Space before a colon in a selector must be preserved, as it means pseudoclass/pseudoelement on any child",

View File

@ -72,7 +72,7 @@ exports.test_data = {
{ fragment: true, input: '<div></div>', output: '<div></div>{{eof}}' },
// { fragment: true, input: ' \n\n<div></div>\n\n\n\n', output: ' <div></div>{{eof}}' },
{ fragment: true, input: '\n', output: '{{eof}}' }
],
]
}, {
name: "Custom Extra Liners (empty)",
description: "",
@ -80,14 +80,14 @@ exports.test_data = {
options: [
{ name: "extra_liners", value: "[]" }
]
},
}
],
tests: [{
fragment: true,
input: '<html><head><meta></head><body><div><p>x</p></div></body></html>',
output: '<html>\n<head>\n <meta>\n</head>\n<body>\n <div>\n <p>x</p>\n </div>\n</body>\n</html>'
}],
}]
}, {
name: "Custom Extra Liners (default)",
description: "",
@ -95,14 +95,14 @@ exports.test_data = {
options: [
{ name: "extra_liners", value: "null" }
]
},
}
],
tests: [{
fragment: true,
input: '<html><head></head><body></body></html>',
output: '<html>\n\n<head></head>\n\n<body></body>\n\n</html>'
}],
}]
}, {
name: "Custom Extra Liners (p, string)",
description: "",
@ -110,14 +110,14 @@ exports.test_data = {
options: [
{ name: "extra_liners", value: "'p,/p'" }
]
},
}
],
tests: [{
fragment: true,
input: '<html><head><meta></head><body><div><p>x</p></div></body></html>',
output: '<html>\n<head>\n <meta>\n</head>\n<body>\n <div>\n\n <p>x\n\n </p>\n </div>\n</body>\n</html>'
}],
}]
}, {
name: "Custom Extra Liners (p)",
description: "",
@ -125,14 +125,14 @@ exports.test_data = {
options: [
{ name: "extra_liners", value: "['p', '/p']" }
]
},
}
],
tests: [{
fragment: true,
input: '<html><head><meta></head><body><div><p>x</p></div></body></html>',
output: '<html>\n<head>\n <meta>\n</head>\n<body>\n <div>\n\n <p>x\n\n </p>\n </div>\n</body>\n</html>'
}],
}]
}, {
name: "Tests for script and style types (issue 453, 821)",
description: "Only format recognized script types",
@ -277,9 +277,9 @@ exports.test_data = {
' }',
'</style>'
]
},
}
],
]
}, {
name: "Attribute Wrap alignment with spaces",
description: "Ensure attributes are internally aligned with spaces when the indent_character is set to tab",
@ -426,7 +426,7 @@ exports.test_data = {
indent_over80: '\n '
}, {
options: [
{ name: "wrap_attributes", value: "'aligned-multiple'" },
{ name: "wrap_attributes", value: "'aligned-multiple'" }
],
indent_attr: ' ',
indent_attr_first: ' ',
@ -758,7 +758,7 @@ exports.test_data = {
fragment: true,
unchanged: '<span>{{condition1 && condition2 && condition3 && condition4 < 0 ? "resForTrue" : "resForFalse"}}</span>'
}
],
]
}, {
name: "Handlebars Else tag indenting",
description: "Handlebar Else tags should be newlined after formatted tags",
@ -813,7 +813,7 @@ exports.test_data = {
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n</p>' },
{ fragment: true, unchanged: '<p>\n <a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a><a href="/test/"><img src="test.jpg" /></a>\n</p>' },
{ fragment: true, unchanged: '<p>\n <span>image: <img src="test.jpg" /></span><span>image: <img src="test.jpg" /></span>\n</p>' },
{ fragment: true, unchanged: '<p>\n <strong>image: <img src="test.jpg" /></strong><strong>image: <img src="test.jpg" /></strong>\n</p>' },
{ fragment: true, unchanged: '<p>\n <strong>image: <img src="test.jpg" /></strong><strong>image: <img src="test.jpg" /></strong>\n</p>' }
]
}, {
name: "File starting with comment",
@ -831,7 +831,7 @@ exports.test_data = {
'',
'</html>'
]
}, ]
}]
}, {
name: "Single line comment after closing tag",
description: "Keep single line comments as they are after closing tags",
@ -866,7 +866,7 @@ exports.test_data = {
' <!-- /.row -->',
'</div> <!-- /.col -->'
]
}, ]
}]
}, {
name: "Regression Tests",
description: "Regression Tests",
@ -878,7 +878,7 @@ exports.test_data = {
},
{ fragment: true, unchanged: '<a ">9</a">' },
{ fragment: true, unchanged: '<a href="javascript:;" id="_h_url_paid_pro3" onmousedown="_h_url_click_paid_pro(this);" rel="nofollow" class="pro-title" itemprop="name">WA GlassKote</a>' },
{ fragment: true, unchanged: '<a href="/b/yergey-brewing-a-beer-has-no-name/1745600">"A Beer Has No Name"</a>' },
{ fragment: true, unchanged: '<a href="/b/yergey-brewing-a-beer-has-no-name/1745600">"A Beer Has No Name"</a>' }
]
}, {
name: "Php formatting",
@ -887,7 +887,7 @@ exports.test_data = {
tests: [{
fragment: true,
input: '<h1 class="content-page-header"><?=$view["name"]; ?></h1>',
output: '<h1 class="content-page-header">\n <?=$view["name"]; ?>\n</h1>',
output: '<h1 class="content-page-header">\n <?=$view["name"]; ?>\n</h1>'
}, {
fragment: true,
unchanged: [
@ -974,9 +974,9 @@ exports.test_data = {
'{{h}}{{h}}{{c}}font-size: 12px;',
'{{h}}{{h}}}',
'{{h}}</style>',
'</head>',
'</head>'
]
}, ]
}]
}, {
name: "underscore.js formatting",
description: "underscore.js templates (<% ... %>) treated as comments.",
@ -990,7 +990,7 @@ exports.test_data = {
' </textarea>',
'</div>'
]
}, ]
}]
}, {
name: "Linewrap length",
description: "",
@ -1249,7 +1249,7 @@ exports.test_data = {
'</div>',
'<p>',
' <p>But not me</p>',
'</p>',
'</p>'
]
}, {
fragment: true,
@ -1338,5 +1338,5 @@ exports.test_data = {
}]
}, {
name: "New Test Suite"
}],
}]
};

View File

@ -186,7 +186,7 @@ exports.test_data = {
{ fragment: true, input: ' return .5', output: ' return .5{{eof}}' },
{ fragment: true, input: ' \n\nreturn .5\n\n\n\n', output: ' return .5{{eof}}' },
{ fragment: true, input: '\n', output: '{{eof}}' }
],
]
}, {
name: "Support simple language specific option inheritance/overriding",
description: "Support simple language specific option inheritance/overriding",
@ -219,7 +219,7 @@ exports.test_data = {
'{{j}}test();',
'}'
]
}, ]
}]
}, {
name: "Brace style permutations",
description: "",
@ -279,7 +279,7 @@ exports.test_data = {
oao: '\n ',
obc: '\n',
oac: ' '
},
}
],
tests: [{
input: 'var a =<ibo>{<iao>a: 2<ibc>}<iac>;\nvar a =<ibo>{<iao>a: 2<ibc>}<iac>;',
@ -309,7 +309,7 @@ exports.test_data = {
'catch (d)<obo>{}<oac>' +
'finally<obo>{<oao>e();<obc>}'
}
],
]
}, {
name: "Comma-first option",
description: "Put commas at the start of lines instead of the end",
@ -403,8 +403,8 @@ exports.test_data = {
' }',
');'
]
},
],
}
]
}, {
name: "Unindent chained functions",
description: "Don't indent chained functions if unindent_chained_functions is true",
@ -416,7 +416,7 @@ exports.test_data = {
tests: [{
input: [
'f().f().f()',
' .f().f();',
' .f().f();'
],
output: [
'f().f().f()',
@ -477,40 +477,40 @@ exports.test_data = {
' .f();',
'});'
]
},
}
],
]
}, {
name: "Space in parens tests",
description: "put space inside parens",
matrix: [{
options: [
{ name: "space_in_paren", value: "false" },
{ name: "space_in_empty_paren", value: "false" },
{ name: "space_in_empty_paren", value: "false" }
],
s: '',
e: '',
e: ''
}, {
options: [
{ name: "space_in_paren", value: "false" },
{ name: "space_in_empty_paren", value: "true" },
{ name: "space_in_empty_paren", value: "true" }
],
s: '',
e: '',
e: ''
}, {
options: [
{ name: "space_in_paren", value: "true" },
{ name: "space_in_empty_paren", value: "false" },
{ name: "space_in_empty_paren", value: "false" }
],
s: ' ',
e: '',
e: ''
}, {
options: [
{ name: "space_in_paren", value: "true" },
{ name: "space_in_empty_paren", value: "true" },
{ name: "space_in_empty_paren", value: "true" }
],
s: ' ',
e: ' ',
e: ' '
}],
tests: [{
input: 'if(p) foo(a,b);',
@ -564,9 +564,9 @@ exports.test_data = {
' dest: "www/gui/build"',
' }{{s}}]',
'}'
],
},
],
]
}
]
}, {
name: "operator_position option - ensure no neswlines if preserve_newlines is false",
matrix: [{
@ -589,7 +589,7 @@ exports.test_data = {
unchanged: inputlib.operator_position.sanity
}, {
input: inputlib.operator_position.comprehensive,
output: inputlib.operator_position.sanity,
output: inputlib.operator_position.sanity
}]
}, {
name: "operator_position option - set to 'before-newline' (default value)",
@ -941,7 +941,7 @@ exports.test_data = {
' return <ListItem item={return <tag>{item}</tag>} key={item.id} />;',
' });',
' }',
'});',
'});'
]
},
{
@ -962,7 +962,7 @@ exports.test_data = {
' return <div {someAttr}>Hello {this.props.name}</div>;',
' }',
'});',
'React.render(<HelloMessage name="John" />, mountNode);',
'React.render(<HelloMessage name="John" />, mountNode);'
]
},
{
@ -1127,7 +1127,7 @@ exports.test_data = {
' </Nav>',
' );',
'var qwer = <DropDown> A dropdown list <Menu> <MenuItem>Do Something</MenuItem> <MenuItem>Do Something Fun!</MenuItem> <MenuItem>Do Something Else</MenuItem> </Menu> </DropDown>;',
'render(dropdown);',
'render(dropdown);'
],
output: [
'var content = (',
@ -1143,7 +1143,7 @@ exports.test_data = {
' </Nav>',
');',
'var qwer = <DropDown> A dropdown list <Menu> <MenuItem>Do Something</MenuItem> <MenuItem>Do Something Fun!</MenuItem> <MenuItem>Do Something Else</MenuItem> </Menu> </DropDown>;',
'render(dropdown);',
'render(dropdown);'
]
},
{
@ -1314,12 +1314,12 @@ exports.test_data = {
options: [
{ name: "space_before_conditional", value: "false" }
],
s: '',
s: ''
}, {
options: [
{ name: "space_before_conditional", value: "true" }
],
s: ' ',
s: ' '
}],
tests: [
{ unchanged: 'if{{s}}(a) b()' },
@ -1338,7 +1338,7 @@ exports.test_data = {
output: 'do\n c();\nwhile{{s}}(a);'
},
{ unchanged: 'return [];' },
{ unchanged: 'return ();' },
{ unchanged: 'return ();' }
]
}, {
name: "Beautify preserve formatting",
@ -1646,7 +1646,7 @@ exports.test_data = {
' eleven: 11',
'};'
]
},
}
]
}, {
name: "Comments and tests",
@ -1676,7 +1676,7 @@ exports.test_data = {
' if (i % 3) {',
' console.log(i);',
' }',
'console.log("done");',
'console.log("done");'
]
},
{
@ -1686,7 +1686,7 @@ exports.test_data = {
' k: 0',
'}',
'// ...',
'foo(o)',
'foo(o)'
]
},
{
@ -1695,7 +1695,7 @@ exports.test_data = {
'Meteor.call("foo", bar, function(err, result) {',
' Session.set("baz", result.lorem)',
'})',
'//blah blah',
'//blah blah'
]
},
{
@ -1707,7 +1707,7 @@ exports.test_data = {
'',
'const foo = 5',
'// comment',
'bar()',
'bar()'
]
},
{
@ -1740,9 +1740,9 @@ exports.test_data = {
' // rounding up using integer arithmetic only',
' if (i % modulus)',
' i += modulus - (i % modulus);',
'// behavior of comments should be different for single statements vs block statements/expressions',
'// behavior of comments should be different for single statements vs block statements/expressions'
]
},
}
]
}, {
@ -1843,7 +1843,7 @@ exports.test_data = {
output: 'var o2 = $.extend(a);\n\nfunction{{f}}() {\n alert(x);\n}'
},
{ input: 'function*() {\n yield 1;\n}', output: 'function*{{f}}() {\n yield 1;\n}' },
{ unchanged: 'function* x() {\n yield 1;\n}' },
{ unchanged: 'function* x() {\n yield 1;\n}' }
]
}, {
name: "Regression tests",
@ -2420,7 +2420,7 @@ exports.test_data = {
{ unchanged: 'a |= 2;' },
{ unchanged: 'a **= 2;' },
{ unchanged: 'a <<= 2;' },
{ unchanged: 'a >>= 2;' },
{ unchanged: 'a >>= 2;' }
]
}, {
tests: [{
@ -2534,7 +2534,7 @@ exports.test_data = {
{ input: 'a=.0n', output: 'a = .0 n' },
{ input: 'a=1.0n', output: 'a = 1.0 n' },
{ input: 'a=1e0n', output: 'a = 1e0 n' },
{ input: 'a=0n11a+4', output: 'a = 0n 11 a + 4' },
{ input: 'a=0n11a+4', output: 'a = 0n 11 a + 4' }
]
}, {
//Relies on the tab being four spaces as default for the tests
@ -2797,7 +2797,7 @@ exports.test_data = {
' self.emit(eventName, event, meta);',
' });',
'}',
'["logged_in", "logged_out", "signed_up", "updated_user"].forEach(bindAuthEvent);',
'["logged_in", "logged_out", "signed_up", "updated_user"].forEach(bindAuthEvent);'
]
},
{
@ -3284,9 +3284,9 @@ exports.test_data = {
{ unchanged: 'if (1 + foo() && bar(baz()) / 2) one();\ntwo();\nthree();' },
{ input: 'var a=1,b={bang:2},c=3;', output: 'var a = 1,\n b = {\n bang: 2\n },\n c = 3;' },
{ input: 'var a={bing:1},b=2,c=3;', output: 'var a = {\n bing: 1\n },\n b = 2,\n c = 3;' },
{ input: 'var a={bing:1},b=2,c=3;', output: 'var a = {\n bing: 1\n },\n b = 2,\n c = 3;' }
],
]
}
],
examples: [{

View File

@ -9,8 +9,11 @@ build_js()
echo Building javascript...
cd $PROJECT_DIR
# jshint
$PROJECT_DIR/node_modules/.bin/jshint . || exit 1
# generate lib files
$PROJECT_DIR/node_modules/.bin/webpack
$PROJECT_DIR/node_modules/.bin/webpack || exit 1
mkdir -p ./js/lib/unpackers
cp -r ./js/src/unpackers ./js/lib/
@ -32,9 +35,6 @@ build_js()
cp ./dist/beautifier.js ./js/lib/
cp ./dist/beautifier.min.js ./js/lib/
# jshint
$PROJECT_DIR/node_modules/.bin/jshint 'js/src' 'test' || exit 1
}
build_beautify()
@ -67,9 +67,6 @@ build_beautify()
# html not ready yet
# $PROJECT_DIR/js/bin/html-beautify.js --config $PROJECT_DIR/jsbeautifyrc -r index.html
# jshint again to make sure things haven't changed
$PROJECT_DIR/node_modules/.bin/jshint 'js/src' 'test' || exit 1
build_js
}

View File

@ -1,3 +1,4 @@
/*exported run_tests, read_settings_from_cookie, beautify, submitIssue */
var the = {
use_codemirror: !window.location.href.match(/without-codemirror/),
beautifier_file: window.location.href.match(/debug/) ? 'beautifier' : './beautifier.min',
@ -10,7 +11,7 @@ requirejs.config({
//By default load any module IDs from js/lib
baseUrl: 'js/lib',
paths: {
'beautifier': the.beautifier_file,
'beautifier': the.beautifier_file
}
});
@ -119,7 +120,7 @@ function unpacker_filter(source) {
for (var i = 0; i < unpackers.length; i++) {
if (unpackers[i].detect(source)) {
unpacked = unpackers[i].unpack(source);
if (unpacked != source) {
if (unpacked !== source) {
source = unpacker_filter(unpacked);
}
}
@ -130,7 +131,9 @@ function unpacker_filter(source) {
function beautify() {
if (the.beautify_in_progress) return;
if (the.beautify_in_progress) {
return;
}
store_settings_to_cookie();
@ -147,7 +150,7 @@ function beautify() {
the.language = $('#language option:selected').text();
opts.indent_size = $('#tabsize').val();
opts.indent_char = opts.indent_size == 1 ? '\t' : ' ';
opts.indent_char = opts.indent_size === 1 ? '\t' : ' ';
opts.max_preserve_newlines = $('#max-preserve-newlines').val();
opts.preserve_newlines = opts.max_preserve_newlines !== "-1";
opts.keep_array_indentation = $('#keep-array-indentation').prop('checked');

View File

@ -19,13 +19,13 @@ $(function() {
the.editor.setValue(default_text);
$('.CodeMirror').click(function() {
if (the.editor.getValue() == default_text) {
if (the.editor.getValue() === default_text) {
the.editor.setValue('');
}
});
} else {
$('#source').val(default_text).bind('click focus', function() {
if ($(this).val() == default_text) {
if ($(this).val() === default_text) {
$(this).val('');
}
}).bind('blur', function() {
@ -37,10 +37,11 @@ $(function() {
$(window).bind('keydown', function(e) {
if (e.ctrlKey && e.keyCode == 13) {
if (e.ctrlKey && e.keyCode === 13) {
beautify();
}
})
});
$('.submit').click(beautify);
$('select').change(beautify);
$(':checkbox').change(beautify);