Skip to content

Commit

Permalink
update some linting plugins / rules
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed May 10, 2024
1 parent 20d6add commit 431a551
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 44 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var WRONG_ARITY = !!NativeSuppressedError && NativeSuppressedError.length !== 3;

// https://github.com/oven-sh/bun/issues/9283
var EXTRA_ARGS_SUPPORT = !!NativeSuppressedError && fails(function () {
return NativeSuppressedError(1, 2, 3, { cause: 4 }).cause === 4;
return new NativeSuppressedError(1, 2, 3, { cause: 4 }).cause === 4;
});

var PATCH = WRONG_ARITY || EXTRA_ARGS_SUPPORT;
Expand Down
6 changes: 3 additions & 3 deletions scripts/bundle-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/usage/usage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const sites = file
echo(green(`downloading and parsing the rank took ${ cyan((Date.now() - start) / 1e3) } seconds\n${ gray('-'.repeat(120)) }`));

function timeout(promise, time) {
return Promise.race([promise, new Promise((resolve, reject) => setTimeout(() => reject(Error('timeout')), time))]);
return Promise.race([promise, new Promise((resolve, reject) => setTimeout(() => reject(new Error('timeout')), time))]);
}

chromium.use(StealthPlugin());
Expand Down
8 changes: 4 additions & 4 deletions tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ GLOBAL.tests = {
return Symbol.unscopables;
}],
'es.error.cause': function () {
return Error('e', { cause: 7 }).cause === 7
return new Error('e', { cause: 7 }).cause === 7
&& !('cause' in Error.prototype);
},
'es.error.to-string': function () {
Expand All @@ -358,7 +358,7 @@ GLOBAL.tests = {
return typeof AggregateError == 'function';
},
'es.aggregate-error.cause': function () {
return AggregateError([1], 'e', { cause: 7 }).cause === 7
return new AggregateError([1], 'e', { cause: 7 }).cause === 7
&& !('cause' in AggregateError.prototype);
},
'es.array.at': function () {
Expand Down Expand Up @@ -1528,7 +1528,7 @@ GLOBAL.tests = {
'esnext.suppressed-error.constructor': function () {
return typeof SuppressedError == 'function'
&& SuppressedError.length === 3
&& SuppressedError(1, 2, 3, { cause: 4 }).cause !== 4;
&& new SuppressedError(1, 2, 3, { cause: 4 }).cause !== 4;
},
'esnext.array.from-async': function () {
// https://bugs.webkit.org/show_bug.cgi?id=271703
Expand Down Expand Up @@ -1965,7 +1965,7 @@ GLOBAL.tests = {
&& DOMException.prototype.DATA_CLONE_ERR === 25;
},
'web.dom-exception.stack': function () {
return !('stack' in Error('1')) || 'stack' in new DOMException();
return !('stack' in new Error('1')) || 'stack' in new DOMException();
},
'web.dom-exception.to-string-tag': function () {
return typeof DOMException == 'function'
Expand Down
4 changes: 2 additions & 2 deletions tests/entries/unit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok('map' in load(NS, 'array/virtual'));
ok('from' in load(NS, 'array'));
ok(load(NS, 'array/splice')([1, 2, 3], 1, 2)[0] === 2);
ok(load(NS, 'error/constructor').Error(1, { cause: 7 }).cause === 7);
ok(new (load(NS, 'error/constructor').Error)(1, { cause: 7 }).cause === 7);
ok(typeof load(NS, 'error/to-string') == 'function');
ok(load(NS, 'error').Error(1, { cause: 7 }).cause === 7);
ok(new (load(NS, 'error').Error)(1, { cause: 7 }).cause === 7);
ok(load(NS, 'math/acosh')(1) === 0);
ok(Object.is(load(NS, 'math/asinh')(-0), -0));
ok(load(NS, 'math/atanh')(1) === Infinity);
Expand Down
22 changes: 17 additions & 5 deletions tests/eslint/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ const base = {
// unicorn
// enforce a specific parameter name in `catch` clauses
'unicorn/catch-error-name': [ERROR, { name: ERROR, ignore: [/^err/] }],
// prefer consistent types when spreading a ternary in an array literal
'unicorn/consistent-empty-array-spread': ERROR,
// enforce correct `Error` subclassing
'unicorn/custom-error-definition': ERROR,
// enforce passing a message value when throwing a built-in error
Expand All @@ -543,10 +545,14 @@ const base = {
'unicorn/no-console-spaces': ERROR,
// enforce the use of unicode escapes instead of hexadecimal escapes
'unicorn/no-hex-escape': ERROR,
// disallow invalid options in `fetch` and `Request`
'unicorn/no-invalid-fetch-options': ERROR,
// prevent calling `EventTarget#removeEventListener()` with the result of an expression
'unicorn/no-invalid-remove-event-listener': ERROR,
// disallow `if` statements as the only statement in `if` blocks without `else`
'unicorn/no-lonely-if': ERROR,
// disallow a magic number as the depth argument in `Array#flat`
'unicorn/no-magic-array-flat-depth': ERROR,
// enforce the use of `Buffer.from()` and `Buffer.alloc()` instead of the deprecated `new Buffer()`
'unicorn/no-new-buffer': ERROR,
// disallow passing single-element arrays to `Promise` methods
Expand Down Expand Up @@ -621,6 +627,8 @@ const base = {
'unicorn/prefer-object-from-entries': ERROR,
// prefer omitting the `catch` binding parameter
'unicorn/prefer-optional-catch-binding': ERROR,
// prefer using `structuredClone` to create a deep clone
'unicorn/prefer-structured-clone': ERROR,
// prefer using `Set#size` instead of `Array#length`
'unicorn/prefer-set-size': ERROR,
// prefer `String#replaceAll()` over regex searches with the global flag
Expand Down Expand Up @@ -1142,7 +1150,7 @@ const forbidES2023IntlBuiltIns = {
'es/no-intl-pluralrules-prototype-selectrange': ERROR,
};

const forbidModernESBuiltIns = {
const forbidModernBuiltIns = {
...forbidESAnnexBBuiltIns,
...forbidES5BuiltIns,
...forbidES2015BuiltIns,
Expand All @@ -1162,6 +1170,8 @@ const forbidModernESBuiltIns = {
...forbidES2021IntlBuiltIns,
...forbidES2022IntlBuiltIns,
...forbidES2023IntlBuiltIns,
// prefer using `structuredClone` to create a deep clone
'unicorn/prefer-structured-clone': OFF,
};

const polyfills = {
Expand Down Expand Up @@ -1208,7 +1218,7 @@ const nodePackages = {
// enforces the use of `catch()` on un-returned promises
'promise/catch-or-return': ERROR,
// disallow unsupported ECMAScript built-ins on the specified version
'node/no-unsupported-features/node-builtins': [ERROR, { version: PACKAGES_NODE_VERSIONS }],
'node/no-unsupported-features/node-builtins': [ERROR, { version: PACKAGES_NODE_VERSIONS, allowExperimental: false }],
// prefer `node:` protocol
'node/prefer-node-protocol': OFF,
// prefer promises
Expand All @@ -1224,6 +1234,8 @@ const nodePackages = {
'unicorn/prefer-node-protocol': OFF,
// prefer omitting the `catch` binding parameter
'unicorn/prefer-optional-catch-binding': OFF,
// prefer using `structuredClone` to create a deep clone
'unicorn/prefer-structured-clone': OFF,
...disable(forbidES5BuiltIns),
...disable(forbidES2015BuiltIns),
...disable(forbidES2016BuiltIns),
Expand All @@ -1250,8 +1262,8 @@ const nodePackages = {

const nodeDev = {
// disallow unsupported ECMAScript built-ins on the specified version
'node/no-unsupported-features/node-builtins': [ERROR, { version: DEV_NODE_VERSIONS, ignores: ['fetch'] }],
...disable(forbidModernESBuiltIns),
'node/no-unsupported-features/node-builtins': [ERROR, { version: DEV_NODE_VERSIONS, ignores: ['fetch'], allowExperimental: false }],
...disable(forbidModernBuiltIns),
...forbidES2023BuiltIns,
'es/no-array-prototype-findlast-findlastindex': OFF,
...forbidES2024BuiltIns,
Expand Down Expand Up @@ -1562,7 +1574,7 @@ export default [
'tests/@(unit-pure|worker)/**',
'tests/compat/@(browsers|hermes|node|rhino)-runner.js',
],
rules: forbidModernESBuiltIns,
rules: forbidModernBuiltIns,
},
{
files: [
Expand Down
67 changes: 51 additions & 16 deletions tests/eslint/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"eslint-plugin-es-x": "^7.6.0",
"eslint-plugin-import-x": "^0.5.0",
"eslint-plugin-jsonc": "^2.15.1",
"eslint-plugin-n": "^17.5.1",
"eslint-plugin-n": "^17.6.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-qunit": "^8.1.1",
"eslint-plugin-redos": "^4.5.0-beta.6",
"eslint-plugin-regexp": "^2.5.0",
"eslint-plugin-sonarjs": "^1.0.3",
"eslint-plugin-unicorn": "^52.0.0",
"eslint-plugin-unicorn": "^53.0.0",
"globals": "^15.2.0",
"jsonc-eslint-parser": "^2.4.0"
}
Expand Down
6 changes: 3 additions & 3 deletions tests/observables/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/unit-global/es.aggregate-error.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/throw-new-error -- testing */
const { create } = Object;

QUnit.test('AggregateError', assert => {
Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/es.array.flat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/no-magic-array-flat-depth -- testing */
import { DESCRIPTORS, STRICT } from '../helpers/constants.js';

QUnit.test('Array#flat', assert => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ QUnit.test('AsyncDisposableStack#3', assert => {
stack.use({ [Symbol.asyncDispose]: () => result += '6' });
stack.adopt({}, () => { throw new Error(5); });
stack.defer(() => result += '4');
stack.use({ [Symbol.asyncDispose]: () => Promise.reject(Error(3)) });
stack.use({ [Symbol.asyncDispose]: () => Promise.reject(new Error(3)) });
stack.adopt({}, () => Promise.resolve(result += '2'));
stack.defer(() => Promise.resolve(result += '1'));

Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/esnext.suppressed-error.constructor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/throw-new-error -- testing */
QUnit.test('SuppressedError', assert => {
assert.isFunction(SuppressedError);
assert.arity(SuppressedError, 3);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-global/web.dom-exception.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const errors = {
DataCloneError: { s: 'DATA_CLONE_ERR', c: 25, m: 1 },
};

const HAS_STACK = 'stack' in Error('1');
const HAS_STACK = 'stack' in new Error('1');

QUnit.test('DOMException', assert => {
assert.isFunction(DOMException);
Expand Down
1 change: 1 addition & 0 deletions tests/unit-pure/es.aggregate-error.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/throw-new-error -- testing */
import AggregateError from 'core-js-pure/es/aggregate-error';
import Symbol from 'core-js-pure/es/symbol';
import toString from 'core-js-pure/es/object/to-string';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ QUnit.test('AsyncDisposableStack#3', assert => {
stack.use({ [Symbol.asyncDispose]: () => result += '6' });
stack.adopt({}, () => { throw new Error(5); });
stack.defer(() => result += '4');
stack.use({ [Symbol.asyncDispose]: () => Promise.reject(Error(3)) });
stack.use({ [Symbol.asyncDispose]: () => Promise.reject(new Error(3)) });
stack.adopt({}, () => Promise.resolve(result += '2'));
stack.defer(() => Promise.resolve(result += '1'));

Expand Down
1 change: 1 addition & 0 deletions tests/unit-pure/esnext.suppressed-error.constructor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/throw-new-error -- testing */
import SuppressedError from 'core-js-pure/actual/suppressed-error';
import Symbol from 'core-js-pure/es/symbol';
import toString from 'core-js-pure/es/object/to-string';
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-pure/web.dom-exception.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const errors = {
DataCloneError: { s: 'DATA_CLONE_ERR', c: 25, m: 1 },
};

const HAS_STACK = 'stack' in Error('1');
const HAS_STACK = 'stack' in new Error('1');

QUnit.test('DOMException', assert => {
assert.isFunction(DOMException);
Expand Down

0 comments on commit 431a551

Please sign in to comment.