Skip to content

Commit b35e68e

Browse files
committed
enable sonar/inconsistent-function-call
1 parent 0d8fe67 commit b35e68e

20 files changed

+46
-25
lines changed

packages/core-js-compat/helpers.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22
// eslint-disable-next-line es/no-object-hasown -- safe
33
const has = Object.hasOwn || Function.call.bind({}.hasOwnProperty);
44

5-
function semver(input) {
6-
if (input instanceof semver) return input;
7-
// eslint-disable-next-line new-cap -- ok
8-
if (!(this instanceof semver)) return new semver(input);
9-
const match = /(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(input);
10-
if (!match) throw new TypeError(`Invalid version: ${ input }`);
11-
const [, $major, $minor, $patch] = match;
12-
this.major = +$major;
13-
this.minor = $minor ? +$minor : 0;
14-
this.patch = $patch ? +$patch : 0;
5+
const VERSION_PATTERN = /(\d+)(?:\.(\d+))?(?:\.(\d+))?/;
6+
7+
class SemVer {
8+
constructor(input) {
9+
const match = VERSION_PATTERN.exec(input);
10+
if (!match) throw new TypeError(`Invalid version: ${ input }`);
11+
const [, $major, $minor, $patch] = match;
12+
this.major = +$major;
13+
this.minor = $minor ? +$minor : 0;
14+
this.patch = $patch ? +$patch : 0;
15+
}
16+
toString() {
17+
return `${ this.major }.${ this.minor }.${ this.patch }`;
18+
}
1519
}
1620

17-
semver.prototype.toString = function () {
18-
return `${ this.major }.${ this.minor }.${ this.patch }`;
19-
};
21+
function semver(input) {
22+
return input instanceof SemVer ? input : new SemVer(input);
23+
}
2024

2125
function compare($a, operator, $b) {
2226
const a = semver($a);

packages/core-js/internals/array-buffer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ if (!NATIVE_ARRAY_BUFFER) {
205205
});
206206
} else {
207207
var INCORRECT_ARRAY_BUFFER_NAME = PROPER_FUNCTION_NAME && NativeArrayBuffer.name !== ARRAY_BUFFER;
208-
/* eslint-disable no-new -- required for testing */
208+
/* eslint-disable no-new, sonar/inconsistent-function-call -- required for testing */
209209
if (!fails(function () {
210210
NativeArrayBuffer(1);
211211
}) || !fails(function () {
@@ -216,7 +216,7 @@ if (!NATIVE_ARRAY_BUFFER) {
216216
new NativeArrayBuffer(NaN);
217217
return NativeArrayBuffer.length !== 1 || INCORRECT_ARRAY_BUFFER_NAME && !CONFIGURABLE_FUNCTION_NAME;
218218
})) {
219-
/* eslint-enable no-new -- required for testing */
219+
/* eslint-enable no-new, sonar/inconsistent-function-call -- required for testing */
220220
$ArrayBuffer = function ArrayBuffer(length) {
221221
anInstance(this, ArrayBufferPrototype);
222222
return inheritIfRequired(new NativeArrayBuffer(toIndex(length)), this, $ArrayBuffer);

packages/core-js/internals/typed-array-constructors-require-wrappers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
/* eslint-disable no-new -- required for testing */
2+
/* eslint-disable no-new, sonar/inconsistent-function-call -- required for testing */
33
var globalThis = require('../internals/global-this');
44
var fails = require('../internals/fails');
55
var checkCorrectnessOfIteration = require('../internals/check-correctness-of-iteration');

packages/core-js/modules/es.regexp.constructor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var BASE_FORCED = DESCRIPTORS &&
4646
(!CORRECT_NEW || MISSED_STICKY || UNSUPPORTED_DOT_ALL || UNSUPPORTED_NCG || fails(function () {
4747
re2[MATCH] = false;
4848
// RegExp constructor can alter flags and IsRegExp works correct with @@match
49+
// eslint-disable-next-line sonar/inconsistent-function-call -- required for testing
4950
return NativeRegExp(re1) !== re1 || NativeRegExp(re2) === re2 || String(NativeRegExp(re1, 'i')) !== '/a/i';
5051
}));
5152

packages/core-js/modules/es.symbol.description.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ if (DESCRIPTORS && isCallable(NativeSymbol) && (!('description' in SymbolPrototy
2424
var SymbolWrapper = function Symbol() {
2525
var description = arguments.length < 1 || arguments[0] === undefined ? undefined : toString(arguments[0]);
2626
var result = isPrototypeOf(SymbolPrototype, this)
27+
// eslint-disable-next-line sonar/inconsistent-function-call -- ok
2728
? new NativeSymbol(description)
2829
// in Edge 13, String(Symbol(undefined)) === 'Symbol(undefined)'
2930
: description === undefined ? NativeSymbol() : NativeSymbol(description);

tests/eslint/eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ const base = {
696696
'sonar/expression-complexity': [OFF, { max: 3 }],
697697
// `in` should not be used with primitive types
698698
'sonar/in-operator-type-error': ERROR,
699+
// functions should be called consistently with or without `new`
700+
'sonar/inconsistent-function-call': ERROR,
699701

700702
// sonarjs
701703
// collection sizes and array length comparisons should make sense

tests/unit-global/es.error.cause.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable sonar/inconsistent-function-call -- required for testing */
12
import { GLOBAL, PROTO } from '../helpers/constants.js';
23

34
const { create } = Object;

tests/unit-global/es.typed-array.constructors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ if (DESCRIPTORS) {
173173
assert.throws(() => new TypedArray(new ArrayBuffer(8), 16), 'If newByteLength < 0, throw a RangeError exception');
174174
assert.throws(() => new TypedArray(new ArrayBuffer(24), 8, 24), 'If offset+newByteLength > bufferByteLength, throw a RangeError exception');
175175
}
176+
// eslint-disable-next-line sonar/inconsistent-function-call -- required for testing
176177
assert.throws(() => TypedArray(1), TypeError, 'throws without `new`');
177178
assert.same(TypedArray[Symbol.species], TypedArray, '@@species');
178179
});

tests/unit-pure/es.aggregate-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable unicorn/throw-new-error -- testing */
1+
/* eslint-disable unicorn/throw-new-error, sonar/inconsistent-function-call -- required for testing */
22
import AggregateError from 'core-js-pure/es/aggregate-error';
33
import Symbol from 'core-js-pure/es/symbol';
44
import toString from 'core-js-pure/es/object/to-string';

tests/unit-pure/es.error.cause.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable sonar/inconsistent-function-call -- required for testing */
12
import { PROTO } from '../helpers/constants.js';
23

34
import path from 'core-js-pure/es/error';

0 commit comments

Comments
 (0)