Skip to content

Commit d9bf076

Browse files
authored
Merge branch 'main' into fix/js-object-comment-only-closing-brace
2 parents 8993a82 + 1b6d627 commit d9bf076

35 files changed

Lines changed: 852 additions & 592 deletions

.github/workflows/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
os: [ ubuntu, windows, macos ]
20-
python-version: ['3.10', 3.11]
20+
python-version: [3.11, 3.12, 3.14]
2121
include:
22-
- python-version: '3.10'
23-
node-version: 16
24-
- python-version: 3.11
25-
node-version: 18
26-
- python-version: 3.11
27-
node-version: 20
22+
- python-version: 3.11
23+
node-version: 22
24+
- python-version: 3.12
25+
node-version: 24
26+
- python-version: 3.14
27+
node-version: 26
2828
steps:
2929
- uses: actions/checkout@v6
3030
- name: Set up Node ${{ matrix.node-version }}

.github/workflows/milestone-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ jobs:
1818
- name: Set up Node
1919
uses: actions/setup-node@v6
2020
with:
21-
node-version: 18
21+
node-version: 26
2222
registry-url: https://registry.npmjs.org/
2323
- name: Set up Python
2424
uses: actions/setup-python@v6
2525
with:
26-
python-version: 3.11
26+
python-version: 3.14
2727
- name: Set git user
2828
run: |
2929
git config --global user.email "github-action@users.noreply.github.com"

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v2.0.1
4+
* Removed all usage of six and dropped support for Python 2. ([#2374](https://github.com/beautifier/js-beautify/pull/2374))
5+
* Move minimum version to Nodejs v22.x ([#2363](https://github.com/beautifier/js-beautify/pull/2363))
6+
* Bump nopt from 7.2.1 to 8.1.0 ([#2361](https://github.com/beautifier/js-beautify/pull/2361))
7+
* Fix minor crash for certain oddly formed *.js files ([#2128](https://github.com/beautifier/js-beautify/pull/2128))
8+
39
## v1.15.4
410
* Downgrade nopt to v7.x to maintain Node.js v14 compatibility ([#2358](https://github.com/beautifier/js-beautify/issues/2358))
511

CONTRIBUTING.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,32 @@ To publish a Beta or RC (Release Candidate), add `-beta1` or `-rc1` to the end o
137137

138138

139139

140+
## Version Numbering Policy
141+
142+
This project follows semantic versioning for API compatibility, with additional guidance for formatting changes.
143+
144+
### What each version number means
145+
146+
* Major (`x.0.0`): API compatibility changes. We reserve major versions for intentional API-incompatible changes.
147+
* Minor (`x.y.0`): Significant formatting fixes, behavior improvements, or new features/options that may affect output.
148+
* Patch (`x.y.z`): Small, low-risk fixes that should not cause side effects.
149+
150+
### Output compatibility expectations
151+
152+
Formatting output for the same input may change in minor and patch releases.
153+
For this project, output compatibility is not equivalent to API compatibility:
154+
155+
* API compatibility is represented by major versions.
156+
* Formatting correctness and behavior improvements are delivered in minor/patch releases based on scope and risk.
157+
158+
### Rules for introducing formatting behavior changes
159+
160+
* Fixes for strictly incorrect formatting should be enabled by default.
161+
* New formatting features should be introduced as options and must default to off, so valid input formatting does not change unexpectedly.
162+
* We avoid unnecessary output churn and treat invalid input handling as best-effort.
163+
164+
### Guidance for consumers
165+
166+
If your workflows are sensitive to output differences, pin exact versions or use conservative ranges.
167+
Using broad ranges (for example, `^x.y.z`) may pull in output-affecting updates by design.
168+

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PROJECT_ROOT=$(subst \,/,$(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
22
BUILD_DIR=$(PROJECT_ROOT)build
33
SCRIPT_DIR=$(PROJECT_ROOT)tools
44
SHELL=/bin/bash
5-
PYTHON=$(SCRIPT_DIR)/python
5+
PYTHON=$(SCRIPT_DIR)/python-dev python
66
NODE=$(SCRIPT_DIR)/node
77
NPM=$(SCRIPT_DIR)/npm
88

@@ -146,7 +146,8 @@ $(BUILD_DIR)/virtualenv: | $(BUILD_DIR)
146146
virtualenv build/python-rel
147147
$(SCRIPT_DIR)/python-dev python -m pip install --upgrade pip || exit 0
148148
$(SCRIPT_DIR)/python-rel python -m pip install --upgrade pip || exit 0
149-
$(SCRIPT_DIR)/python-dev3 pip install black
149+
$(SCRIPT_DIR)/python-dev pip install setuptools black
150+
$(SCRIPT_DIR)/python-rel pip install setuptools
150151
@touch $(BUILD_DIR)/virtualenv
151152

152153

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries
5858

5959
To pull the latest version from one of these services include one set of the script tags below in your document:
6060
```html
61-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify.js"></script>
62-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify-css.js"></script>
63-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify-html.js"></script>
61+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/2.0.1/beautify.js"></script>
62+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/2.0.1/beautify-css.js"></script>
63+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/2.0.1/beautify-html.js"></script>
6464

65-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify.min.js"></script>
66-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify-css.min.js"></script>
67-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify-html.min.js"></script>
65+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/2.0.1/beautify.min.js"></script>
66+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/2.0.1/beautify-css.min.js"></script>
67+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/2.0.1/beautify-html.min.js"></script>
6868
```
6969

7070
Example usage of a JS tag in html:
@@ -76,7 +76,7 @@ Example usage of a JS tag in html:
7676

7777
. . .
7878

79-
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify.min.js"></script>
79+
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/2.0.1/beautify.min.js"></script>
8080
<script src="script.js"></script>
8181
</body>
8282
</html>
@@ -97,6 +97,7 @@ Unlike the JavaScript version, the Python version can only reformat JavaScript.
9797
```bash
9898
$ pip install cssbeautifier
9999
```
100+
Note: This project no longer supports Python 2.
100101

101102
# Usage
102103
You can beautify JavaScript using JS Beautifier in your web browser, or on the command-line using Node.js or Python.
@@ -445,4 +446,4 @@ Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, D
445446
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
446447
Mathias Bynens, Vittorio Gambaletta and others.
447448
448-
(README.md: js-beautify@1.15.4)
449+
(README.md: js-beautify@2.0.1)

index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ <h2>Options</h2>
148148
</div>
149149
</div>
150150

151+
<div>
152+
<p style="margin:6px 0 0 0">HTML attribute wrapping:</p>
153+
<select id="wrap-attributes">
154+
<option value="auto">Wrap when line is too long</option>
155+
<option value="force">Wrap each attribute</option>
156+
<option value="force-aligned">Wrap and align attributes</option>
157+
<option value="force-expand-multiline">Always wrap multiline</option>
158+
<option value="aligned-multiple">Align multiple attributes</option>
159+
<option value="preserve">Preserve wrapping</option>
160+
<option value="preserve-aligned">Preserve and align</option>
161+
</select>
162+
</div>
163+
151164
<div class="options-checkboxes">
152165
<input class="checkbox" type="checkbox" id="end-with-newline">
153166
<label for="end-with-newline">End script and style with newline?</label>

js/src/html/beautifier.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ var get_custom_beautifier_name = function(tag_check, raw_token) {
166166
// For those without a type attribute use default;
167167
if (typeAttribute.search('text/css') > -1) {
168168
result = 'css';
169-
} else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
169+
} else if (typeAttribute.search(/module|importmap|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
170170
result = 'javascript';
171171
} else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
172172
result = 'html';

js/src/javascript/beautifier.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,16 @@ function split_linebreaks(s) {
104104
//return s.split(/\x0d\x0a|\x0a/);
105105

106106
s = s.replace(acorn.allLineBreaks, '\n');
107-
var out = [],
108-
idx = s.indexOf("\n");
107+
var out = [];
108+
var start = 0;
109+
var idx = s.indexOf("\n", start);
109110
while (idx !== -1) {
110-
out.push(s.substring(0, idx));
111-
s = s.substring(idx + 1);
112-
idx = s.indexOf("\n");
111+
out.push(s.substring(start, idx));
112+
start = idx + 1;
113+
idx = s.indexOf("\n", start);
113114
}
114-
if (s.length) {
115-
out.push(s);
115+
if (start < s.length) {
116+
out.push(s.substring(start));
116117
}
117118
return out;
118119
}

0 commit comments

Comments
 (0)