Skip to content

chore: use recommended restrict-plus-operands #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ module.exports = defineConfig({
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/restrict-plus-operands': 'warn',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
Expand Down
2 changes: 1 addition & 1 deletion scripts/apidoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ async function build(): Promise<void> {
.map((tag) => tag.text.trimEnd()) || [];

if (examples.length !== 0) {
console.log('Example-Length: ' + examples);
console.log('Example-Length:', examples);
content += examples.join('\n') + '\n';
}

Expand Down
2 changes: 1 addition & 1 deletion src/commerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Commerce {
symbol: string = ''
): string {
if (min < 0 || max < 0) {
return symbol + 0.0;
return `${symbol}${0.0}`;
}

const randValue = this.faker.datatype.number({ max: max, min: min });
Expand Down
15 changes: 10 additions & 5 deletions src/finance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Finance {
sum += Number(routingNumber[i + 2]) || 0;
}

return routingNumber + (Math.ceil(sum / 10) * 10 - sum);
return `${routingNumber}${Math.ceil(sum / 10) * 10 - sum}`;
}

/**
Expand Down Expand Up @@ -293,7 +293,12 @@ export class Finance {
* @method faker.finance.iban
*/
iban(formatted: boolean = false, countryCode: string): string {
let ibanFormat;
let ibanFormat: {
bban: Array<{ type: string; count: number }>;
country: string;
total?: number;
format?: string;
};
if (countryCode) {
const findFormat = (currentFormat) =>
currentFormat.country === countryCode;
Expand Down Expand Up @@ -341,12 +346,12 @@ export class Finance {
let checksum: string | number =
98 -
this.ibanLib.mod97(
this.ibanLib.toDigitString(s + ibanFormat.country + '00')
this.ibanLib.toDigitString(`${s}${ibanFormat.country}00`)
);
if (checksum < 10) {
checksum = '0' + checksum;
checksum = `0${checksum}`;
}
const iban = ibanFormat.country + checksum + s;
const iban = `${ibanFormat.country}${checksum}${s}`;
return formatted ? iban.match(/.{1,4}/g).join(' ') : iban;
}

Expand Down
25 changes: 7 additions & 18 deletions src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ export class Image {
if (typeof https !== 'undefined' && https === true) {
protocol = 'https://';
}
let url = protocol + 'placeimg.com/' + width + '/' + height;
let url = `${protocol}placeimg.com/${width}/${height}`;
if (typeof category !== 'undefined') {
url += '/' + category;
}

if (randomize) {
url += '?' + this.faker.datatype.number();
url += `?${this.faker.datatype.number()}`;
}

return url;
Expand Down Expand Up @@ -264,22 +264,11 @@ export class Image {
* @param color
*/
dataUri(width?: number, height?: number, color: string = 'grey'): string {
const svgString =
'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="' +
width +
'" height="' +
height +
'"><rect width="100%" height="100%" fill="' +
color +
'"/><text x="' +
width / 2 +
'" y="' +
height / 2 +
'" font-size="20" alignment-baseline="middle" text-anchor="middle" fill="white">' +
width +
'x' +
height +
'</text></svg>';
const svgString = `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="${width}" height="${height}"><rect width="100%" height="100%" fill="${color}"/><text x="${
width / 2
}" y="${
height / 2
}" font-size="20" alignment-baseline="middle" text-anchor="middle" fill="white">${width}x${height}</text></svg>`;
const rawPrefix = 'data:image/svg+xml;charset=UTF-8,';
return rawPrefix + encodeURIComponent(svgString);
}
Expand Down
6 changes: 3 additions & 3 deletions src/image_providers/lorempicsum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ export class LoremPicsum {
url += '/seed/' + seed;
}

url += '/' + width + '/' + height;
url += `/${width}/${height}`;

if (grayscale && blur) {
return url + '?grayscale' + '&blur=' + blur;
return `${url}?grayscale&blur=${blur}`;
}

if (grayscale) {
return url + '?grayscale';
}

if (blur) {
return url + '?blur=' + blur;
return `${url}?blur=${blur}`;
}

return url;
Expand Down
4 changes: 2 additions & 2 deletions src/image_providers/lorempixel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ export class Lorempixel {
width ||= 640;
height ||= 480;

let url = 'https://lorempixel.com/' + width + '/' + height;
let url = `https://lorempixel.com/${width}/${height}`;
if (typeof category !== 'undefined') {
url += '/' + category;
}

if (randomize) {
url += '?' + this.faker.datatype.number();
url += `?${this.faker.datatype.number()}`;
}

return url;
Expand Down
2 changes: 1 addition & 1 deletion src/image_providers/unsplash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Unsplash {
url += '/category/' + category;
}

url += '/' + width + 'x' + height;
url += `/${width}x${height}`;

if (typeof keyword !== 'undefined') {
const keywordFormat = new RegExp(
Expand Down
19 changes: 8 additions & 11 deletions src/internet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,9 @@ export class Internet {
* @method faker.internet.avatar
*/
avatar(): string {
return (
'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/' +
this.faker.datatype.number(1249) +
'.jpg'
);
return `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/${this.faker.datatype.number(
1249
)}.jpg`;
}

/**
Expand Down Expand Up @@ -240,18 +238,17 @@ export class Internet {
lastName ||= this.faker.name.lastName();
switch (this.faker.datatype.number(2)) {
case 0:
result = firstName + this.faker.datatype.number(99);
result = `${firstName}${this.faker.datatype.number(99)}`;
break;
case 1:
result =
firstName + this.faker.random.arrayElement(['.', '_']) + lastName;
break;
case 2:
result =
firstName +
this.faker.random.arrayElement(['.', '_']) +
lastName +
this.faker.datatype.number(99);
result = `${firstName}${this.faker.random.arrayElement([
'.',
'_',
])}${lastName}${this.faker.datatype.number(99)}`;
break;
}
result = result.toString().replace(/'/g, '');
Expand Down
2 changes: 1 addition & 1 deletion src/lorem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class Lorem {
'lorem.lines',
];
const randomLoremMethod = this.faker.random.arrayElement(loremMethods);
return this.faker.fake('{{' + randomLoremMethod + '}}');
return this.faker.fake(`{{${randomLoremMethod}}}`);
}

/**
Expand Down
35 changes: 19 additions & 16 deletions src/vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,15 @@ export class Vehicle {
*/
vin(): string {
const bannedChars = ['o', 'i', 'q'];
return (
this.faker.random.alphaNumeric(10, { bannedChars: bannedChars }) +
this.faker.random.alpha({
count: 1,
upcase: true,
bannedChars: bannedChars,
}) +
this.faker.random.alphaNumeric(1, { bannedChars: bannedChars }) +
this.faker.datatype.number({ min: 10000, max: 100000 })
) // return five digit #
return `${this.faker.random.alphaNumeric(10, {
bannedChars,
})}${this.faker.random.alpha({
count: 1,
upcase: true,
bannedChars,
})}${this.faker.random.alphaNumeric(1, {
bannedChars,
})}${this.faker.datatype.number({ min: 10000, max: 100000 })}` // return five digit #
.toUpperCase();
}

Expand All @@ -106,12 +105,16 @@ export class Vehicle {
* faker.vehicle.vrm() // 'MF56UPA'
*/
vrm(): string {
return (
this.faker.random.alpha({ count: 2, upcase: true }) +
this.faker.datatype.number({ min: 0, max: 9 }) +
this.faker.datatype.number({ min: 0, max: 9 }) +
this.faker.random.alpha({ count: 3, upcase: true })
).toUpperCase();
return `${this.faker.random.alpha({
count: 2,
upcase: true,
})}${this.faker.datatype.number({
min: 0,
max: 9,
})}${this.faker.datatype.number({
min: 0,
max: 9,
})}${this.faker.random.alpha({ count: 3, upcase: true })}`.toUpperCase();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/vendor/mersenne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function MersenneTwister19937(): void {

/* generates a random number on [0,0xffffffff]-interval */
//c//unsigned long genrand_int32(void)
this.genrand_int32 = function () {
this.genrand_int32 = function (): number {
//c//unsigned long y;
//c//static unsigned long mag01[2]={0x0UL, MATRIX_A};
let y: number;
Expand Down Expand Up @@ -271,7 +271,8 @@ function MersenneTwister19937(): void {
//c//double genrand_real3(void)
this.genrand_real3 = function (): number {
//c//return ((genrand_int32()) + 0.5)*(1.0/4294967296.0);
return (this.genrand_int32() + 0.5) * (1.0 / 4294967296.0);
// TODO @Shinigami92 2022-01-30: Rewrite this file to a class
return ((this.genrand_int32() as number) + 0.5) * (1.0 / 4294967296.0);
/* divided by 2^32 */
};

Expand Down
4 changes: 2 additions & 2 deletions src/vendor/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function exec<Method extends (args: Args) => string, Args extends any[]>(
if (now - startTime >= opts.maxTime) {
return errorMessage(
now,
'Exceeded maxTime:' + opts.maxTime,
`Exceeded maxTime: ${opts.maxTime}`,
// @ts-expect-error: we know that opts.startTime is defined
opts
);
Expand All @@ -96,7 +96,7 @@ export function exec<Method extends (args: Args) => string, Args extends any[]>(
if (opts.currentIterations >= opts.maxRetries) {
return errorMessage(
now,
'Exceeded maxRetries:' + opts.maxRetries,
`Exceeded maxRetries: ${opts.maxRetries}`,
// @ts-expect-error: we know that opts.startTime is defined
opts
);
Expand Down
Loading