Merge branch 'master' into master

This commit is contained in:
Liam Newman 2018-03-01 16:09:42 -08:00 committed by GitHub
commit a475e310f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 127 additions and 52 deletions

View File

@ -1,4 +1,15 @@
# Changelog
## v1.7.5
### Description
### Closed Issues
* Strict mode: js_source_text is not defined [CSS] ([#1286](https://github.com/beautify-web/js-beautify/issues/1286))
* Made brace_style option more inclusive ([#1277](https://github.com/beautify-web/js-beautify/pull/1277))
* White space before"!important" tag missing in CSS beautify ([#1273](https://github.com/beautify-web/js-beautify/issues/1273))
## v1.7.4
### Description
@ -32,6 +43,7 @@ Lessons learned:
### Closed Issues
* undindent-chained-methods option. Resolves #482 ([#1240](https://github.com/beautify-web/js-beautify/pull/1240))
* Add test and tools folder to npmignore ([#1239](https://github.com/beautify-web/js-beautify/issues/1239))
* incorrect new-line insertion after "yield" ([#1206](https://github.com/beautify-web/js-beautify/issues/1206))
* Do not modify built-in objects ([#1205](https://github.com/beautify-web/js-beautify/issues/1205))

View File

@ -25,17 +25,17 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries
To pull from one of these services include one set of the script tags below in your document:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.4/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.4/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.4/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.5/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.5/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.5/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.4/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.4/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.4/beautify-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.5/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.5/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.7.5/beautify-html.min.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.7.4/js/lib/beautify.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.7.4/js/lib/beautify-css.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.7.4/js/lib/beautify-html.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.7.5/js/lib/beautify.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.7.5/js/lib/beautify-css.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.7.5/js/lib/beautify-html.js"></script>
```
Disclaimer: These are free services, so there are [no uptime or support guarantees](https://github.com/rgrove/rawgit/wiki/Frequently-Asked-Questions#i-need-guaranteed-100-uptime-should-i-use-cdnrawgitcom).
@ -65,8 +65,11 @@ res = jsbeautifier.beautify_file('some_file.js')
``` python
opts = jsbeautifier.default_options()
opts.indent_size = 2
opts.space_in_empty_paren = True
res = jsbeautifier.beautify('some javascript', opts)
```
The configuration option names are the same as the CLI names but with underscores instead of dashes. The example above would be set on the command-line as `--indent-size 2 --space-in-empty-paren`.
## JavaScript
@ -83,18 +86,23 @@ You can also use `js-beautify` as a `node` library (install locally, the `npm` d
$ npm install js-beautify
```
Import and call the approriate beautifier method for javascript (js), css, or html. All three method signatures are `beautify(code, options)`. `code` is a the string of code to be beautified. options is an object with the settings you would like used to beautify the code.
The configuration option names are the same as the CLI names but with underscores instead of dashes. For example, `--indent-size 2 --space-in-empty-paren` would be `{ indent_size: 2, space_in_empty_paren: true }`.
```js
var beautify = require('js-beautify').js_beautify,
var beautify = require('js-beautify').js,
fs = require('fs');
fs.readFile('foo.js', 'utf8', function (err, data) {
if (err) {
throw err;
}
console.log(beautify(data, { indent_size: 2 }));
console.log(beautify(data, { indent_size: 2, space_in_empty_paren: true }));
});
```
## Options
These are the command-line flags for both Python and JS scripts:
@ -322,4 +330,4 @@ Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, D
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
Mathias Bynens, Vittorio Gambaletta and others.
(README.md: js-beautify@1.7.4)
(README.md: js-beautify@1.7.5)

View File

@ -318,8 +318,8 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
// Doctype and xml elements
'!doctype', '?xml',
// ?php tag
'?php',
// ?php and ?= tags
'?php', '?=',
// other tags that were in this list, keeping just in case
'basefont', 'isindex'
],
@ -647,10 +647,8 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
// must check for space first otherwise the tag could have the first attribute included, and
// then not un-indent correctly
if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
tag_index = tag_complete.indexOf(' ');
} else if (tag_complete.indexOf('\n') !== -1) { //if there's a line break, thats where the tag name ends
tag_index = tag_complete.indexOf('\n');
if (tag_complete.search(/\s/) !== -1) { //if there's whitespace, thats where the tag name ends
tag_index = tag_complete.search(/\s/);
} else if (tag_complete.charAt(0) === '{') {
tag_index = tag_complete.indexOf('}');
} else { //otherwise go with the tag ending
@ -915,6 +913,11 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
//unformatted?
var next_tag = this.get_tag(true /* peek. */ );
next_tag = next_tag || '';
if (typeof next_tag !== 'string') {
next_tag = next_tag[0];
}
// test next_tag to see if it is just html tag (no external content)
var tag = (next_tag || "").match(/^\s*<\s*\/?([a-z]*)\s*[^>]*>\s*$/);

View File

@ -170,8 +170,8 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
// Doctype and xml elements
'!doctype', '?xml',
// ?php tag
'?php',
// ?php and ?= tags
'?php', '?=',
// other tags that were in this list, keeping just in case
'basefont', 'isindex'
],
@ -499,10 +499,8 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
// must check for space first otherwise the tag could have the first attribute included, and
// then not un-indent correctly
if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
tag_index = tag_complete.indexOf(' ');
} else if (tag_complete.indexOf('\n') !== -1) { //if there's a line break, thats where the tag name ends
tag_index = tag_complete.indexOf('\n');
if (tag_complete.search(/\s/) !== -1) { //if there's whitespace, thats where the tag name ends
tag_index = tag_complete.search(/\s/);
} else if (tag_complete.charAt(0) === '{') {
tag_index = tag_complete.indexOf('}');
} else { //otherwise go with the tag ending
@ -767,6 +765,11 @@ function Beautifier(html_source, options, js_beautify, css_beautify) {
//unformatted?
var next_tag = this.get_tag(true /* peek. */ );
next_tag = next_tag || '';
if (typeof next_tag !== 'string') {
next_tag = next_tag[0];
}
// test next_tag to see if it is just html tag (no external content)
var tag = (next_tag || "").match(/^\s*<\s*\/?([a-z]*)\s*[^>]*>\s*$/);

View File

@ -2646,6 +2646,17 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
'</html>');
//============================================================
// Regression Tests
reset_options();
// #1202
test_fragment('<a class="js-open-move-from-header" href="#">5A - IN-SPRINT TESTING</a>');
test_fragment('<a ">9</a">');
test_fragment('<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>');
test_fragment('<a href="/b/yergey-brewing-a-beer-has-no-name/1745600">"A Beer Has No Name"</a>');
//============================================================
// Php formatting
reset_options();
@ -2673,6 +2684,15 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
'<body></body>\n' +
'\n' +
'</html>');
test_fragment(
'<?= "A" ?>\n' +
'<?= "B" ?>\n' +
'<?= "C" ?>');
test_fragment(
'<?php\n' +
'echo "A";\n' +
'?>\n' +
'<span>Test</span>');
//============================================================

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "js-beautify",
"version": "1.7.4",
"version": "1.7.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "js-beautify",
"version": "1.7.4",
"version": "1.7.5",
"description": "jsbeautifier.org for node",
"main": "js/index.js",
"bin": {

View File

@ -9,7 +9,7 @@ import errno
import copy
from jsbeautifier.__version__ import __version__
from jsbeautifier.javascript.options import BeautifierOptions
from jsbeautifier.javascript.beautifier import Beautifier
from jsbeautifier.javascript.beautifier import Beautifier, sanitizeOperatorPosition
#
# The MIT License (MIT)
@ -117,7 +117,7 @@ def beautify_file(file_name, opts = default_options() ):
stream = sys.stdin
input_string = ''.join(stream.readlines())
except Exception as ex:
print("Must pipe input or define at least one file.", file=sys.stderr)
print("Must pipe input or define at least one file.\n", file=sys.stderr)
usage(sys.stderr)
raise Exception()
else:
@ -136,7 +136,6 @@ Javascript beautifier (http://jsbeautifier.org/)
Usage: jsbeautifier.py [options] <infile>
<infile> can be "-", which means stdin.
<outfile> defaults to stdout
Input options:
@ -153,7 +152,7 @@ Output options:
-P, --space-in-paren Add padding spaces within paren, ie. f( a, b )
-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 ()
-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, none)(,preserve-inline)
-k, --keep-array-indentation Keep array indentation.
-r, --replace Write output in-place, replacing input
@ -161,9 +160,11 @@ Output options:
-f, --keep-function-indentation Do not re-indent function bodies defined in var lines.
-x, --unescape-strings Decode printable chars encoded in \\xNN notation.
-X, --e4x Pass E4X xml literals through untouched
-w, --wrap-line-length Attempt to wrap line when it exceeds this length.
-C, --comma-first Put commas at the beginning of new line instead of end.
-O, --operator-position=STRING Set operator position (before-newline, after-newline, preserve-newline)
-w, --wrap-line-length Attempt to wrap line when it exceeds this length.
NOTE: Line continues until next wrap point is found.
-n, --end_with_newline End output with newline
-n, --end-with-newline End output with newline
--editorconfig Enable setting configuration from EditorConfig
Rarely needed options:
@ -175,7 +176,7 @@ Rarely needed options:
-l, --indent-level=NUMBER Initial indentation level. (default 0).
-h, --help, --usage Prints this help statement.
-v, --version Show the version
-v, --version Show the version
""", file=stream)
if stream == sys.stderr:
@ -210,7 +211,7 @@ def main():
try:
opts, args = getopt.getopt(argv, "s:c:e:o:rdEPjabkil:xhtfvXnCO:w:",
['indent-size=','indent-char=','eol=''outfile=', 'replace', 'disable-preserve-newlines',
['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=', 'keep-array-indentation', 'indent-level=', 'unescape-strings',
'help', 'usage', 'stdin', 'eval-code', 'indent-with-tabs', 'keep-function-indentation', 'version',

View File

@ -1 +1 @@
__version__ = '1.7.4'
__version__ = '1.7.5'

View File

@ -121,15 +121,13 @@ test_cli_js_beautify()
$CLI_SCRIPT -o $TEST_TEMP/js-beautify-rn.js -e '\r\n' $TEST_TEMP/js-beautify-n.js
# ensure eol processed correctly
# Issue #987 - strange error when processing --eol
# uncomment to reproduce
# $CLI_SCRIPT -o $TEST_TEMP/js-beautify-n-dash.js --indent-size 2 --eol '\n' $TEST_TEMP/js-beautify-n.js
# $CLI_SCRIPT -o $TEST_TEMP/js-beautify-rn-dash.js --indent-size 2 --eol '\r\n' $TEST_TEMP/js-beautify-n.js
# diff -q $TEST_TEMP/js-beautify-n-dash.js $TEST_TEMP/js-beautify-rn-dash.js && {
# diff $TEST_TEMP/js-beautify-n-dash.js $TEST_TEMP/js-beautify-rn-dash.js | cat -t -e
# echo "js-beautify output for $TEST_TEMP/js-beautify-n-dash.js and $TEST_TEMP/js-beautify-rn-dash.js was expected to be different."
# cleanup 1
# }
$CLI_SCRIPT -o $TEST_TEMP/js-beautify-n-dash.js --indent-size 2 --eol '\n' $TEST_TEMP/js-beautify-n.js
$CLI_SCRIPT -o $TEST_TEMP/js-beautify-rn-dash.js --indent-size 2 --eol '\r\n' $TEST_TEMP/js-beautify-n.js
diff -q $TEST_TEMP/js-beautify-n-dash.js $TEST_TEMP/js-beautify-rn-dash.js && {
diff $TEST_TEMP/js-beautify-n-dash.js $TEST_TEMP/js-beautify-rn-dash.js | cat -t -e
echo "js-beautify output for $TEST_TEMP/js-beautify-n-dash.js and $TEST_TEMP/js-beautify-rn-dash.js was expected to be different."
cleanup 1
}
diff -q $TEST_TEMP/js-beautify-n.js $TEST_TEMP/js-beautify-rn.js && {
diff $TEST_TEMP/js-beautify-n.js $TEST_TEMP/js-beautify-rn.js | cat -t -e

View File

@ -793,9 +793,22 @@ exports.test_data = {
'</html>'
]
}, ]
}, {
name: "Regression Tests",
description: "Regression Tests",
options: [],
tests: [{
comment: '#1202',
fragment: true,
unchanged: '<a class="js-open-move-from-header" href="#">5A - IN-SPRINT TESTING</a>'
},
{ 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>' },
]
}, {
name: "Php formatting",
description: "Php (<?php ... ?>) treated as comments.",
description: "Php (<?php ... ?> and <?= ... ?>) treated as comments.",
options: [],
tests: [{
fragment: true,
@ -825,6 +838,21 @@ exports.test_data = {
'',
'</html>'
]
}, {
fragment: true,
unchanged: [
'<?= "A" ?>',
'<?= "B" ?>',
'<?= "C" ?>'
]
}, {
fragment: true,
unchanged: [
'<?php',
'echo "A";',
'?>',
'<span>Test</span>'
]
}]
}, {
name: "Support simple language specific option inheritance/overriding",

View File

@ -36,8 +36,8 @@ build_all()
build_py()
{
echo Building python module...
pip install -e ./python || exit 1
echo Building python module...
/usr/bin/env python -m pip install -e ./python || exit 1
}
build_js()

View File

@ -15,20 +15,22 @@ main()
exit 1
fi
jq --version || {
local JQ
JQ=$(command -v jq) || {
echo "Required tool 'jq' missing. Failed."
exit 1
}
gsort --version || {
echo "Required tool 'gsort' missing. Failed."
local GSORT
GSORT=$(command -v gsort || command -v sort) || {
echo "Required tool 'GNU sort' missing. Failed."
exit 1
}
IFS=$'\n'
echo "# Changelog" > CHANGELOG.md
for m in $(curl -s "https://api.github.com/repos/$1/milestones?state=closed" | jq -c '.[] | [.title, .number, .description]' | gsort -r -V); do
for m in $(curl -s "https://api.github.com/repos/$1/milestones?state=closed" | "$JQ" -c '.[] | [.title, .number, .description]' | "$GSORT" -r -V); do
mid=$(echo $m | sed 's/\[".*",\(.*\),".*"\]/\1/')
title=$(echo $m | sed 's/\["\(.*\)",.*,".*"\]/\1/')
@ -39,7 +41,7 @@ main()
echo $m | sed 's/\[".*",.*,"\(.*\)"\]/\1/' | sed -e 's/\\"/"/g' | sed -e 's/\\r\\n/\\n/g' | sed -e 's/\\n/\'$'\n/g' >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo '### Closed Issues' >> CHANGELOG.md
for i in $(curl -s "https://api.github.com/repos/$1/issues?milestone=$mid&state=closed" | jq -c '.[] | [.html_url, .number, .title]'); do
for i in $(curl -s "https://api.github.com/repos/$1/issues?milestone=$mid&state=closed" | "$JQ" -c '.[] | [.html_url, .number, .title]'); do
echo $i | sed 's/\["\(.*\)",\(.*\),\"\(.*\)\"\]/* \3 ([#\2](\1))/' | sed 's/\\"/"/g' >> CHANGELOG.md
done
echo "" >> CHANGELOG.md