enable some new eslint-plugin-unicorn rules

This commit is contained in:
Denis Pushkarev
2024-10-05 09:56:10 +07:00
parent b6af247350
commit e91e2f9659
6 changed files with 19 additions and 12 deletions
+4 -4
View File
@@ -1311,11 +1311,11 @@ setTimeout(() => promise.catch(() => { /* empty */ }), 1e3);
```
In a browser on rejection, by default, you will see notify in the console, or you can add a custom handler and a handler on handling unhandled, [*example*](https://tinyurl.com/5n6nj2e8):
```js
window.addEventListener('unhandledrejection', e => console.log('unhandled', e.reason, e.promise));
window.addEventListener('rejectionhandled', e => console.log('handled', e.reason, e.promise));
globalThis.addEventListener('unhandledrejection', e => console.log('unhandled', e.reason, e.promise));
globalThis.addEventListener('rejectionhandled', e => console.log('handled', e.reason, e.promise));
// or
window.onunhandledrejection = e => console.log('unhandled', e.reason, e.promise);
window.onrejectionhandled = e => console.log('handled', e.reason, e.promise);
globalThis.onunhandledrejection = e => console.log('unhandled', e.reason, e.promise);
globalThis.onrejectionhandled = e => console.log('handled', e.reason, e.promise);
let promise = Promise.reject(42);
// => unhandled 42 [object Promise]
+2 -4
View File
@@ -182,9 +182,7 @@ export default {
// https://github.com/mdn/browser-compat-data/blob/main/browsers/chrome_android.json
// https://github.com/mdn/browser-compat-data/blob/main/docs/matching-browser-releases/index.md#version-numbers-for-chrome-for-android
ChromeToChromeAndroid(chrome) {
return chrome <= 18 ? 18
: chrome <= 25 ? 25
: chrome;
return chrome <= 18 ? 18 : Math.max(chrome, 25);
},
// https://medium.com/samsung-internet-dev
// https://github.com/mdn/browser-compat-data/blob/main/browsers/samsunginternet_android.json
@@ -309,7 +307,7 @@ export default {
],
// https://github.com/mdn/browser-compat-data/blob/main/browsers/firefox_android.json
FirefoxToFirefoxAndroid(firefox) {
return firefox <= 4 ? 4 : firefox;
return Math.max(firefox, 4);
},
// https://github.com/oven-sh/bun/releases
// This is the base data. Since it have no direct Safari equals by the
+1
View File
@@ -1,4 +1,5 @@
'use strict';
/* eslint-disable unicorn/prefer-global-this -- required */
var GLOBAL = typeof global != 'undefined' ? global : Function('return this')();
var results = GLOBAL.results = Object.create(null);
var data = GLOBAL.data;
+3 -3
View File
@@ -1,5 +1,5 @@
'use strict';
/* eslint-disable prefer-regex-literals, radix -- required for testing */
/* eslint-disable prefer-regex-literals, radix, unicorn/prefer-global-this -- required for testing */
/* eslint-disable regexp/no-empty-capturing-group, regexp/no-lazy-ends, regexp/no-useless-quantifier -- required for testing */
var GLOBAL = typeof global != 'undefined' ? global : Function('return this')();
var WHITESPACES = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002' +
@@ -266,14 +266,14 @@ function NATIVE_RAW_JSON() {
function IMMEDIATE() {
return setImmediate && clearImmediate && !(IS_BUN && (function () {
var version = global.Bun.version.split('.');
var version = Bun.version.split('.');
return version.length < 3 || version[0] === '0' && (version[1] < 3 || version[1] === '3' && version[2] === '0');
})());
}
function TIMERS() {
return !(/MSIE .\./.test(USERAGENT) || IS_BUN && (function () {
var version = global.Bun.version.split('.');
var version = Bun.version.split('.');
return version.length < 3 || version[0] === '0' && (version[1] < 3 || version[1] === '3' && version[2] === '0');
})());
}
+8
View File
@@ -560,6 +560,8 @@ const base = {
'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 consistent style for element existence checks with `indexOf()`, `lastIndexOf()`, `findIndex()`, and `findLastIndex()`
'unicorn/consistent-existence-index-check': ERROR,
// enforce correct `Error` subclassing
'unicorn/custom-error-definition': ERROR,
// enforce passing a message value when throwing a built-in error
@@ -646,12 +648,16 @@ const base = {
'unicorn/prefer-default-parameters': ERROR,
// prefer `EventTarget` over `EventEmitter`
'unicorn/prefer-event-target': ERROR,
// prefer `globalThis` over `window`, `self`, and `global`
'unicorn/prefer-global-this': ERROR,
// prefer `.includes()` over `.indexOf()` and `Array#some()` when checking for existence or non-existence
'unicorn/prefer-includes': ERROR,
// prefer reading a `JSON` file as a buffer
'unicorn/prefer-json-parse-buffer': ERROR,
// prefer using a logical operator over a ternary
'unicorn/prefer-logical-operator-over-ternary': ERROR,
// prefer `Math.min()` and `Math.max()` over ternaries for simple comparisons
'unicorn/prefer-math-min-max': ERROR,
// prefer modern `Math` APIs over legacy patterns
'unicorn/prefer-modern-math-apis': ERROR,
// prefer negative index over `.length - index` when possible
@@ -1091,6 +1097,8 @@ const forbidES5BuiltIns = {
'es/no-string-prototype-trim': ERROR,
// prefer `Date.now()` to get the number of milliseconds since the Unix Epoch
'unicorn/prefer-date-now': OFF,
// prefer `globalThis` over `window`, `self`, and `global`
'unicorn/prefer-global-this': OFF,
};
const forbidES2015BuiltIns = {
+1 -1
View File
@@ -1,4 +1,4 @@
/* eslint-disable no-restricted-globals -- safe */
/* eslint-disable no-restricted-globals, unicorn/prefer-global-this -- safe */
import { DESCRIPTORS } from '../helpers/constants.js';
QUnit.test('self', assert => {