Skip to content

Commit dfe7abf

Browse files
committed
build: use biome as formatter
1 parent f28ccd3 commit dfe7abf

File tree

16 files changed

+344
-76
lines changed

16 files changed

+344
-76
lines changed

.eslintrc.js

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ module.exports = {
133133
// https://eslint.org/docs/rules/
134134
'accessor-pairs': 'error',
135135
'array-callback-return': 'error',
136-
'arrow-parens': 'error',
137-
'arrow-spacing': 'error',
138136
'block-scoped-var': 'error',
139-
'block-spacing': 'error',
140-
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
141137
'capitalized-comments': ['error', 'always', {
142138
line: {
143139
// Ignore all lines that have less characters than 20 and all lines that
@@ -150,49 +146,20 @@ module.exports = {
150146
ignorePattern: '.*',
151147
},
152148
}],
153-
'comma-dangle': ['error', 'always-multiline'],
154-
'comma-spacing': 'error',
155-
'comma-style': 'error',
156-
'computed-property-spacing': 'error',
157149
'default-case-last': 'error',
158-
'dot-location': ['error', 'property'],
159150
'dot-notation': 'error',
160151
'eol-last': 'error',
161152
'eqeqeq': ['error', 'smart'],
162153
'func-call-spacing': 'error',
163154
'func-name-matching': 'error',
164155
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
165-
'indent': ['error', 2, {
166-
ArrayExpression: 'first',
167-
CallExpression: { arguments: 'first' },
168-
FunctionDeclaration: { parameters: 'first' },
169-
FunctionExpression: { parameters: 'first' },
170-
MemberExpression: 'off',
171-
ObjectExpression: 'first',
172-
SwitchCase: 1,
173-
}],
174-
'key-spacing': 'error',
175-
'keyword-spacing': 'error',
176156
'linebreak-style': 'error',
177-
'max-len': ['error', {
178-
code: 120,
179-
ignorePattern: '^// Flags:',
180-
ignoreRegExpLiterals: true,
181-
ignoreTemplateLiterals: true,
182-
ignoreUrls: true,
183-
tabWidth: 2,
184-
}],
185-
'new-parens': 'error',
186-
'no-confusing-arrow': 'error',
187157
'no-constant-condition': ['error', { checkLoops: false }],
188158
'no-constructor-return': 'error',
189159
'no-duplicate-imports': 'error',
190160
'no-else-return': 'error',
191-
'no-extra-parens': ['error', 'functions'],
192161
'no-lonely-if': 'error',
193162
'no-mixed-requires': 'error',
194-
'no-multi-spaces': ['error', { ignoreEOLComments: true }],
195-
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0, maxBOF: 0 }],
196163
'no-new-require': 'error',
197164
'no-path-concat': 'error',
198165
'no-proto': 'error',
@@ -257,10 +224,8 @@ module.exports = {
257224
},
258225
],
259226
'no-self-compare': 'error',
260-
'no-tabs': 'error',
261227
'no-template-curly-in-string': 'error',
262228
'no-throw-literal': 'error',
263-
'no-trailing-spaces': 'error',
264229
'no-undef': ['error', { typeof: true }],
265230
'no-undef-init': 'error',
266231
'no-unused-expressions': ['error', { allowShortCircuit: true }],
@@ -276,39 +241,11 @@ module.exports = {
276241
'no-useless-return': 'error',
277242
'no-var': 'error',
278243
'no-void': 'error',
279-
'no-whitespace-before-property': 'error',
280-
'object-curly-newline': 'error',
281-
'object-curly-spacing': ['error', 'always'],
282244
'one-var': ['error', { initialized: 'never' }],
283-
'one-var-declaration-per-line': 'error',
284-
'operator-linebreak': ['error', 'after'],
285-
'padding-line-between-statements': [
286-
'error',
287-
{ blankLine: 'always', prev: 'function', next: 'function' },
288-
],
289245
'prefer-const': ['error', { ignoreReadBeforeAssign: true }],
290246
'prefer-object-has-own': 'error',
291-
'quotes': ['error', 'single', { avoidEscape: true }],
292-
'quote-props': ['error', 'consistent'],
293-
'rest-spread-spacing': 'error',
294-
'semi': 'error',
295-
'semi-spacing': 'error',
296-
'space-before-blocks': ['error', 'always'],
297-
'space-before-function-paren': ['error', {
298-
anonymous: 'never',
299-
named: 'never',
300-
asyncArrow: 'always',
301-
}],
302-
'space-in-parens': 'error',
303-
'space-infix-ops': 'error',
304-
'space-unary-ops': 'error',
305-
'spaced-comment': ['error', 'always', {
306-
'block': { 'balanced': true },
307-
'exceptions': ['-'],
308-
}],
309247
'strict': ['error', 'global'],
310248
'symbol-description': 'error',
311-
'template-curly-spacing': 'error',
312249
'unicode-bom': 'error',
313250
'valid-typeof': ['error', { requireStringLiterals: true }],
314251

.github/workflows/linters.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,23 @@ jobs:
114114
NODE=$(command -v node) make lint-md
115115
env:
116116
NODE_RELEASED_VERSIONS: ${{ steps.get-released-versions.outputs.NODE_RELEASED_VERSIONS }}
117+
format-js:
118+
if: github.event.pull_request.draft == false
119+
runs-on: ubuntu-latest
120+
steps:
121+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
122+
with:
123+
persist-credentials: false
124+
- name: Use Node.js ${{ env.NODE_VERSION }}
125+
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
126+
with:
127+
node-version: ${{ env.NODE_VERSION }}
128+
- name: Environment Information
129+
run: npx envinfo
130+
- name: Format JavaScript files
131+
run: |
132+
make format-js-build
133+
make format-js-check
117134
lint-py:
118135
if: github.event.pull_request.draft == false
119136
runs-on: ubuntu-latest

.github/workflows/tools.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ on:
1717
- acorn-walk
1818
- ada
1919
- base64
20+
- biome
2021
- brotli
2122
- c-ares
2223
- cjs-module-lexer
@@ -88,6 +89,14 @@ jobs:
8889
cat temp-output
8990
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
9091
rm temp-output
92+
- id: biome
93+
subsystem: tools
94+
label: tools
95+
run: |
96+
./tools/dep_updaters/update-biome.sh > temp-output
97+
cat temp-output
98+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
99+
rm temp-output
91100
- id: brotli
92101
subsystem: deps
93102
label: dependencies

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ tools/*/*.i.tmp
115115
/node_modules
116116
/tools/doc/node_modules
117117
/tools/clang-format/node_modules
118+
/tools/biome/node_modules
118119

119120
# === Rules for test artifacts ===
120121
/*.tap

LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,31 @@ The externally maintained libraries used by Node.js are:
20242024
THE SOFTWARE.
20252025
"""
20262026

2027+
- biome, located at tools/biome/node_modules/@biomejs/biome, is licensed as follows:
2028+
"""
2029+
MIT License
2030+
2031+
Copyright (c) 2023 Biome Developers and Contributors.
2032+
2033+
Permission is hereby granted, free of charge, to any person obtaining a copy
2034+
of this software and associated documentation files (the "Software"), to deal
2035+
in the Software without restriction, including without limitation the rights
2036+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2037+
copies of the Software, and to permit persons to whom the Software is
2038+
furnished to do so, subject to the following conditions:
2039+
2040+
The above copyright notice and this permission notice shall be included in all
2041+
copies or substantial portions of the Software.
2042+
2043+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2044+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2045+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2046+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2047+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2048+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2049+
SOFTWARE.
2050+
"""
2051+
20272052
- gtest, located at deps/googletest, is licensed as follows:
20282053
"""
20292054
Copyright 2008, Google Inc.

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,40 @@ FORMAT_CPP_FILES += $(wildcard \
14501450
# and the actual filename is generated so it won't match header guards
14511451
ADDON_DOC_LINT_FLAGS=-whitespace/ending_newline,-build/header_guard
14521452

1453+
.PHONY: format-js-build
1454+
format-js-build:
1455+
cd tools/biome && $(call available-node,$(run-npm-ci))
1456+
1457+
.PHONY: format-js-clean
1458+
.NOTPARALLEL: format-js-clean
1459+
format-js-clean:
1460+
$(RM) -r tools/biome/node_modules
1461+
1462+
.PHONY: format-js
1463+
format-js: ## Format JS files
1464+
ifneq ("","$(wildcard tools/biome/node_modules/)")
1465+
tools/biome/node_modules/.bin/biome \
1466+
check . \
1467+
--apply \ # Apply safe fixes
1468+
--changed \
1469+
--no-errors-on-unmatched
1470+
else
1471+
$(info Required tooling for JavaScript code formatting is not installed.)
1472+
$(info To install (requires internet access) run: $$ make format-js-build)
1473+
endif
1474+
1475+
.PHONY: format-js-check
1476+
format-js-check: ## Check JS files formatting
1477+
ifneq ("","$(wildcard tools/biome/node_modules/)")
1478+
tools/biome/node_modules/.bin/biome \
1479+
check . \
1480+
--changed \
1481+
--no-errors-on-unmatched
1482+
else
1483+
$(info Required tooling for JavaScript code formatting is not installed.)
1484+
$(info To install (requires internet access) run: $$ make format-js-build)
1485+
endif
1486+
14531487
.PHONY: format-cpp-build
14541488
format-cpp-build:
14551489
cd tools/clang-format && $(call available-node,$(run-npm-ci))

biome.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"$schema": "./tools/biome/node_modules/@biomejs/biome/configuration_schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"defaultBranch": "main",
6+
"clientKind": "git",
7+
"useIgnoreFile": true
8+
},
9+
"files": {
10+
"ignoreUnknown": true,
11+
"include": [],
12+
"ignore": [
13+
"doc",
14+
"out",
15+
"benchmark",
16+
"typings",
17+
"test",
18+
"tools",
19+
"deps",
20+
".eslintrc.js",
21+
"lib"
22+
]
23+
},
24+
"formatter": {
25+
"enabled": true,
26+
"indentStyle": "space",
27+
"indentWidth": 2,
28+
"lineWidth": 120
29+
},
30+
"linter": {
31+
"enabled": false
32+
},
33+
"organizeImports": {
34+
"enabled": false
35+
},
36+
"javascript": {
37+
"formatter": {
38+
"enabled": true,
39+
"arrowParentheses": "always",
40+
"trailingComma": "all",
41+
"quoteStyle": "single",
42+
"semicolons": "always"
43+
}
44+
},
45+
"json": {
46+
"formatter": {
47+
"enabled": false
48+
}
49+
}
50+
}

test/common/dns.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ function readDomainFromPacket(buffer, offset) {
4040
}
4141
// Pointer to another part of the packet.
4242
assert.strictEqual(length & 0xC0, 0xC0);
43-
// eslint-disable-next-line space-infix-ops, space-unary-ops
4443
const pointeeOffset = buffer.readUInt16BE(offset) &~ 0xC000;
4544
return {
4645
nread: 2,

test/parallel/test-assert.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ assert.throws(
730730
// before the assertion causes any wrong assertion message.
731731
// Therefore, don't reformat the following code.
732732
// Refs: https://github.com/nodejs/node/issues/30872
733-
try { assert.ok(0); // eslint-disable-line no-useless-catch, brace-style
733+
try { assert.ok(0); // eslint-disable-line no-useless-catch
734734
} catch (err) {
735735
throw err;
736736
}
@@ -767,7 +767,7 @@ assert.throws(
767767
// before the assertion causes any wrong assertion message.
768768
// Therefore, don't reformat the following code.
769769
// Refs: https://github.com/nodejs/node/issues/30872
770-
function test() { assert.ok(0); // eslint-disable-line brace-style
770+
function test() { assert.ok(0);
771771
}
772772
test();
773773
},
@@ -804,7 +804,6 @@ assert.throws(
804804
() => {
805805
a(
806806
(() => 'string')()
807-
// eslint-disable-next-line operator-linebreak
808807
===
809808
123 instanceof
810809
Buffer
@@ -828,7 +827,6 @@ assert.throws(
828827
() => {
829828
a(
830829
(() => 'string')()
831-
// eslint-disable-next-line operator-linebreak
832830
===
833831
123 instanceof
834832
Buffer
@@ -848,7 +846,6 @@ assert.throws(
848846
}
849847
);
850848

851-
/* eslint-disable indent */
852849
assert.throws(() => {
853850
a((
854851
() => 'string')() ===
@@ -866,7 +863,6 @@ Buffer
866863
' )\n'
867864
}
868865
);
869-
/* eslint-enable indent */
870866

871867
assert.throws(
872868
() => {
@@ -894,7 +890,7 @@ assert.throws(
894890
);
895891

896892
assert.throws(
897-
// eslint-disable-next-line dot-notation, quotes
893+
// eslint-disable-next-line dot-notation
898894
() => assert['ok']["apply"](null, [0]),
899895
{
900896
code: 'ERR_ASSERTION',

test/parallel/test-repl-colors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable quotes */
21
'use strict';
32
require('../common');
43
const { Duplex } = require('stream');

0 commit comments

Comments
 (0)