Skip to content

Commit d4125e2

Browse files
authored
chore: use explicit-module-boundary-types (#361)
1 parent 730ca6a commit d4125e2

File tree

11 files changed

+126
-24
lines changed

11 files changed

+126
-24
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = defineConfig({
3131

3232
'@typescript-eslint/ban-ts-comment': 'warn',
3333
'@typescript-eslint/consistent-type-imports': 'error',
34+
'@typescript-eslint/explicit-module-boundary-types': 'error',
3435
'@typescript-eslint/no-inferrable-types': [
3536
'error',
3637
{ ignoreParameters: true },

src/address.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class Address {
4747
* @method faker.address.zipCode
4848
* @param format
4949
*/
50-
zipCode(format?: string) {
50+
zipCode(format?: string): string {
5151
// if zip format is not specified, use the zip format defined for the locale
5252
if (typeof format === 'undefined') {
5353
const localeFormat = this.faker.definitions.address.postcode;
@@ -70,7 +70,7 @@ export class Address {
7070
* @method faker.address.zipCodeByState
7171
* @param state
7272
*/
73-
zipCodeByState(state: string) {
73+
zipCodeByState(state: string): string | number {
7474
const zipRange = this.faker.definitions.address.postcode_by_state[state];
7575
if (zipRange) {
7676
return this.faker.datatype.number(zipRange);
@@ -94,7 +94,7 @@ export class Address {
9494
* @method faker.address.city
9595
* @param format
9696
*/
97-
city(format?: string | number) {
97+
city(format?: string | number): string {
9898
const formats = [
9999
'{{address.cityPrefix}} {{name.firstName}}{{address.citySuffix}}',
100100
'{{address.cityPrefix}} {{name.firstName}}',
@@ -353,7 +353,7 @@ export class Address {
353353
* @method faker.address.direction
354354
* @param useAbbr return direction abbreviation. defaults to false
355355
*/
356-
direction(useAbbr: boolean = false) {
356+
direction(useAbbr: boolean = false): string {
357357
if (!useAbbr) {
358358
return this.faker.random.arrayElement(
359359
this.faker.definitions.address.direction

src/helpers.ts

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,103 @@
11
import type { Faker } from '.';
22

3+
export interface Card {
4+
name: string;
5+
username: string;
6+
email: string;
7+
address: {
8+
streetA: string;
9+
streetB: string;
10+
streetC: string;
11+
streetD: string;
12+
city: string;
13+
state: string;
14+
country: string;
15+
zipcode: string;
16+
geo: {
17+
lat: string;
18+
lng: string;
19+
};
20+
};
21+
phone: string;
22+
website: string;
23+
company: {
24+
name: string;
25+
catchPhrase: string;
26+
bs: string;
27+
};
28+
posts: Array<{
29+
words: string;
30+
sentence: string;
31+
sentences: string;
32+
paragraph: string;
33+
}>;
34+
accountHistory: Array<{
35+
amount: string;
36+
date: Date;
37+
business: string;
38+
name: string;
39+
type: string;
40+
account: string;
41+
}>;
42+
}
43+
44+
export interface ContextualCard {
45+
name: string;
46+
username: string;
47+
avatar: string;
48+
email: string;
49+
dob: Date;
50+
phone: string;
51+
address: {
52+
street: string;
53+
suite: string;
54+
city: string;
55+
zipcode: string;
56+
geo: {
57+
lat: string;
58+
lng: string;
59+
};
60+
};
61+
website: string;
62+
company: {
63+
name: string;
64+
catchPhrase: string;
65+
bs: string;
66+
};
67+
}
68+
69+
export interface UserCard {
70+
name: string;
71+
username: string;
72+
email: string;
73+
address: {
74+
street: string;
75+
suite: string;
76+
city: string;
77+
zipcode: string;
78+
geo: {
79+
lat: string;
80+
lng: string;
81+
};
82+
};
83+
phone: string;
84+
website: string;
85+
company: {
86+
name: string;
87+
catchPhrase: string;
88+
bs: string;
89+
};
90+
}
91+
92+
export interface Transaction {
93+
amount: string;
94+
date: Date;
95+
business: string;
96+
name: string;
97+
type: string;
98+
account: string;
99+
}
100+
3101
export class Helpers {
4102
constructor(private readonly faker: Faker) {
5103
// Bind `this` so namespaced is working correctly
@@ -160,7 +258,7 @@ export class Helpers {
160258
* @param string
161259
* @param num
162260
*/
163-
repeatString(string, num = 0): string {
261+
repeatString(string: string, num = 0): string {
164262
let text = '';
165263
for (let i = 0; i < num; i++) {
166264
text += string.toString();
@@ -323,7 +421,7 @@ export class Helpers {
323421
*
324422
* @method faker.helpers.createCard
325423
*/
326-
createCard() {
424+
createCard(): Card {
327425
return {
328426
name: this.faker.name.findName(),
329427
username: this.faker.internet.userName(),
@@ -382,7 +480,7 @@ export class Helpers {
382480
*
383481
* @method faker.helpers.contextualCard
384482
*/
385-
contextualCard() {
483+
contextualCard(): ContextualCard {
386484
const name = this.faker.name.firstName();
387485
const userName = this.faker.internet.userName(name);
388486
return {
@@ -421,7 +519,7 @@ export class Helpers {
421519
*
422520
* @method faker.helpers.userCard
423521
*/
424-
userCard() {
522+
userCard(): UserCard {
425523
return {
426524
name: this.faker.name.findName(),
427525
username: this.faker.internet.userName(),
@@ -451,7 +549,7 @@ export class Helpers {
451549
*
452550
* @method faker.helpers.createTransaction
453551
*/
454-
createTransaction() {
552+
createTransaction(): Transaction {
455553
return {
456554
amount: this.faker.finance.amount(),
457555
date: new Date(2012, 1, 2), // TODO: add a ranged date method

src/iban.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ export = {
3737
// @ts-expect-error
3838
match.toUpperCase().charCodeAt(0) - 55
3939
),
40-
mod97: (digitStr): number => {
40+
mod97: (digitStr: string): number => {
4141
let m = 0;
4242
for (let i = 0; i < digitStr.length; i++) {
43-
m = (m * 10 + (digitStr[i] | 0)) % 97;
43+
m =
44+
(m * 10 +
45+
// @ts-expect-error: We need to convert this properly
46+
(digitStr[i] | 0)) %
47+
97;
4448
}
4549
return m;
4650
},

src/image_providers/unsplash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class Unsplash {
3030
*
3131
* @method faker.image.unsplash.avatar
3232
*/
33-
avatar() {
33+
avatar(): string {
3434
return this.faker.internet.avatar();
3535
}
3636

src/internet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export class Internet {
220220
* @param firstName
221221
* @param lastName
222222
*/
223-
exampleEmail(firstName?: string, lastName?: string) {
223+
exampleEmail(firstName?: string, lastName?: string): string {
224224
const provider = this.faker.random.arrayElement(
225225
this.faker.definitions.internet.example_email
226226
);

src/lorem.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class Lorem {
9090
* @param sentenceCount defaults to a random number between 2 and 6
9191
* @param separator defaults to `' '`
9292
*/
93-
sentences(sentenceCount?: number, separator?: string) {
93+
sentences(sentenceCount?: number, separator?: string): string {
9494
if (typeof sentenceCount === 'undefined') {
9595
sentenceCount = this.faker.datatype.number({ min: 2, max: 6 });
9696
}
@@ -137,10 +137,8 @@ export class Lorem {
137137
* @method faker.lorem.text
138138
* @param times
139139
*/
140-
// TODO @Shinigami92 2022-01-11: Is this a function-name alias?
141-
// Or can we just remove the `loremText`?
142140
// TODO @Shinigami92 2022-01-11: `times` is not in use
143-
text = function loremText(times?: number) {
141+
text(times?: number): string {
144142
const loremMethods = [
145143
'lorem.word',
146144
'lorem.words',
@@ -152,7 +150,7 @@ export class Lorem {
152150
];
153151
const randomLoremMethod = this.faker.random.arrayElement(loremMethods);
154152
return this.faker.fake('{{' + randomLoremMethod + '}}');
155-
};
153+
}
156154

157155
/**
158156
* Returns lines of lorem separated by `'\n'`

src/mersenne.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Mersenne {
1515
}
1616
}
1717

18-
rand(max?: number, min?: number) {
18+
rand(max?: number, min?: number): number {
1919
// TODO @Shinigami92 2022-01-11: This is buggy, cause if min is not passed but only max,
2020
// then min will be undefined and this result in NaN for the whole function
2121
if (max === undefined) {
@@ -26,15 +26,15 @@ export class Mersenne {
2626
return Math.floor(this.gen.genrand_real2() * (max - min) + min);
2727
}
2828

29-
seed(S: number) {
29+
seed(S: number): void {
3030
if (typeof S != 'number') {
3131
throw new Error('seed(S) must take numeric argument; is ' + typeof S);
3232
}
3333

3434
this.gen.init_genrand(S);
3535
}
3636

37-
seed_array(A) {
37+
seed_array(A: number[]): void {
3838
if (typeof A != 'object') {
3939
throw new Error(
4040
'seed_array(A) must take array of numbers; is ' + typeof A

src/phone.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Phone {
1818
* @param format
1919
* @memberOf faker.phone
2020
*/
21-
phoneNumber(format?: string) {
21+
phoneNumber(format?: string): string {
2222
format ||= this.faker.phone.phoneFormats();
2323
return this.faker.helpers.replaceSymbolWithNumber(format);
2424
}
@@ -31,7 +31,7 @@ export class Phone {
3131
* @param phoneFormatsArrayIndex
3232
* @memberOf faker.phone
3333
*/
34-
phoneNumberFormat(phoneFormatsArrayIndex: number = 0) {
34+
phoneNumberFormat(phoneFormatsArrayIndex: number = 0): string {
3535
return this.faker.helpers.replaceSymbolWithNumber(
3636
this.faker.definitions.phone_number.formats[phoneFormatsArrayIndex]
3737
);

src/random.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export class Random {
124124
* @param object
125125
* @param field
126126
*/
127+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
127128
objectElement(object: any = { foo: 'bar', too: 'car' }, field?: string) {
128129
const array = Object.keys(object);
129130
const key = this.faker.random.arrayElement(array);

src/vendor/user-agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type { Faker } from '..';
3030

3131
export type Arch = 'lin' | 'mac' | 'win';
3232

33-
export function generate(faker: Faker) {
33+
export function generate(faker: Faker): string {
3434
function rnd(
3535
a?: string[] | number | Record<string, number>,
3636
b?: number

0 commit comments

Comments
 (0)