diff --git a/.eslintrc.js b/.eslintrc.js index 0b53d7785a4a..b6d29da1ecdb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -394,6 +394,8 @@ const base = { 'unicorn/no-lonely-if': ERROR, // forbid classes that only have static members 'unicorn/no-static-only-class': ERROR, + // disallow `then` property + 'unicorn/no-thenable': ERROR, // disallow unreadable array destructuring 'unicorn/no-unreadable-array-destructuring': ERROR, // disallow unused object properties @@ -402,6 +404,8 @@ const base = { 'unicorn/no-useless-fallback-in-spread': ERROR, // disallow useless array length check 'unicorn/no-useless-length-check': ERROR, + // disallow returning / yielding `Promise.{ resolve, reject }` in async functions or promise callbacks + 'unicorn/no-useless-promise-resolve-reject': ERROR, // disallow useless spread 'unicorn/no-useless-spread': ERROR, // enforce lowercase identifier and uppercase value for number literals @@ -412,10 +416,14 @@ const base = { 'unicorn/prefer-code-point': ERROR, // prefer default parameters over reassignment 'unicorn/prefer-default-parameters': ERROR, + // prefer reading a `JSON` file as a buffer + 'unicorn/prefer-json-parse-buffer': ERROR, // prefer `String#slice` over `String#{ substr, substring }` 'unicorn/prefer-string-slice': ERROR, // prefer `switch` over multiple `else-if` 'unicorn/prefer-switch': [ERROR, { minimumCases: 3 }], + // enforce consistent relative `URL` style + 'unicorn/relative-url-style': [ERROR, ALWAYS], // enforce using the separator argument with `Array#join()` 'unicorn/require-array-join-separator': ERROR, // enforce using the digits argument with `Number#toFixed()` diff --git a/package.json b/package.json index f9d9bffa38e5..a218a21d6853 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "eslint-plugin-qunit": "^7.2.0", "eslint-plugin-regexp": "^1.5.1", "eslint-plugin-sonarjs": "~0.11.0", - "eslint-plugin-unicorn": "^39.0.0", + "eslint-plugin-unicorn": "^40.0.0", "jsonc-eslint-parser": "^2.0.4", "karma": "^6.3.9", "karma-phantomjs-launcher": "~1.0.4", diff --git a/packages/core-js/internals/native-url.js b/packages/core-js/internals/native-url.js index b9ac5878db81..8435fff5ffdd 100644 --- a/packages/core-js/internals/native-url.js +++ b/packages/core-js/internals/native-url.js @@ -5,6 +5,7 @@ var IS_PURE = require('../internals/is-pure'); var ITERATOR = wellKnownSymbol('iterator'); module.exports = !fails(function () { + // eslint-disable-next-line unicorn/relative-url-style -- required for testing var url = new URL('b?a=1&b=2&c=3', 'http://a'); var searchParams = url.searchParams; var result = ''; diff --git a/packages/core-js/modules/es.promise.finally.js b/packages/core-js/modules/es.promise.finally.js index eb7153430b85..d105b67d237d 100644 --- a/packages/core-js/modules/es.promise.finally.js +++ b/packages/core-js/modules/es.promise.finally.js @@ -11,6 +11,7 @@ var redefine = require('../internals/redefine'); // Safari bug https://bugs.webkit.org/show_bug.cgi?id=200829 var NON_GENERIC = !!NativePromise && fails(function () { + // eslint-disable-next-line unicorn/no-thenable -- required for testing NativePromise.prototype['finally'].call({ then: function () { /* empty */ } }, function () { /* empty */ }); }); diff --git a/packages/core-js/modules/es.promise.js b/packages/core-js/modules/es.promise.js index 9541ac54a544..b6a15faf7c2a 100644 --- a/packages/core-js/modules/es.promise.js +++ b/packages/core-js/modules/es.promise.js @@ -265,6 +265,7 @@ if (FORCED) { Internal.prototype = redefineAll(PromisePrototype, { // `Promise.prototype.then` method // https://tc39.es/ecma262/#sec-promise.prototype.then + // eslint-disable-next-line unicorn/no-thenable -- safe then: function then(onFulfilled, onRejected) { var state = getInternalPromiseState(this); var reaction = newPromiseCapability(speciesConstructor(this, PromiseConstructor)); diff --git a/packages/core-js/postinstall.js b/packages/core-js/postinstall.js index 144aa16474c4..e366c39865d8 100644 --- a/packages/core-js/postinstall.js +++ b/packages/core-js/postinstall.js @@ -38,7 +38,7 @@ function isBannerRequired() { try { var DELTA = Date.now() - fs.statSync(file).mtime; if (DELTA >= 0 && DELTA < MINUTE * 3) { - banners = JSON.parse(fs.readFileSync(file, 'utf8')); + banners = JSON.parse(fs.readFileSync(file)); if (banners.indexOf(BANNER) !== -1) return false; } } catch (error) { diff --git a/tests/compat/tests.js b/tests/compat/tests.js index 060b20126392..57648140993c 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -65,6 +65,7 @@ var SYMBOLS_SUPPORT = function () { }; var URL_AND_URL_SEARCH_PARAMS_SUPPORT = function () { + // eslint-disable-next-line unicorn/relative-url-style -- required for testing var url = new URL('b?a=1&b=2&c=3', 'http://a'); var searchParams = url.searchParams; var result = ''; @@ -805,6 +806,7 @@ GLOBAL.tests = { return Promise.any; }, 'es.promise.finally': [PROMISES_SUPPORT, function () { + // eslint-disable-next-line unicorn/no-thenable -- required for testing return Promise.prototype['finally'].call({ then: function () { return this; } }, function () { /* empty */ }); }], 'es.reflect.apply': function () { diff --git a/tests/pure/es.promise.js b/tests/pure/es.promise.js index 830d4f80155f..d85f95a5d893 100644 --- a/tests/pure/es.promise.js +++ b/tests/pure/es.promise.js @@ -1,3 +1,4 @@ +/* eslint-disable unicorn/no-thenable -- required for testing */ import { DESCRIPTORS, GLOBAL, PROTO, STRICT } from '../helpers/constants'; import { createIterable } from '../helpers/helpers'; diff --git a/tests/pure/web.url.js b/tests/pure/web.url.js index 197b2abea52b..c7c2ebe45f27 100644 --- a/tests/pure/web.url.js +++ b/tests/pure/web.url.js @@ -1,4 +1,4 @@ -/* eslint-disable es/no-object-getownpropertydescriptor -- safe */ +/* eslint-disable es/no-object-getownpropertydescriptor, unicorn/relative-url-style -- required for testing */ import { DESCRIPTORS, NODE } from '../helpers/constants'; import urlTestData from '../wpt-url-resources/urltestdata'; import settersTestData from '../wpt-url-resources/setters'; diff --git a/tests/tests/es.promise.js b/tests/tests/es.promise.js index 4f143d4be37b..dec783e23959 100644 --- a/tests/tests/es.promise.js +++ b/tests/tests/es.promise.js @@ -1,3 +1,4 @@ +/* eslint-disable unicorn/no-thenable -- required for testing */ import { DESCRIPTORS, GLOBAL, NATIVE, PROTO, STRICT } from '../helpers/constants'; import { createIterable } from '../helpers/helpers'; diff --git a/tests/tests/web.url.js b/tests/tests/web.url.js index 4112d01d3c5a..05934b0d1080 100644 --- a/tests/tests/web.url.js +++ b/tests/tests/web.url.js @@ -1,3 +1,4 @@ +/* eslint-disable unicorn/relative-url-style -- required for testing */ import { DESCRIPTORS, NODE } from '../helpers/constants'; import urlTestData from '../wpt-url-resources/urltestdata'; import settersTestData from '../wpt-url-resources/setters';