Skip to content

Commit 9be890c

Browse files
committed
review eslint core rules: enable some rules for parameters
1 parent bc32a7f commit 9be890c

25 files changed

+43
-16
lines changed

packages/core-js-compat/compat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function getModules(filter) {
2525

2626
function normalizeModules(option) {
2727
// TODO: use `.flatMap` in core-js@4
28-
return new Set(Array.isArray(option) ? [].concat.apply([], option.map(getModules)) : getModules(option));
28+
return new Set(Array.isArray(option) ? [].concat(...option.map(getModules)) : getModules(option));
2929
}
3030

3131
function checkModule(name, targets) {

tests/eslint/eslint.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ const base = {
124124
camelcase: [ERROR, { properties: NEVER }],
125125
// enforce default clauses in switch statements to be last
126126
'default-case-last': ERROR,
127+
// enforce default parameters to be last
128+
'default-param-last': ERROR,
127129
// encourages use of dot notation whenever possible
128130
'dot-notation': [ERROR, { allowKeywords: true }],
129131
// require the use of === and !==
@@ -262,6 +264,10 @@ const base = {
262264
'prefer-exponentiation-operator': ERROR,
263265
// prefer `Object.hasOwn`
264266
'prefer-object-has-own': ERROR,
267+
// require rest parameters instead of `arguments`
268+
'prefer-rest-params': ERROR,
269+
// require spread operators instead of `.apply()`
270+
'prefer-spread': ERROR,
265271
// require template literals instead of string concatenation
266272
'prefer-template': ERROR,
267273
// require or disallow use of quotes around object literal property names
@@ -767,6 +773,10 @@ const es3 = {
767773
'prefer-exponentiation-operator': OFF,
768774
// prefer `Object.hasOwn`
769775
'prefer-object-has-own': OFF,
776+
// require rest parameters instead of `arguments`
777+
'prefer-rest-params': OFF,
778+
// require spread operators instead of `.apply()`
779+
'prefer-spread': OFF,
770780
// require template literals instead of string concatenation
771781
'prefer-template': OFF,
772782
// require or disallow use of quotes around object literal property names

tests/helpers/helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ export function patchRegExp$exec(run) {
139139
return assert => {
140140
const originalExec = RegExp.prototype.exec;
141141
// eslint-disable-next-line no-extend-native -- required for testing
142-
RegExp.prototype.exec = function () {
143-
return originalExec.apply(this, arguments);
142+
RegExp.prototype.exec = function (...args) {
143+
return originalExec.apply(this, args);
144144
};
145145
try {
146146
return run(assert);

tests/helpers/qunit-helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ assign(QUnit.assert, {
3333
: 'Enumerability is not applicable',
3434
});
3535
},
36-
epsilon(a, b, EPSILON = 1e-11, message) {
36+
epsilon(a, b, EPSILON = 1e-11, message = null) {
3737
const result = Math.abs(a - b) <= EPSILON;
3838
this.pushResult({
3939
result,

tests/unit-global/es.array.from.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable prefer-rest-params -- required for testing */
12
import { DESCRIPTORS, GLOBAL } from '../helpers/constants';
23
import { createIterable } from '../helpers/helpers';
34

tests/unit-global/es.array.is-array.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ QUnit.test('Array.isArray', assert => {
77
assert.nonEnumerable(Array, 'isArray');
88
assert.false(isArray({}));
99
assert.false(isArray(function () {
10+
// eslint-disable-next-line prefer-rest-params -- required for testing
1011
return arguments;
1112
}()));
1213
assert.true(isArray([]));

tests/unit-global/es.object.to-string.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ QUnit.test('Object#toString', assert => {
2020
assert.same(toString.call(/./), '[object RegExp]', 'regexp -> `RegExp`');
2121
assert.same(toString.call(new TypeError()), '[object Error]', 'new TypeError -> `Error`');
2222
assert.same(toString.call(function () {
23+
// eslint-disable-next-line prefer-rest-params -- required for testing
2324
return arguments;
2425
}()), '[object Arguments]', 'arguments -> `Arguments`');
2526
const constructors = [

tests/unit-global/es.regexp.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
QUnit.test('RegExp#test delegates to exec', assert => {
3-
const exec = function () {
3+
const exec = function (...args) {
44
execCalled = true;
5-
return /./.exec.apply(this, arguments);
5+
return /./.exec.apply(this, args);
66
};
77

88
let execCalled = false;

tests/unit-global/es.string.from-code-point.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable prefer-spread -- required for testing */
12
QUnit.test('String.fromCodePoint', assert => {
23
const { fromCodePoint } = String;
34
assert.isFunction(fromCodePoint);

tests/unit-global/es.string.match.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ QUnit.test('String#match delegates to @@match', assert => {
228228
});
229229

230230
QUnit.test('RegExp#@@match delegates to exec', assert => {
231-
const exec = function () {
231+
const exec = function (...args) {
232232
execCalled = true;
233-
return /./.exec.apply(this, arguments);
233+
return /./.exec.apply(this, args);
234234
};
235235

236236
let execCalled = false;

tests/unit-global/es.string.replace.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ QUnit.test('String.replace delegates to @@replace', assert => {
170170
});
171171

172172
QUnit.test('RegExp#@@replace delegates to exec', assert => {
173-
const exec = function () {
173+
const exec = function (...args) {
174174
execCalled = true;
175-
return /./.exec.apply(this, arguments);
175+
return /./.exec.apply(this, args);
176176
};
177177

178178
let execCalled = false;

tests/unit-global/es.string.search.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ QUnit.test('RegExp#@@search delegates to exec', assert => {
112112
let execCalled = false;
113113
let re = /b/;
114114
re.lastIndex = 7;
115-
re.exec = function () {
115+
re.exec = function (...args) {
116116
execCalled = true;
117-
return /./.exec.apply(this, arguments);
117+
return /./.exec.apply(this, args);
118118
};
119119
assert.deepEqual(re[Symbol.search]('abc'), 1);
120120
assert.true(execCalled);

tests/unit-global/es.string.split.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -735,18 +735,19 @@ QUnit.test('RegExp#@@split delegates to exec', assert => {
735735
let speciesCalled = false;
736736
let execSpeciesCalled = false;
737737
const re = /[24]/;
738-
re.exec = function () {
738+
re.exec = function (...args) {
739739
execCalled = true;
740-
return /./.exec.apply(this, arguments);
740+
return /./.exec.apply(this, args);
741741
};
742742
re.constructor = {
743743
// eslint-disable-next-line object-shorthand -- constructor
744-
[Symbol.species]: function (source, flags) {
744+
[Symbol.species]: function (...args) {
745+
const [source, flags] = args;
745746
const re2 = new RegExp(source, flags);
746747
speciesCalled = true;
747748
re2.exec = function () {
748749
execSpeciesCalled = true;
749-
return /./.exec.apply(this, arguments);
750+
return /./.exec.apply(this, args);
750751
};
751752
return re2;
752753
},

tests/unit-global/esnext.array.is-template-object.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ QUnit.test('Array.isTemplateObject', assert => {
1212
assert.false(isTemplateObject(null));
1313
assert.false(isTemplateObject({}));
1414
assert.false(isTemplateObject(function () {
15+
// eslint-disable-next-line prefer-rest-params -- required for testing
1516
return arguments;
1617
}()));
1718
assert.false(isTemplateObject([]));

tests/unit-global/esnext.function.is-callable.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ QUnit.test('Function.isCallable', assert => {
99
assert.nonEnumerable(Function, 'isCallable');
1010
assert.false(isCallable({}), 'object');
1111
assert.false(isCallable(function () {
12+
// eslint-disable-next-line prefer-rest-params -- required for testing
1213
return arguments;
1314
}()), 'arguments');
1415
assert.false(isCallable([]), 'array');

tests/unit-global/esnext.function.is-constructor.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ QUnit.test('Function.isConstructor', assert => {
99
assert.nonEnumerable(Function, 'isConstructor');
1010
assert.false(isConstructor({}), 'object');
1111
assert.false(isConstructor(function () {
12+
// eslint-disable-next-line prefer-rest-params -- required for testing
1213
return arguments;
1314
}()), 'arguments');
1415
assert.false(isConstructor([]), 'array');

tests/unit-pure/es.array.from.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable prefer-rest-params -- required for testing */
12
import { DESCRIPTORS } from '../helpers/constants';
23
import { createIterable } from '../helpers/helpers';
34

tests/unit-pure/es.array.is-array.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ QUnit.test('Array.isArray', assert => {
44
assert.isFunction(isArray);
55
assert.false(isArray({}));
66
assert.false(isArray(function () {
7+
// eslint-disable-next-line prefer-rest-params -- required for testing
78
return arguments;
89
}()));
910
assert.true(isArray([]));

tests/unit-pure/es.string.from-code-point.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable prefer-spread -- required for testing */
12
import fromCodePoint from 'core-js-pure/es/string/from-code-point';
23

34
QUnit.test('String.fromCodePoint', assert => {

tests/unit-pure/esnext.array.is-template-object.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ QUnit.test('Array.isTemplateObject', assert => {
1010
assert.false(isTemplateObject(null));
1111
assert.false(isTemplateObject({}));
1212
assert.false(isTemplateObject(function () {
13+
// eslint-disable-next-line prefer-rest-params -- required for testing
1314
return arguments;
1415
}()));
1516
assert.false(isTemplateObject([]));

tests/unit-pure/esnext.function.is-callable.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ QUnit.test('Function.isCallable', assert => {
77
assert.name(isCallable, 'isCallable');
88
assert.false(isCallable({}), 'object');
99
assert.false(isCallable(function () {
10+
// eslint-disable-next-line prefer-rest-params -- required for testing
1011
return arguments;
1112
}()), 'arguments');
1213
assert.false(isCallable([]), 'array');

tests/unit-pure/esnext.function.is-constructor.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ QUnit.test('Function.isConstructor', assert => {
77
assert.name(isConstructor, 'isConstructor');
88
assert.false(isConstructor({}), 'object');
99
assert.false(isConstructor(function () {
10+
// eslint-disable-next-line prefer-rest-params -- required for testing
1011
return arguments;
1112
}()), 'arguments');
1213
assert.false(isConstructor([]), 'array');

tests/unit-pure/helpers.get-iterator-method.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ QUnit.test('getIteratorMethod helper', assert => {
1010
assert.isIterator(iterFn.call(iterable));
1111
assert.isFunction(getIteratorMethod([]));
1212
assert.isFunction(getIteratorMethod(function () {
13+
// eslint-disable-next-line prefer-rest-params -- required for testing
1314
return arguments;
1415
}()));
1516
assert.isFunction(getIteratorMethod(Array.prototype));

tests/unit-pure/helpers.get-iterator.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ QUnit.test('getIterator helper', assert => {
66
assert.isFunction(getIterator);
77
assert.isIterator(getIterator([]));
88
assert.isIterator(getIterator(function () {
9+
// eslint-disable-next-line prefer-rest-params -- required for testing
910
return arguments;
1011
}()));
1112
assert.isIterator(getIterator(createIterable([])));

tests/unit-pure/helpers.is-iterable.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ QUnit.test('isIterable helper', assert => {
77
assert.true(isIterable(createIterable([])));
88
assert.true(isIterable([]));
99
assert.true(isIterable(function () {
10+
// eslint-disable-next-line prefer-rest-params -- required for testing
1011
return arguments;
1112
}()));
1213
assert.true(isIterable(Array.prototype));

0 commit comments

Comments
 (0)