Skip to content

Commit

Permalink
build: use biome as formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Feb 27, 2024
1 parent f28ccd3 commit dfe7abf
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 76 deletions.
63 changes: 0 additions & 63 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ module.exports = {
// https://eslint.org/docs/rules/
'accessor-pairs': 'error',
'array-callback-return': 'error',
'arrow-parens': 'error',
'arrow-spacing': 'error',
'block-scoped-var': 'error',
'block-spacing': 'error',
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
'capitalized-comments': ['error', 'always', {
line: {
// Ignore all lines that have less characters than 20 and all lines that
Expand All @@ -150,49 +146,20 @@ module.exports = {
ignorePattern: '.*',
},
}],
'comma-dangle': ['error', 'always-multiline'],
'comma-spacing': 'error',
'comma-style': 'error',
'computed-property-spacing': 'error',
'default-case-last': 'error',
'dot-location': ['error', 'property'],
'dot-notation': 'error',
'eol-last': 'error',
'eqeqeq': ['error', 'smart'],
'func-call-spacing': 'error',
'func-name-matching': 'error',
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
'indent': ['error', 2, {
ArrayExpression: 'first',
CallExpression: { arguments: 'first' },
FunctionDeclaration: { parameters: 'first' },
FunctionExpression: { parameters: 'first' },
MemberExpression: 'off',
ObjectExpression: 'first',
SwitchCase: 1,
}],
'key-spacing': 'error',
'keyword-spacing': 'error',
'linebreak-style': 'error',
'max-len': ['error', {
code: 120,
ignorePattern: '^// Flags:',
ignoreRegExpLiterals: true,
ignoreTemplateLiterals: true,
ignoreUrls: true,
tabWidth: 2,
}],
'new-parens': 'error',
'no-confusing-arrow': 'error',
'no-constant-condition': ['error', { checkLoops: false }],
'no-constructor-return': 'error',
'no-duplicate-imports': 'error',
'no-else-return': 'error',
'no-extra-parens': ['error', 'functions'],
'no-lonely-if': 'error',
'no-mixed-requires': 'error',
'no-multi-spaces': ['error', { ignoreEOLComments: true }],
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0, maxBOF: 0 }],
'no-new-require': 'error',
'no-path-concat': 'error',
'no-proto': 'error',
Expand Down Expand Up @@ -257,10 +224,8 @@ module.exports = {
},
],
'no-self-compare': 'error',
'no-tabs': 'error',
'no-template-curly-in-string': 'error',
'no-throw-literal': 'error',
'no-trailing-spaces': 'error',
'no-undef': ['error', { typeof: true }],
'no-undef-init': 'error',
'no-unused-expressions': ['error', { allowShortCircuit: true }],
Expand All @@ -276,39 +241,11 @@ module.exports = {
'no-useless-return': 'error',
'no-var': 'error',
'no-void': 'error',
'no-whitespace-before-property': 'error',
'object-curly-newline': 'error',
'object-curly-spacing': ['error', 'always'],
'one-var': ['error', { initialized: 'never' }],
'one-var-declaration-per-line': 'error',
'operator-linebreak': ['error', 'after'],
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: 'function', next: 'function' },
],
'prefer-const': ['error', { ignoreReadBeforeAssign: true }],
'prefer-object-has-own': 'error',
'quotes': ['error', 'single', { avoidEscape: true }],
'quote-props': ['error', 'consistent'],
'rest-spread-spacing': 'error',
'semi': 'error',
'semi-spacing': 'error',
'space-before-blocks': ['error', 'always'],
'space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
}],
'space-in-parens': 'error',
'space-infix-ops': 'error',
'space-unary-ops': 'error',
'spaced-comment': ['error', 'always', {
'block': { 'balanced': true },
'exceptions': ['-'],
}],
'strict': ['error', 'global'],
'symbol-description': 'error',
'template-curly-spacing': 'error',
'unicode-bom': 'error',
'valid-typeof': ['error', { requireStringLiterals: true }],

Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ jobs:
NODE=$(command -v node) make lint-md
env:
NODE_RELEASED_VERSIONS: ${{ steps.get-released-versions.outputs.NODE_RELEASED_VERSIONS }}
format-js:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: ${{ env.NODE_VERSION }}
- name: Environment Information
run: npx envinfo
- name: Format JavaScript files
run: |
make format-js-build
make format-js-check
lint-py:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
- acorn-walk
- ada
- base64
- biome
- brotli
- c-ares
- cjs-module-lexer
Expand Down Expand Up @@ -88,6 +89,14 @@ jobs:
cat temp-output
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
rm temp-output
- id: biome
subsystem: tools
label: tools
run: |
./tools/dep_updaters/update-biome.sh > temp-output
cat temp-output
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
rm temp-output
- id: brotli
subsystem: deps
label: dependencies
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ tools/*/*.i.tmp
/node_modules
/tools/doc/node_modules
/tools/clang-format/node_modules
/tools/biome/node_modules

# === Rules for test artifacts ===
/*.tap
Expand Down
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,31 @@ The externally maintained libraries used by Node.js are:
THE SOFTWARE.
"""

- biome, located at tools/biome/node_modules/@biomejs/biome, is licensed as follows:
"""
MIT License

Copyright (c) 2023 Biome Developers and Contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

- gtest, located at deps/googletest, is licensed as follows:
"""
Copyright 2008, Google Inc.
Expand Down
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,40 @@ FORMAT_CPP_FILES += $(wildcard \
# and the actual filename is generated so it won't match header guards
ADDON_DOC_LINT_FLAGS=-whitespace/ending_newline,-build/header_guard

.PHONY: format-js-build
format-js-build:
cd tools/biome && $(call available-node,$(run-npm-ci))

.PHONY: format-js-clean
.NOTPARALLEL: format-js-clean
format-js-clean:
$(RM) -r tools/biome/node_modules

.PHONY: format-js
format-js: ## Format JS files
ifneq ("","$(wildcard tools/biome/node_modules/)")
tools/biome/node_modules/.bin/biome \
check . \
--apply \ # Apply safe fixes
--changed \
--no-errors-on-unmatched
else
$(info Required tooling for JavaScript code formatting is not installed.)
$(info To install (requires internet access) run: $$ make format-js-build)
endif

.PHONY: format-js-check
format-js-check: ## Check JS files formatting
ifneq ("","$(wildcard tools/biome/node_modules/)")
tools/biome/node_modules/.bin/biome \
check . \
--changed \
--no-errors-on-unmatched
else
$(info Required tooling for JavaScript code formatting is not installed.)
$(info To install (requires internet access) run: $$ make format-js-build)
endif

.PHONY: format-cpp-build
format-cpp-build:
cd tools/clang-format && $(call available-node,$(run-npm-ci))
Expand Down
50 changes: 50 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"$schema": "./tools/biome/node_modules/@biomejs/biome/configuration_schema.json",
"vcs": {
"enabled": true,
"defaultBranch": "main",
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": true,
"include": [],
"ignore": [
"doc",
"out",
"benchmark",
"typings",
"test",
"tools",
"deps",
".eslintrc.js",
"lib"
]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 120
},
"linter": {
"enabled": false
},
"organizeImports": {
"enabled": false
},
"javascript": {
"formatter": {
"enabled": true,
"arrowParentheses": "always",
"trailingComma": "all",
"quoteStyle": "single",
"semicolons": "always"
}
},
"json": {
"formatter": {
"enabled": false
}
}
}
1 change: 0 additions & 1 deletion test/common/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function readDomainFromPacket(buffer, offset) {
}
// Pointer to another part of the packet.
assert.strictEqual(length & 0xC0, 0xC0);
// eslint-disable-next-line space-infix-ops, space-unary-ops
const pointeeOffset = buffer.readUInt16BE(offset) &~ 0xC000;
return {
nread: 2,
Expand Down
10 changes: 3 additions & 7 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ assert.throws(
// before the assertion causes any wrong assertion message.
// Therefore, don't reformat the following code.
// Refs: https://github.com/nodejs/node/issues/30872
try { assert.ok(0); // eslint-disable-line no-useless-catch, brace-style
try { assert.ok(0); // eslint-disable-line no-useless-catch
} catch (err) {
throw err;
}
Expand Down Expand Up @@ -767,7 +767,7 @@ assert.throws(
// before the assertion causes any wrong assertion message.
// Therefore, don't reformat the following code.
// Refs: https://github.com/nodejs/node/issues/30872
function test() { assert.ok(0); // eslint-disable-line brace-style
function test() { assert.ok(0);
}
test();
},
Expand Down Expand Up @@ -804,7 +804,6 @@ assert.throws(
() => {
a(
(() => 'string')()
// eslint-disable-next-line operator-linebreak
===
123 instanceof
Buffer
Expand All @@ -828,7 +827,6 @@ assert.throws(
() => {
a(
(() => 'string')()
// eslint-disable-next-line operator-linebreak
===
123 instanceof
Buffer
Expand All @@ -848,7 +846,6 @@ assert.throws(
}
);

/* eslint-disable indent */
assert.throws(() => {
a((
() => 'string')() ===
Expand All @@ -866,7 +863,6 @@ Buffer
' )\n'
}
);
/* eslint-enable indent */

assert.throws(
() => {
Expand Down Expand Up @@ -894,7 +890,7 @@ assert.throws(
);

assert.throws(
// eslint-disable-next-line dot-notation, quotes
// eslint-disable-next-line dot-notation
() => assert['ok']["apply"](null, [0]),
{
code: 'ERR_ASSERTION',
Expand Down
1 change: 0 additions & 1 deletion test/parallel/test-repl-colors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable quotes */
'use strict';
require('../common');
const { Duplex } = require('stream');
Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
}), {
name: 'RangeError',
code: 'ERR_OUT_OF_RANGE',
// eslint-disable-next-line max-len
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6 ("options.shard.total"). Received 0'
});
});
Expand All @@ -350,7 +349,6 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
}), {
name: 'RangeError',
code: 'ERR_OUT_OF_RANGE',
// eslint-disable-next-line max-len
message: 'The value of "options.shard.index" is out of range. It must be >= 1 && <= 6 ("options.shard.total"). Received 7'
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-webcrypto-export-import-ec.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ async function testImportRaw({ name, publicUsages }, namedCurve) {

// https://github.com/nodejs/node/issues/45859
(async function() {
const compressed = Buffer.from([48, 57, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 34, 0, 2, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209]); // eslint-disable-line max-len
const uncompressed = Buffer.from([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209, 206, 3, 117, 82, 212, 129, 69, 12, 227, 155, 77, 16, 149, 112, 27, 23, 91, 250, 179, 75, 142, 108, 9, 158, 24, 241, 193, 152, 53, 131, 97, 232]); // eslint-disable-line max-len
const compressed = Buffer.from([48, 57, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 34, 0, 2, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209]);
const uncompressed = Buffer.from([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 210, 16, 176, 166, 249, 217, 240, 18, 134, 128, 88, 180, 63, 164, 244, 113, 1, 133, 67, 187, 160, 12, 146, 80, 223, 146, 87, 194, 172, 174, 93, 209, 206, 3, 117, 82, 212, 129, 69, 12, 227, 155, 77, 16, 149, 112, 27, 23, 91, 250, 179, 75, 142, 108, 9, 158, 24, 241, 193, 152, 53, 131, 97, 232]);
for (const name of ['ECDH', 'ECDSA']) {
const options = { name, namedCurve: 'P-256' };
const key = await subtle.importKey('spki', compressed, options, true, []);
Expand Down
Loading

0 comments on commit dfe7abf

Please sign in to comment.