Skip to content

Commit 6d3f42e

Browse files
docs: deprecation workflow (#1067)
Co-authored-by: Eric Cheng <ericcheng9316@gmail.com>
1 parent c1cc131 commit 6d3f42e

6 files changed

Lines changed: 70 additions & 24 deletions

File tree

CONTRIBUTING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ You can view a generated code coverage report at `coverage/index.html`.
4949

5050
After adding new or updating existing locale data, you need to run `pnpm run generate:locales` to generate/update the related files.
5151

52+
## Deprecation workflow
53+
54+
If you ever find yourself deprecating something in the source code, you can follow these steps to save yourself (and the reviewers) some trouble.
55+
56+
If the code you want to deprecate is a property, convert it to a [getter](https://www.typescriptlang.org/docs/handbook/2/classes.html#getters--setters) first. Now that you have a function, the first thing you want to do is call the internal [`deprecated` function](src/internal/deprecated.ts). Afterwards, add a `@deprecated` parameter to the end of the JSDoc with a human readable description message with a suitable replacement for the deprecated function. Lastly, add a `@see` parameter to the JSDoc with a link to the replacement in the faker library (if it exists). The syntax for the link is `faker.[module].[function]`.
57+
58+
Example:
59+
60+
```ts
61+
/**
62+
* @see faker.cat.random
63+
*
64+
* @deprecated Use faker.cat.random() instead.
65+
*/
66+
get cat() {
67+
deprecated({
68+
deprecated: 'faker.animal.cat',
69+
});
70+
return 'cat';
71+
}
72+
```
73+
5274
## Developing the docs
5375

5476
Before running the docs, build the Faker dist, it's used inside of certain routes.

src/internal/deprecated.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
11
/* eslint-disable jsdoc/check-tag-names */
22
/* eslint-disable jsdoc/require-param */
33

4+
/**
5+
* A deprecation should never be done in a patch.
6+
*/
7+
type DeprecationSemVer = `${number}.${number}`;
8+
49
/** @internal */
510
export interface DeprecatedOptions {
11+
/**
12+
* The name of the function, following the syntax `faker.[module].[function]()`.
13+
*/
614
deprecated: string;
15+
/**
16+
* An alternative solution.
17+
*/
718
proposed?: string;
8-
since?: string;
9-
until?: string;
19+
/**
20+
* The semver since when this is deprecated.
21+
*/
22+
since?: DeprecationSemVer;
23+
/**
24+
* The semver when this will be removed.
25+
*/
26+
until?: DeprecationSemVer;
1027
}
1128

12-
/** @internal */
29+
/**
30+
* @internal
31+
*/
1332
export function deprecated(opts: DeprecatedOptions): void {
1433
let message = `[@faker-js/faker]: ${opts.deprecated} is deprecated`;
1534

1635
if (opts.since) {
17-
message += ` since ${opts.since}`;
36+
message += ` since v${opts.since}`;
1837
}
1938

2039
if (opts.until) {
21-
message += ` and will be removed in ${opts.until}`;
40+
message += ` and will be removed in v${opts.until}`;
2241
}
2342

2443
if (opts.proposed) {
25-
message += `. Please use ${opts.proposed} instead`;
44+
message += `. Please use ${opts.proposed} instead.`;
2645
}
2746

2847
console.warn(`${message}.`);

src/modules/address/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export class Address {
7676
deprecated({
7777
deprecated: 'faker.address.city(format)',
7878
proposed: 'faker.address.city() or faker.fake(format)',
79-
since: 'v7.0',
80-
until: 'v8.0',
79+
since: '7.0',
80+
until: '8.0',
8181
});
8282
}
8383
const formats = this.faker.definitions.address.city;
@@ -98,13 +98,14 @@ export class Address {
9898
* faker.address.cityPrefix() // 'East'
9999
*
100100
* @deprecated
101+
* Use `faker.address.city()` instead.
101102
*/
102103
cityPrefix(): string {
103104
deprecated({
104105
deprecated: 'faker.address.cityPrefix()',
105106
proposed: "faker.address.city() or faker.fake('{{address.city_prefix}}')",
106-
since: 'v7.2',
107-
until: 'v8.0',
107+
since: '7.2',
108+
until: '8.0',
108109
});
109110
return this.faker.helpers.arrayElement(
110111
this.faker.definitions.address.city_prefix
@@ -120,13 +121,14 @@ export class Address {
120121
* faker.address.citySuffix() // 'mouth'
121122
*
122123
* @deprecated
124+
* Use `faker.address.city()` instead.
123125
*/
124126
citySuffix(): string {
125127
deprecated({
126128
deprecated: 'faker.address.citySuffix()',
127129
proposed: "faker.address.city() or faker.fake('{{address.city_suffix}}')",
128-
since: 'v7.2',
129-
until: 'v8.0',
130+
since: '7.2',
131+
until: '8.0',
130132
});
131133
return this.faker.helpers.arrayElement(
132134
this.faker.definitions.address.city_suffix
@@ -185,8 +187,8 @@ export class Address {
185187
'faker.address.streetName() without address.street_name definitions',
186188
proposed:
187189
'faker.address.street() or provide address.street_name definitions',
188-
since: 'v7.0',
189-
until: 'v8.0',
190+
since: '7.0',
191+
until: '8.0',
190192
});
191193
return this.street();
192194
}

src/modules/commerce/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ export class Commerce {
2222
* faker.commerce.color() // 'red'
2323
*
2424
* @deprecated
25+
* Use `faker.color.human()` instead.
2526
*/
2627
color(): string {
2728
deprecated({
2829
deprecated: 'faker.commerce.color()',
2930
proposed: 'faker.color.human()',
30-
since: 'v7.0.0',
31-
until: 'v8.0.0',
31+
since: '7.0',
32+
until: '8.0',
3233
});
3334
return this.faker.color.human();
3435
}

src/modules/phone/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export class Phone {
3333
deprecated({
3434
deprecated: 'faker.phone.phoneNumber()',
3535
proposed: 'faker.phone.number()',
36-
since: 'v7.3',
37-
until: 'v8.0',
36+
since: '7.3',
37+
until: '8.0',
3838
});
3939
return this.faker.phone.number(format);
4040
}
@@ -71,14 +71,15 @@ export class Phone {
7171
* faker.phone.phoneNumberFormat(3) // '282.652.3201'
7272
*
7373
* @deprecated
74+
* Use faker.phone.phoneNumber() instead.
7475
*/
7576
phoneNumberFormat(phoneFormatsArrayIndex = 0): string {
7677
deprecated({
7778
deprecated: 'faker.phone.phoneNumberFormat()',
7879
proposed:
7980
'faker.phone.phoneNumber() or faker.helpers.replaceSymbolWithNumber(format)',
80-
since: 'v7.0',
81-
until: 'v8.0',
81+
since: '7.0',
82+
until: '8.0',
8283
});
8384
return this.faker.helpers.replaceSymbolWithNumber(
8485
this.faker.definitions.phone_number.formats[phoneFormatsArrayIndex]
@@ -95,13 +96,14 @@ export class Phone {
9596
* faker.phone.phoneFormats() // '!##.!##.####'
9697
*
9798
* @deprecated
99+
* Use `faker.phone.phoneNumber()` instead.
98100
*/
99101
phoneFormats(): string {
100102
deprecated({
101103
deprecated: 'faker.phone.phoneFormats()',
102104
proposed: 'faker.phone.phoneNumber()',
103-
since: 'v7.0',
104-
until: 'v8.0',
105+
since: '7.0',
106+
until: '8.0',
105107
});
106108
return this.faker.helpers.arrayElement(
107109
this.faker.definitions.phone_number.formats

src/modules/random/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ export class Random {
273273
deprecated({
274274
deprecated: 'faker.random.alpha({ upcase: true })',
275275
proposed: "faker.random.alpha({ casing: 'upper' })",
276-
since: 'v7.0',
277-
until: 'v8.0',
276+
since: '7.0',
277+
until: '8.0',
278278
});
279279
}
280280

0 commit comments

Comments
 (0)