diff --git a/.eslintrc.js b/.eslintrc.js index 6a01e343588..ea9fadda254 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -66,7 +66,6 @@ module.exports = defineConfig({ 'unicorn/prefer-module': 'off', 'unicorn/prefer-native-coercion-functions': 'off', 'unicorn/prefer-negative-index': 'off', - 'unicorn/prefer-number-properties': 'off', 'unicorn/prefer-optional-catch-binding': 'off', 'unicorn/prefer-string-slice': 'off', 'unicorn/prefer-ternary': 'off', diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index 2464af03020..18147dcb2e8 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -382,7 +382,7 @@ export class CommerceModule { const [group, groupRules] = this.faker.helpers.objectEntry(ISBN_LENGTH_RULES); const element = this.faker.string.numeric(8); - const elementValue = parseInt(element.slice(0, -1)); + const elementValue = Number.parseInt(element.slice(0, -1)); const registrantLength = groupRules.find( ([rangeMaximum]) => elementValue <= rangeMaximum @@ -401,7 +401,7 @@ export class CommerceModule { let checksum = 0; for (let i = 0; i < variant - 1; i++) { const weight = variant === 10 ? i + 1 : i % 2 ? 3 : 1; - checksum += weight * parseInt(isbn[i]); + checksum += weight * Number.parseInt(isbn[i]); } checksum = variant === 10 ? checksum % 11 : (10 - (checksum % 10)) % 10; diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts index 8f7efaaeed4..e93be54d90f 100644 --- a/src/modules/date/index.ts +++ b/src/modules/date/index.ts @@ -16,7 +16,7 @@ function toDate( fallback: () => Date ): Date { date = new Date(date); - if (isNaN(date.valueOf())) { + if (Number.isNaN(date.valueOf())) { date = fallback(); } diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 81007156995..4c64be4e98c 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -62,11 +62,11 @@ function getRepetitionsBasedOnQuantifierParameters( } } else if (quantifierMin != null && quantifierMax != null) { repetitions = faker.number.int({ - min: parseInt(quantifierMin), - max: parseInt(quantifierMax), + min: Number.parseInt(quantifierMin), + max: Number.parseInt(quantifierMax), }); } else if (quantifierMin != null && quantifierMax == null) { - repetitions = parseInt(quantifierMin); + repetitions = Number.parseInt(quantifierMin); } return repetitions; @@ -108,8 +108,8 @@ function legacyRegexpStringParse( let repetitions: number; let token = RANGE_REP_REG.exec(string); while (token != null) { - min = parseInt(token[2]); - max = parseInt(token[3]); + min = Number.parseInt(token[2]); + max = Number.parseInt(token[3]); // switch min and max if (min > max) { tmp = max; @@ -128,7 +128,7 @@ function legacyRegexpStringParse( // Deal with repeat `{num}` token = REP_REG.exec(string); while (token != null) { - repetitions = parseInt(token[2]); + repetitions = Number.parseInt(token[2]); string = string.slice(0, token.index) + token[1].repeat(repetitions) + @@ -139,8 +139,8 @@ function legacyRegexpStringParse( token = RANGE_REG.exec(string); while (token != null) { - min = parseInt(token[1]); // This time we are not capturing the char before `[]` - max = parseInt(token[2]); + min = Number.parseInt(token[1]); // This time we are not capturing the char before `[]` + max = Number.parseInt(token[2]); // switch min and max if (min > max) { tmp = max; @@ -462,7 +462,7 @@ export class SimpleHelpersModule { while (range != null) { if (!range[0].includes('-')) { // handle non-ranges - if (isCaseInsensitive && isNaN(Number(range[0]))) { + if (isCaseInsensitive && Number.isNaN(Number(range[0]))) { rangeCodes.push( range[0].toUpperCase().charCodeAt(0), range[0].toLowerCase().charCodeAt(0) @@ -481,7 +481,10 @@ export class SimpleHelpersModule { } for (let i = min; i <= max; i++) { - if (isCaseInsensitive && isNaN(Number(String.fromCharCode(i)))) { + if ( + isCaseInsensitive && + Number.isNaN(Number(String.fromCharCode(i))) + ) { const ch = String.fromCharCode(i); rangeCodes.push( ch.toUpperCase().charCodeAt(0), @@ -556,8 +559,8 @@ export class SimpleHelpersModule { // Deal with quantifier ranges `{min,max}` token = RANGE_REP_REG.exec(pattern); while (token != null) { - min = parseInt(token[2]); - max = parseInt(token[3]); + min = Number.parseInt(token[2]); + max = Number.parseInt(token[3]); // throw error if min larger than max if (min > max) { throw new FakerError('Numbers out of order in {} quantifier.'); @@ -575,7 +578,7 @@ export class SimpleHelpersModule { // Deal with repeat `{num}` token = REP_REG.exec(pattern); while (token != null) { - repetitions = parseInt(token[2]); + repetitions = Number.parseInt(token[2]); pattern = pattern.slice(0, token.index) + token[1].repeat(repetitions) + @@ -1046,7 +1049,7 @@ export class SimpleHelpersModule { ): T[keyof T] { // ignore numeric keys added by TypeScript const keys: Array = Object.keys(enumObject).filter((key) => - isNaN(Number(key)) + Number.isNaN(Number(key)) ); const randomKey = this.arrayElement(keys); return enumObject[randomKey]; diff --git a/src/modules/helpers/luhn-check.ts b/src/modules/helpers/luhn-check.ts index 7d841878261..ba68b41d470 100644 --- a/src/modules/helpers/luhn-check.ts +++ b/src/modules/helpers/luhn-check.ts @@ -28,7 +28,7 @@ function luhnChecksum(str: string): number { let sum = 0; let alternate = false; for (let i = str.length - 1; i >= 0; i--) { - let n = parseInt(str.substring(i, i + 1)); + let n = Number.parseInt(str.substring(i, i + 1)); if (alternate) { n *= 2; if (n > 9) { diff --git a/test/modules/number.spec.ts b/test/modules/number.spec.ts index 79b14261e31..3033c63b0f6 100644 --- a/test/modules/number.spec.ts +++ b/test/modules/number.spec.ts @@ -319,7 +319,7 @@ describe('number', () => { expect(binary).toBeTypeOf('string'); expect(binary).toSatisfy(isBinary); - const binaryNum = parseInt(binary, 2); + const binaryNum = Number.parseInt(binary, 2); expect(binaryNum).toBeLessThanOrEqual(5); }); @@ -329,7 +329,7 @@ describe('number', () => { expect(binary).toBeTypeOf('string'); expect(binary).toSatisfy(isBinary); - const binaryNum = parseInt(binary, 2); + const binaryNum = Number.parseInt(binary, 2); expect(binaryNum).toBeLessThanOrEqual(255); expect(binaryNum).greaterThanOrEqual(15); }); @@ -362,7 +362,7 @@ describe('number', () => { expect(octal).toBeTypeOf('string'); expect(octal).toSatisfy(validator.isOctal); - const octalNum = parseInt(octal, 8); + const octalNum = Number.parseInt(octal, 8); expect(octalNum).toBeLessThanOrEqual(5); }); @@ -372,7 +372,7 @@ describe('number', () => { expect(octal).toBeTypeOf('string'); expect(octal).toSatisfy(validator.isOctal); - const octalNum = parseInt(octal, 8); + const octalNum = Number.parseInt(octal, 8); expect(octalNum).toBeLessThanOrEqual(255); expect(octalNum).greaterThanOrEqual(15); }); @@ -412,7 +412,7 @@ describe('number', () => { expect(hex).toBeTypeOf('string'); expect(hex).toSatisfy(validator.isHexadecimal); - const hexNum = parseInt(hex, 16); + const hexNum = Number.parseInt(hex, 16); expect(hexNum).toBeLessThanOrEqual(255); expect(hexNum).greaterThanOrEqual(15); });