Skip to content

Commit f222448

Browse files
authored
infra(unicorn): prefer-number-properties (#2452)
1 parent 8540381 commit f222448

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ module.exports = defineConfig({
6666
'unicorn/prefer-module': 'off',
6767
'unicorn/prefer-native-coercion-functions': 'off',
6868
'unicorn/prefer-negative-index': 'off',
69-
'unicorn/prefer-number-properties': 'off',
7069
'unicorn/prefer-optional-catch-binding': 'off',
7170
'unicorn/prefer-string-slice': 'off',
7271
'unicorn/prefer-ternary': 'off',

src/modules/commerce/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export class CommerceModule {
382382
const [group, groupRules] =
383383
this.faker.helpers.objectEntry(ISBN_LENGTH_RULES);
384384
const element = this.faker.string.numeric(8);
385-
const elementValue = parseInt(element.slice(0, -1));
385+
const elementValue = Number.parseInt(element.slice(0, -1));
386386

387387
const registrantLength = groupRules.find(
388388
([rangeMaximum]) => elementValue <= rangeMaximum
@@ -401,7 +401,7 @@ export class CommerceModule {
401401
let checksum = 0;
402402
for (let i = 0; i < variant - 1; i++) {
403403
const weight = variant === 10 ? i + 1 : i % 2 ? 3 : 1;
404-
checksum += weight * parseInt(isbn[i]);
404+
checksum += weight * Number.parseInt(isbn[i]);
405405
}
406406

407407
checksum = variant === 10 ? checksum % 11 : (10 - (checksum % 10)) % 10;

src/modules/date/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function toDate(
1616
fallback: () => Date
1717
): Date {
1818
date = new Date(date);
19-
if (isNaN(date.valueOf())) {
19+
if (Number.isNaN(date.valueOf())) {
2020
date = fallback();
2121
}
2222

src/modules/helpers/index.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ function getRepetitionsBasedOnQuantifierParameters(
6262
}
6363
} else if (quantifierMin != null && quantifierMax != null) {
6464
repetitions = faker.number.int({
65-
min: parseInt(quantifierMin),
66-
max: parseInt(quantifierMax),
65+
min: Number.parseInt(quantifierMin),
66+
max: Number.parseInt(quantifierMax),
6767
});
6868
} else if (quantifierMin != null && quantifierMax == null) {
69-
repetitions = parseInt(quantifierMin);
69+
repetitions = Number.parseInt(quantifierMin);
7070
}
7171

7272
return repetitions;
@@ -108,8 +108,8 @@ function legacyRegexpStringParse(
108108
let repetitions: number;
109109
let token = RANGE_REP_REG.exec(string);
110110
while (token != null) {
111-
min = parseInt(token[2]);
112-
max = parseInt(token[3]);
111+
min = Number.parseInt(token[2]);
112+
max = Number.parseInt(token[3]);
113113
// switch min and max
114114
if (min > max) {
115115
tmp = max;
@@ -128,7 +128,7 @@ function legacyRegexpStringParse(
128128
// Deal with repeat `{num}`
129129
token = REP_REG.exec(string);
130130
while (token != null) {
131-
repetitions = parseInt(token[2]);
131+
repetitions = Number.parseInt(token[2]);
132132
string =
133133
string.slice(0, token.index) +
134134
token[1].repeat(repetitions) +
@@ -139,8 +139,8 @@ function legacyRegexpStringParse(
139139

140140
token = RANGE_REG.exec(string);
141141
while (token != null) {
142-
min = parseInt(token[1]); // This time we are not capturing the char before `[]`
143-
max = parseInt(token[2]);
142+
min = Number.parseInt(token[1]); // This time we are not capturing the char before `[]`
143+
max = Number.parseInt(token[2]);
144144
// switch min and max
145145
if (min > max) {
146146
tmp = max;
@@ -462,7 +462,7 @@ export class SimpleHelpersModule {
462462
while (range != null) {
463463
if (!range[0].includes('-')) {
464464
// handle non-ranges
465-
if (isCaseInsensitive && isNaN(Number(range[0]))) {
465+
if (isCaseInsensitive && Number.isNaN(Number(range[0]))) {
466466
rangeCodes.push(
467467
range[0].toUpperCase().charCodeAt(0),
468468
range[0].toLowerCase().charCodeAt(0)
@@ -481,7 +481,10 @@ export class SimpleHelpersModule {
481481
}
482482

483483
for (let i = min; i <= max; i++) {
484-
if (isCaseInsensitive && isNaN(Number(String.fromCharCode(i)))) {
484+
if (
485+
isCaseInsensitive &&
486+
Number.isNaN(Number(String.fromCharCode(i)))
487+
) {
485488
const ch = String.fromCharCode(i);
486489
rangeCodes.push(
487490
ch.toUpperCase().charCodeAt(0),
@@ -556,8 +559,8 @@ export class SimpleHelpersModule {
556559
// Deal with quantifier ranges `{min,max}`
557560
token = RANGE_REP_REG.exec(pattern);
558561
while (token != null) {
559-
min = parseInt(token[2]);
560-
max = parseInt(token[3]);
562+
min = Number.parseInt(token[2]);
563+
max = Number.parseInt(token[3]);
561564
// throw error if min larger than max
562565
if (min > max) {
563566
throw new FakerError('Numbers out of order in {} quantifier.');
@@ -575,7 +578,7 @@ export class SimpleHelpersModule {
575578
// Deal with repeat `{num}`
576579
token = REP_REG.exec(pattern);
577580
while (token != null) {
578-
repetitions = parseInt(token[2]);
581+
repetitions = Number.parseInt(token[2]);
579582
pattern =
580583
pattern.slice(0, token.index) +
581584
token[1].repeat(repetitions) +
@@ -1046,7 +1049,7 @@ export class SimpleHelpersModule {
10461049
): T[keyof T] {
10471050
// ignore numeric keys added by TypeScript
10481051
const keys: Array<keyof T> = Object.keys(enumObject).filter((key) =>
1049-
isNaN(Number(key))
1052+
Number.isNaN(Number(key))
10501053
);
10511054
const randomKey = this.arrayElement(keys);
10521055
return enumObject[randomKey];

src/modules/helpers/luhn-check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function luhnChecksum(str: string): number {
2828
let sum = 0;
2929
let alternate = false;
3030
for (let i = str.length - 1; i >= 0; i--) {
31-
let n = parseInt(str.substring(i, i + 1));
31+
let n = Number.parseInt(str.substring(i, i + 1));
3232
if (alternate) {
3333
n *= 2;
3434
if (n > 9) {

test/modules/number.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ describe('number', () => {
319319
expect(binary).toBeTypeOf('string');
320320
expect(binary).toSatisfy(isBinary);
321321

322-
const binaryNum = parseInt(binary, 2);
322+
const binaryNum = Number.parseInt(binary, 2);
323323
expect(binaryNum).toBeLessThanOrEqual(5);
324324
});
325325

@@ -329,7 +329,7 @@ describe('number', () => {
329329
expect(binary).toBeTypeOf('string');
330330
expect(binary).toSatisfy(isBinary);
331331

332-
const binaryNum = parseInt(binary, 2);
332+
const binaryNum = Number.parseInt(binary, 2);
333333
expect(binaryNum).toBeLessThanOrEqual(255);
334334
expect(binaryNum).greaterThanOrEqual(15);
335335
});
@@ -362,7 +362,7 @@ describe('number', () => {
362362
expect(octal).toBeTypeOf('string');
363363
expect(octal).toSatisfy(validator.isOctal);
364364

365-
const octalNum = parseInt(octal, 8);
365+
const octalNum = Number.parseInt(octal, 8);
366366
expect(octalNum).toBeLessThanOrEqual(5);
367367
});
368368

@@ -372,7 +372,7 @@ describe('number', () => {
372372
expect(octal).toBeTypeOf('string');
373373
expect(octal).toSatisfy(validator.isOctal);
374374

375-
const octalNum = parseInt(octal, 8);
375+
const octalNum = Number.parseInt(octal, 8);
376376
expect(octalNum).toBeLessThanOrEqual(255);
377377
expect(octalNum).greaterThanOrEqual(15);
378378
});
@@ -412,7 +412,7 @@ describe('number', () => {
412412
expect(hex).toBeTypeOf('string');
413413
expect(hex).toSatisfy(validator.isHexadecimal);
414414

415-
const hexNum = parseInt(hex, 16);
415+
const hexNum = Number.parseInt(hex, 16);
416416
expect(hexNum).toBeLessThanOrEqual(255);
417417
expect(hexNum).greaterThanOrEqual(15);
418418
});

0 commit comments

Comments
 (0)