Skip to content

Commit

Permalink
tools: use stylistic ESLint plugin for formatting
Browse files Browse the repository at this point in the history
Refs: https://eslint.org/blog/2023/10/deprecating-formatting-rules/
PR-URL: #50714
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
targos authored and aduh95 committed Apr 29, 2024
1 parent e066ba2 commit 4e5ce3a
Show file tree
Hide file tree
Showing 1,049 changed files with 14,778 additions and 4,478 deletions.
137 changes: 70 additions & 67 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const hacks = [
'eslint-plugin-markdown',
'@babel/eslint-parser',
'@babel/plugin-syntax-import-attributes',
'@stylistic/eslint-plugin-js',
];
Module._findPath = (request, paths, isMain) => {
const r = ModuleFindPath(request, paths, isMain);
Expand All @@ -39,7 +40,7 @@ module.exports = {
es2022: true,
},
extends: ['eslint:recommended', 'plugin:jsdoc/recommended'],
plugins: ['jsdoc', 'markdown', 'node-core'],
plugins: ['jsdoc', 'markdown', 'node-core', '@stylistic/js'],
parser: '@babel/eslint-parser',
parserOptions: {
babelOptions: {
Expand Down Expand Up @@ -133,11 +134,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 +147,17 @@ 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 +222,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 +239,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 All @@ -327,6 +262,74 @@ module.exports = {
'jsdoc/check-tag-names': 'off',
'jsdoc/require-returns': 'off',

// Stylistic rules
'@stylistic/js/arrow-parens': 'error',
'@stylistic/js/arrow-spacing': 'error',
'@stylistic/js/block-spacing': 'error',
'@stylistic/js/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'@stylistic/js/comma-dangle': ['error', 'always-multiline'],
'@stylistic/js/comma-spacing': 'error',
'@stylistic/js/comma-style': 'error',
'@stylistic/js/computed-property-spacing': 'error',
'@stylistic/js/dot-location': ['error', 'property'],
'@stylistic/js/eol-last': 'error',
'@stylistic/js/func-call-spacing': 'error',
'@stylistic/js/indent': ['error', 2, {
ArrayExpression: 'first',
CallExpression: { arguments: 'first' },
FunctionDeclaration: { parameters: 'first' },
FunctionExpression: { parameters: 'first' },
MemberExpression: 'off',
ObjectExpression: 'first',
SwitchCase: 1,
}],
'@stylistic/js/key-spacing': 'error',
'@stylistic/js/keyword-spacing': 'error',
'@stylistic/js/linebreak-style': 'error',
'@stylistic/js/max-len': ['error', {
code: 120,
ignorePattern: '^// Flags:',
ignoreRegExpLiterals: true,
ignoreTemplateLiterals: true,
ignoreUrls: true,
tabWidth: 2,
}],
'@stylistic/js/new-parens': 'error',
'@stylistic/js/no-confusing-arrow': 'error',
'@stylistic/js/no-extra-parens': ['error', 'functions'],
'@stylistic/js/no-multi-spaces': ['error', { ignoreEOLComments: true }],
'@stylistic/js/no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0, maxBOF: 0 }],
'@stylistic/js/no-tabs': 'error',
'@stylistic/js/no-trailing-spaces': 'error',
'@stylistic/js/no-whitespace-before-property': 'error',
'@stylistic/js/object-curly-newline': 'error',
'@stylistic/js/object-curly-spacing': ['error', 'always'],
'@stylistic/js/one-var-declaration-per-line': 'error',
'@stylistic/js/operator-linebreak': ['error', 'after'],
'@stylistic/js/padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: 'function', next: 'function' },
],
'@stylistic/js/quotes': ['error', 'single', { avoidEscape: true }],
'@stylistic/js/quote-props': ['error', 'consistent'],
'@stylistic/js/rest-spread-spacing': 'error',
'@stylistic/js/semi': 'error',
'@stylistic/js/semi-spacing': 'error',
'@stylistic/js/space-before-blocks': ['error', 'always'],
'@stylistic/js/space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
}],
'@stylistic/js/space-in-parens': 'error',
'@stylistic/js/space-infix-ops': 'error',
'@stylistic/js/space-unary-ops': 'error',
'@stylistic/js/spaced-comment': ['error', 'always', {
'block': { 'balanced': true },
'exceptions': ['-'],
}],
'@stylistic/js/template-curly-spacing': 'error',

// Custom rules from eslint-plugin-node-core
'node-core/no-unescaped-regexp-dot': 'error',
'node-core/no-duplicate-requires': 'error',
Expand Down
4 changes: 2 additions & 2 deletions doc/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ rules:
prefer-rest-params: error
prefer-template: error

# Stylistic Issues
no-multiple-empty-lines: [error, {max: 1, maxEOF: 0, maxBOF: 0}]
# Stylistic rules
'@stylistic/js/no-multiple-empty-lines': [error, {max: 1, maxEOF: 0, maxBOF: 0}]
8 changes: 4 additions & 4 deletions doc/api/dns.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Returns an array of IP address strings, formatted according to [RFC 5952][],
that are currently configured for DNS resolution. A string will include a port
section if a custom port is used.

<!-- eslint-disable semi-->
<!-- eslint-disable @stylistic/js/semi-->

```js
[
Expand Down Expand Up @@ -468,7 +468,7 @@ will be present on the object:

Here is an example of the `ret` object passed to the callback:

<!-- eslint-disable semi -->
<!-- eslint-disable @stylistic/js/semi -->

```js
[ { type: 'A', address: '127.0.0.1', ttl: 299 },
Expand Down Expand Up @@ -934,7 +934,7 @@ Returns an array of IP address strings, formatted according to [RFC 5952][],
that are currently configured for DNS resolution. A string will include a port
section if a custom port is used.

<!-- eslint-disable semi-->
<!-- eslint-disable @stylistic/js/semi-->

```js
[
Expand Down Expand Up @@ -1135,7 +1135,7 @@ present on the object:

Here is an example of the result object:

<!-- eslint-disable semi -->
<!-- eslint-disable @stylistic/js/semi -->

```js
[ { type: 'A', address: '127.0.0.1', ttl: 299 },
Expand Down
2 changes: 1 addition & 1 deletion doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ property, which is an array of `[key, value, key2, value2, ...]`. For
example, the previous message header object might have a `rawHeaders`
list like the following:

<!-- eslint-disable semi -->
<!-- eslint-disable @stylistic/js/semi -->

```js
[ 'ConTent-Length', '123456',
Expand Down
2 changes: 1 addition & 1 deletion doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -3587,7 +3587,7 @@ Accept: text/plain

Then `request.url` will be:

<!-- eslint-disable semi -->
<!-- eslint-disable @stylistic/js/semi -->

```js
'/status?name=ryan'
Expand Down
2 changes: 1 addition & 1 deletion doc/api/os.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The properties included on each object include:
* `idle` {number} The number of milliseconds the CPU has spent in idle mode.
* `irq` {number} The number of milliseconds the CPU has spent in irq mode.

<!-- eslint-disable semi -->
<!-- eslint-disable @stylistic/js/semi -->

```js
[
Expand Down
4 changes: 2 additions & 2 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ Results in `process.execArgv`:
And `process.argv`:
<!-- eslint-disable semi -->
<!-- eslint-disable @stylistic/js/semi -->
```js
['/usr/local/bin/node', 'script.js', '--version']
Expand All @@ -1742,7 +1742,7 @@ added: v0.1.100
The `process.execPath` property returns the absolute pathname of the executable
that started the Node.js process. Symbolic links, if any, are resolved.
<!-- eslint-disable semi -->
<!-- eslint-disable @stylistic/js/semi -->
```js
'/usr/local/bin/node'
Expand Down
2 changes: 1 addition & 1 deletion doc/api/zlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ From `zlib/zconf.h`, modified for Node.js usage:

The memory requirements for deflate are (in bytes):

<!-- eslint-disable semi -->
<!-- eslint-disable @stylistic/js/semi -->

```js
(1 << (windowBits + 2)) + (1 << (memLevel + 9))
Expand Down
9 changes: 6 additions & 3 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ env:
rules:
prefer-object-spread: error
no-buffer-constructor: error
no-mixed-operators:
- error
- groups: [['&&', '||']]
no-restricted-syntax:
# Config copied from .eslintrc.js
- error
Expand Down Expand Up @@ -181,6 +178,12 @@ rules:
- error
- name: url
message: Require `internal/url` instead of `url`.

# Stylistic rules
'@stylistic/js/no-mixed-operators':
- error
- groups: [['&&', '||']]

# Custom rules in tools/eslint-rules
node-core/avoid-prototype-pollution: error
node-core/lowercase-name-for-primitive: error
Expand Down
6 changes: 4 additions & 2 deletions test/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ rules:
multiline-comment-style: [error, separate-lines]
prefer-const: error
symbol-description: off
comma-dangle: [error, always-multiline]

no-restricted-syntax:
# Config copied from .eslintrc.js
Expand Down Expand Up @@ -54,6 +53,9 @@ rules:
- selector: Identifier[name='webcrypto']
message: Use `globalThis.crypto`.

# Stylistic rules
'@stylistic/js/comma-dangle': [error, always-multiline]

# Custom rules in tools/eslint-rules
node-core/prefer-assert-iferror: error
node-core/prefer-assert-methods: error
Expand Down Expand Up @@ -83,7 +85,7 @@ overrides:
- sequential/*.js
- sequential/*.mjs
rules:
comma-dangle: [error, {
'@stylistic/js/comma-dangle': [error, {
arrays: always-multiline,
exports: always-multiline,
functions: only-multiline,
Expand Down
2 changes: 1 addition & 1 deletion test/common/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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
// eslint-disable-next-line @stylistic/js/space-infix-ops, @stylistic/js/space-unary-ops
const pointeeOffset = buffer.readUInt16BE(offset) &~ 0xC000;
return {
nread: 2,
Expand Down
Loading

0 comments on commit 4e5ce3a

Please sign in to comment.