Skip to content

Commit

Permalink
update eslint-plugin-unicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jan 11, 2021
1 parent 4a6dc47 commit 8632b8c
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,12 @@ const base = {
'unicorn/no-unused-properties': 'error',
// enforce lowercase identifier and uppercase value for number literals
'unicorn/number-literal-case': 'error',
// prefer `Array#indexOf` over `Array#findIndex`` when looking for the index of an item
'unicorn/prefer-array-index-of': 'error',
// prefer default parameters over reassignment
'unicorn/prefer-default-parameters': 'error',
// prefer `RegExp#test` over `String#match` and `RegExp#exec`
'unicorn/prefer-regexp-test': 'error',
// prefer `String#slice` over `String#{ substr, substring }`
'unicorn/prefer-string-slice': 'error',

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"eslint-plugin-optimize-regex": "^1.2.0",
"eslint-plugin-qunit": "^5.2.0",
"eslint-plugin-sonarjs": "~0.5.0",
"eslint-plugin-unicorn": "^25.0.1",
"eslint-plugin-unicorn": "^26.0.0",
"grunt": "^1.3.0",
"grunt-cli": "^1.3.2",
"grunt-contrib-clean": "^2.0.0",
Expand Down
8 changes: 4 additions & 4 deletions tests/pure/es.promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ QUnit.test('Promise.all', assert => {
let FakePromise2 = FakePromise1[Symbol.species] = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
FakePromise1.resolve = FakePromise2.resolve = bind(Promise.resolve, Promise);
FakePromise1.resolve = FakePromise2.resolve = bind(resolve, Promise);
assert.ok(all.call(FakePromise1, [1, 2, 3]) instanceof FakePromise1, 'subclassing, `this` pattern');
FakePromise1 = function () { /* empty */ };
FakePromise2 = function (executor) {
Expand All @@ -212,7 +212,7 @@ QUnit.test('Promise.all', assert => {
const FakePromise3 = function (executor) {
executor(() => { /* empty */ }, null);
};
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = bind(Promise.resolve, Promise);
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = bind(resolve, Promise);
assert.throws(() => {
all.call(FakePromise1, [1, 2, 3]);
}, 'NewPromiseCapability validations, #1');
Expand Down Expand Up @@ -263,7 +263,7 @@ QUnit.test('Promise.race', assert => {
let FakePromise2 = FakePromise1[Symbol.species] = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
FakePromise1.resolve = FakePromise2.resolve = bind(Promise.resolve, Promise);
FakePromise1.resolve = FakePromise2.resolve = bind(resolve, Promise);
assert.ok(race.call(FakePromise1, [1, 2, 3]) instanceof FakePromise1, 'subclassing, `this` pattern');
FakePromise1 = function () { /* empty */ };
FakePromise2 = function (executor) {
Expand All @@ -272,7 +272,7 @@ QUnit.test('Promise.race', assert => {
const FakePromise3 = function (executor) {
executor(() => { /* empty */ }, null);
};
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = bind(Promise.resolve, Promise);
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = bind(resolve, Promise);
assert.throws(() => {
race.call(FakePromise1, [1, 2, 3]);
}, 'NewPromiseCapability validations, #1');
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/es.array.find-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ QUnit.test('Array#findIndex', assert => {
assert.same(that, array, 'correct link to array in callback');
assert.same(this, context, 'correct callback context');
}, context);
// eslint-disable-next-line unicorn/prefer-array-index-of
assert.same([1, 3, NaN, 42, {}].findIndex(it => it === 42), 3);
// eslint-disable-next-line unicorn/prefer-array-index-of
assert.same([1, 3, NaN, 42, {}].findIndex(it => it === 43), -1);
if (STRICT) {
assert.throws(() => findIndex.call(null, 0), TypeError);
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/es.promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ QUnit.test('Promise.all', assert => {
FakePromise2 = FakePromise1[Symbol.species] = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
FakePromise1.resolve = FakePromise2.resolve = Promise.resolve.bind(Promise);
FakePromise1.resolve = FakePromise2.resolve = resolve.bind(Promise);
assert.ok(all.call(FakePromise1, [1, 2, 3]) instanceof FakePromise1, 'subclassing, `this` pattern');
FakePromise1 = function () { /* empty */ };
FakePromise2 = function (executor) {
Expand All @@ -223,7 +223,7 @@ QUnit.test('Promise.all', assert => {
const FakePromise3 = function (executor) {
executor(() => { /* empty */ }, null);
};
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = Promise.resolve.bind(Promise);
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = resolve.bind(Promise);
assert.throws(() => {
all.call(FakePromise1, [1, 2, 3]);
}, 'NewPromiseCapability validations, #1');
Expand Down Expand Up @@ -278,7 +278,7 @@ QUnit.test('Promise.race', assert => {
FakePromise2 = FakePromise1[Symbol.species] = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
FakePromise1.resolve = FakePromise2.resolve = Promise.resolve.bind(Promise);
FakePromise1.resolve = FakePromise2.resolve = resolve.bind(Promise);
assert.ok(race.call(FakePromise1, [1, 2, 3]) instanceof FakePromise1, 'subclassing, `this` pattern');
FakePromise1 = function () { /* empty */ };
FakePromise2 = function (executor) {
Expand All @@ -287,7 +287,7 @@ QUnit.test('Promise.race', assert => {
const FakePromise3 = function (executor) {
executor(() => { /* empty */ }, null);
};
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = Promise.resolve.bind(Promise);
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = resolve.bind(Promise);
assert.throws(() => {
race.call(FakePromise1, [1, 2, 3]);
}, 'NewPromiseCapability validations, #1');
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/es.string.trim-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ QUnit.test('String#trimRight', assert => {
});

QUnit.test('String#trimEnd', assert => {
const { trimEnd } = String.prototype;
const { trimEnd, trimRight } = String.prototype;
assert.isFunction(trimEnd);
assert.arity(trimEnd, 0);
assert.name(trimEnd, 'trimEnd');
assert.looksNative(trimEnd);
assert.nonEnumerable(String.prototype, 'trimEnd');
assert.same(trimEnd, String.prototype.trimRight, 'same #trimRight');
assert.same(trimEnd, trimRight, 'same #trimRight');
assert.strictEqual(' \n q w e \n '.trimEnd(), ' \n q w e', 'removes whitespaces at right side of string');
assert.strictEqual(WHITESPACES.trimEnd(), '', 'removes all whitespaces');
assert.strictEqual('\u200B\u0085'.trimEnd(), '\u200B\u0085', "shouldn't remove this symbols");
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/es.string.trim-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ QUnit.test('String#trimLeft', assert => {
});

QUnit.test('String#trimStart', assert => {
const { trimStart } = String.prototype;
const { trimStart, trimLeft } = String.prototype;
assert.isFunction(trimStart);
assert.arity(trimStart, 0);
assert.name(trimStart, 'trimStart');
assert.looksNative(trimStart);
assert.nonEnumerable(String.prototype, 'trimStart');
assert.same(trimStart, String.prototype.trimLeft, 'same #trimLeft');
assert.same(trimStart, trimLeft, 'same #trimLeft');
assert.strictEqual(' \n q w e \n '.trimStart(), 'q w e \n ', 'removes whitespaces at left side of string');
assert.strictEqual(WHITESPACES.trimStart(), '', 'removes all whitespaces');
assert.strictEqual('\u200B\u0085'.trimStart(), '\u200B\u0085', "shouldn't remove this symbols");
Expand Down
1 change: 1 addition & 0 deletions tests/tests/es.typed-array.find-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.findIndex', assert => {
assert.same(this, context, 'correct callback context');
}, context);
assert.same(new TypedArray([1, 2, 3]).findIndex(it => !(it % 2)), 1);
// eslint-disable-next-line unicorn/prefer-array-index-of
assert.same(new TypedArray([1, 2, 3]).findIndex(it => it === 4), -1);
let values = '';
let keys = '';
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/esnext.math.deg-per-rad.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
QUnit.test('Math.DEG_PER_RAD', assert => {
const { DEG_PER_RAD } = Math;
const { DEG_PER_RAD, PI } = Math;
assert.ok('DEG_PER_RAD' in Math, 'DEG_PER_RAD in Math');
assert.nonEnumerable(Math, 'DEG_PER_RAD');
assert.strictEqual(DEG_PER_RAD, Math.PI / 180, 'Is Math.PI / 180');
assert.strictEqual(DEG_PER_RAD, PI / 180, 'Is Math.PI / 180');
});
8 changes: 4 additions & 4 deletions tests/tests/esnext.math.degrees.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
QUnit.test('Math.degrees', assert => {
const { degrees } = Math;
const { degrees, PI } = Math;
assert.isFunction(degrees);
assert.name(degrees, 'degrees');
assert.arity(degrees, 1);
assert.looksNative(degrees);
assert.nonEnumerable(Math, 'degrees');
assert.same(degrees(0), 0);
assert.same(degrees(Math.PI / 2), 90);
assert.same(degrees(Math.PI), 180);
assert.same(degrees(3 * Math.PI / 2), 270);
assert.same(degrees(PI / 2), 90);
assert.same(degrees(PI), 180);
assert.same(degrees(3 * PI / 2), 270);
});
4 changes: 2 additions & 2 deletions tests/tests/esnext.math.rad-per-deg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
QUnit.test('Math.RAD_PER_DEG', assert => {
const { RAD_PER_DEG } = Math;
const { RAD_PER_DEG, PI } = Math;
assert.ok('RAD_PER_DEG' in Math, 'RAD_PER_DEG in Math');
assert.nonEnumerable(Math, 'RAD_PER_DEG');
assert.strictEqual(RAD_PER_DEG, 180 / Math.PI, 'Is 180 / Math.PI');
assert.strictEqual(RAD_PER_DEG, 180 / PI, 'Is 180 / Math.PI');
});
8 changes: 4 additions & 4 deletions tests/tests/esnext.math.radians.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
QUnit.test('Math.radians', assert => {
const { radians } = Math;
const { radians, PI } = Math;
assert.isFunction(radians);
assert.name(radians, 'radians');
assert.arity(radians, 1);
assert.looksNative(radians);
assert.nonEnumerable(Math, 'radians');
assert.same(radians(0), 0);
assert.same(radians(90), Math.PI / 2);
assert.same(radians(180), Math.PI);
assert.same(radians(270), 3 * Math.PI / 2);
assert.same(radians(90), PI / 2);
assert.same(radians(180), PI);
assert.same(radians(270), 3 * PI / 2);
});

0 comments on commit 8632b8c

Please sign in to comment.