Skip to content

Commit 0e18f39

Browse files
author
Daniel Stockman
committed
Merge branch 'master' into python-cssbeautifier
Conflicts: js/test/beautify-tests.js
2 parents c1b7f1a + da0323d commit 0e18f39

File tree

11 files changed

+101
-8
lines changed

11 files changed

+101
-8
lines changed

js/lib/beautify-html.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
options = options || {};
9595

9696
// backwards compatibility to 1.3.4
97-
if (options.wrap_line_length === undefined && options.max_char !== undefined) {
97+
if ((options.wrap_line_length === undefined || parseInt(options.wrap_line_length, 10) === 0) &&
98+
(options.max_char === undefined || parseInt(options.max_char, 10) === 0)) {
9899
options.wrap_line_length = options.max_char;
99100
}
100101

js/lib/beautify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
// Just continue formatting and the behavior should be logical.
293293
// Also ignore unknown tokens. Again, this should result in better behavior.
294294
if (token_type !== 'TK_INLINE_COMMENT' && token_type !== 'TK_COMMENT' &&
295-
token_type !== 'TK_UNKNOWN') {
295+
token_type !== 'TK_BLOCK_COMMENT' && token_type !== 'TK_UNKNOWN') {
296296
last_last_text = flags.last_text;
297297
last_type = token_type;
298298
flags.last_text = token_text;

js/lib/cli.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ var fs = require('fs'),
116116
// no shorthand for "config"
117117
});
118118

119+
function verifyExists(fullPath) {
120+
return fs.existsSync(fullPath) ? fullPath : null;
121+
}
122+
123+
function findRecursive(dir, fileName) {
124+
var fullPath = path.join(dir, fileName);
125+
var nextDir = path.dirname(dir);
126+
var result = verifyExists(fullPath);
127+
128+
if (!result && (nextDir !== dir)) {
129+
result = findRecursive(nextDir, fileName);
130+
}
131+
132+
return result;
133+
}
134+
135+
function getUserHome() {
136+
return process.env.HOME || process.env.USERPROFILE;
137+
}
138+
119139
// var cli = require('js-beautify/cli'); cli.interpret();
120140
var interpret = exports.interpret = function(argv, slice) {
121141
var parsed = nopt(knownOpts, shortHands, argv, slice);
@@ -132,8 +152,8 @@ var interpret = exports.interpret = function(argv, slice) {
132152
parsed,
133153
cleanOptions(cc.env('jsbeautify_'), knownOpts),
134154
parsed.config,
135-
cc.find('.jsbeautifyrc'),
136-
cc.find(path.join(process.env.HOME || "", ".jsbeautifyrc")),
155+
findRecursive(process.cwd(), '.jsbeautifyrc'),
156+
verifyExists(path.join(getUserHome() || "", ".jsbeautifyrc")),
137157
__dirname + '/../config/defaults.json'
138158
).snapshot;
139159

js/test/beautify-tests.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,37 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
16891689
bth('<div class=\'{{#if thingIs \'value\'}}content{{/if}}\'></div>');
16901690

16911691

1692+
opts.wrap_line_length = 0;
1693+
//...---------1---------2---------3---------4---------5---------6---------7
1694+
//...1234567890123456789012345678901234567890123456789012345678901234567890
1695+
bth('<div>Some test text that should wrap_inside_this section here.</div>',
1696+
/* expected */
1697+
'<div>Some test text that should wrap_inside_this section here.</div>');
1698+
1699+
opts.wrap_line_length = "0";
1700+
//...---------1---------2---------3---------4---------5---------6---------7
1701+
//...1234567890123456789012345678901234567890123456789012345678901234567890
1702+
bth('<div>Some test text that should wrap_inside_this section here.</div>',
1703+
/* expected */
1704+
'<div>Some test text that should wrap_inside_this section here.</div>');
1705+
1706+
//BUGBUG: This should wrap before 40 not after.
1707+
opts.wrap_line_length = 40;
1708+
//...---------1---------2---------3---------4---------5---------6---------7
1709+
//...1234567890123456789012345678901234567890123456789012345678901234567890
1710+
bth('<div>Some test text that should wrap_inside_this section here.</div>',
1711+
/* expected */
1712+
'<div>Some test text that should wrap_inside_this\n' +
1713+
' section here.</div>');
1714+
1715+
opts.wrap_line_length = "40";
1716+
//...---------1---------2---------3---------4---------5---------6---------7
1717+
//...1234567890123456789012345678901234567890123456789012345678901234567890
1718+
bth('<div>Some test text that should wrap_inside_this section here.</div>',
1719+
/* expected */
1720+
'<div>Some test text that should wrap_inside_this\n' +
1721+
' section here.</div>');
1722+
16921723
// css beautifier
16931724
opts.indent_size = 1;
16941725
opts.indent_char = '\t';

js/test/resources/example1.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function indentMe() {
2+
"no, me!";
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"indent_size": 11,
3+
"indent_char": " ",
4+
"indent_level": 0,
5+
"indent_with_tabs": false
6+
}

js/test/resources/indent11chars/subDir1/subDir2/empty.txt

Whitespace-only changes.

js/test/shell-smoke-test.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,37 @@ test_cli_js_beautify()
8888
exit 1
8989
}
9090

