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 e1f943c
Show file tree
Hide file tree
Showing 20 changed files with 348 additions and 91 deletions.
63 changes: 0 additions & 63 deletions .eslintrc.js
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
24 changes: 24 additions & 0 deletions .github/workflows/linters.yml
Expand Up @@ -114,6 +114,30 @@ 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
BIOME_FORMAT_START="$(git merge-base HEAD refs/remotes/origin/$GITHUB_BASE_REF)"
tools/biome/node_modules/.bin/biome \
check . \
--changed \
--no-errors-on-unmatched \
--since="$BIOME_FORMAT_START"
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
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
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
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
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 \
--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: ## Format JS files
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
45 changes: 45 additions & 0 deletions biome.json
@@ -0,0 +1,45 @@
{
"$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", "src"]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 120,
"formatWithErrors": true,
"lineEnding": "lf"
},
"linter": {
"enabled": false
},
"organizeImports": {
"enabled": false
},
"javascript": {
"formatter": {
"enabled": true,
"arrowParentheses": "always",
"trailingComma": "all",
"quoteStyle": "single",
"semicolons": "always"
}
},
"json": {
"formatter": {
"enabled": true,
"indentWidth": 2,
"indentStyle": "space",
"lineEnding": "lf"
}
}
}
1 change: 0 additions & 1 deletion test/common/dns.js
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
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
3 changes: 0 additions & 3 deletions test/parallel/test-internal-validators-validateoneof.js
Expand Up @@ -10,7 +10,6 @@ const { validateOneOf } = require('internal/validators');
const allowed = [2, 3];
assert.throws(() => validateOneOf(1, 'name', allowed), {
code: 'ERR_INVALID_ARG_VALUE',
// eslint-disable-next-line quotes
message: `The argument 'name' must be one of: 2, 3. Received 1`
});
}
Expand All @@ -25,7 +24,6 @@ const { validateOneOf } = require('internal/validators');
const allowed = ['b', 'c'];
assert.throws(() => validateOneOf('a', 'name', allowed), {
code: 'ERR_INVALID_ARG_VALUE',
// eslint-disable-next-line quotes
message: `The argument 'name' must be one of: 'b', 'c'. Received 'a'`
});
}
Expand All @@ -40,7 +38,6 @@ const { validateOneOf } = require('internal/validators');
const allowed = [Symbol.for('b'), Symbol.for('c')];
assert.throws(() => validateOneOf(Symbol.for('a'), 'name', allowed), {
code: 'ERR_INVALID_ARG_VALUE',
// eslint-disable-next-line quotes
message: `The argument 'name' must be one of: Symbol(b), Symbol(c). ` +
'Received Symbol(a)'
});
Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-policy-integrity-flag.js
Expand Up @@ -21,12 +21,10 @@ const emptySRI = `sha512-${emptyHash.digest('base64')}`;
const policyHash = crypto.createHash('sha512');
policyHash.update(fs.readFileSync(depPolicy));

/* eslint-disable max-len */
// When using \n only
const nixPolicySRI = 'sha512-u/nXI6UacK5fKDC2bopcgnuQY4JXJKlK3dESO3GIKKxwogVHjJqpF9rgk7Zw+TJXIc96xBUWKHuUgOzic8/4tQ==';
// When \n is turned into \r\n
const windowsPolicySRI = 'sha512-OeyCPRo4OZMosHyquZXDHpuU1F4KzG9UHFnn12FMaHsvqFUt3TFZ+7wmZE7ThZ5rsQWkUjc9ZH0knGZ2e8BYPQ==';
/* eslint-enable max-len */

const depPolicySRI = `${nixPolicySRI} ${windowsPolicySRI}`;
{
Expand Down

0 comments on commit e1f943c

Please sign in to comment.