91+
export HOME=
92+
export USERPROFILE=
93+
$CLI_SCRIPT -o /tmp/js-beautify-mkdir/example1-default.js $SCRIPT_DIR/resources/example1.js
94+
95+
cd $SCRIPT_DIR/resources/indent11chars
96+
$CLI_SCRIPT /tmp/js-beautify-mkdir/example1-default.js | diff -q /tmp/js-beautify-mkdir/example1-default.js - && {
97+
echo "js-beautify output for /tmp/js-beautify-mkdir/example1-default.js was expected to be different based on CWD settings."
98+
exit 1
99+
}
100+
cd $SCRIPT_DIR/resources/indent11chars/subDir1/subDir2
101+
$CLI_SCRIPT /tmp/js-beautify-mkdir/example1-default.js | diff -q /tmp/js-beautify-mkdir/example1-default.js - && {
102+
echo "js-beautify output for /tmp/js-beautify-mkdir/example1-default.js was expected to be different based on CWD parent folder settings."
103+
exit 1
104+
}
105+
cd $SCRIPT_DIR
106+
107+
108+
export HOME=$SCRIPT_DIR/resources/indent11chars
109+
$CLI_SCRIPT /tmp/js-beautify-mkdir/example1-default.js | diff -q /tmp/js-beautify-mkdir/example1-default.js - && {
110+
echo "js-beautify output for /tmp/js-beautify-mkdir/example1-default.js was expected to be different based on HOME settings."
111+
exit 1
112+
}
113+
114+
export HOME=
115+
export USERPROFILE=$SCRIPT_DIR/resources/indent11chars
116+
$CLI_SCRIPT /tmp/js-beautify-mkdir/example1-default.js | diff -q /tmp/js-beautify-mkdir/example1-default.js - && {
117+
echo "js-beautify output for /tmp/js-beautify-mkdir/example1-default.js was expected to be different based on USERPROFILE settings."
118+
exit 1
119+
}
120+
121+
91122
}
92123

93124
test_cli_common css-beautify

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-beautify",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "jsbeautifier.org for node",
55
"main": "js/index.js",
66
"preferGlobal": true,
@@ -47,6 +47,7 @@
4747
"nopt": "~2.1.1"
4848
},
4949
"devDependencies": {
50-
"jshint": "1.1.0"
50+
"jshint": "1.1.0",
51+
"node-static": "~0.7.1"
5152
}
5253
}

python/jsbeautifier/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def beautify(self, s, opts = None ):
329329

330330
# The cleanest handling of inline comments is to treat them as though they aren't there.
331331
# Just continue formatting and the behavior should be logical.
332-
if token_type != 'TK_INLINE_COMMENT' and token_type != 'TK_COMMENT' and token_type != 'TK_UNKNOWN':
332+
if token_type != 'TK_INLINE_COMMENT' and token_type != 'TK_COMMENT' and token_type != 'TK_BLOCK_COMMENT' and token_type != 'TK_UNKNOWN':
333333
self.last_last_text = self.flags.last_text
334334
self.last_type = token_type
335335
self.flags.last_text = self.token_text

0 commit comments

Comments
 (0)