Skip to content

Commit 3651918

Browse files
authored
Update ESLint config to v9 (JSDoc linting) (#591)
Our ESLint rules have been updated to v9, which includes new rules to enforce our JSDoc conventions. Most of the changes in this PR were a result of running `yarn lint:fix`. There were a handful of manual changes that seemed obvious and simple to make. There should be no functional changes in this PR. All changes are to comments (aside from the config update and related config changes).
1 parent ee21753 commit 3651918

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1094
-860
lines changed

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@
7070
"devDependencies": {
7171
"@lavamoat/allow-scripts": "^1.0.6",
7272
"@metamask/auto-changelog": "^2.5.0",
73-
"@metamask/eslint-config": "^8.0.0",
74-
"@metamask/eslint-config-jest": "^8.0.0",
75-
"@metamask/eslint-config-nodejs": "^8.0.0",
76-
"@metamask/eslint-config-typescript": "^8.0.0",
73+
"@metamask/eslint-config": "^9.0.0",
74+
"@metamask/eslint-config-jest": "^9.0.0",
75+
"@metamask/eslint-config-nodejs": "^9.0.0",
76+
"@metamask/eslint-config-typescript": "^9.0.1",
7777
"@types/jest": "^26.0.22",
7878
"@types/node": "^14.14.31",
7979
"@types/punycode": "^2.1.0",
@@ -86,6 +86,7 @@
8686
"eslint-import-resolver-typescript": "^2.4.0",
8787
"eslint-plugin-import": "^2.22.1",
8888
"eslint-plugin-jest": "^24.1.5",
89+
"eslint-plugin-jsdoc": "^36.1.0",
8990
"eslint-plugin-node": "^11.1.0",
9091
"eslint-plugin-prettier": "^3.3.1",
9192
"ethjs-provider-http": "^0.1.6",

src/BaseController.ts

+20-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export type Listener<T> = (state: T) => void;
77
* @type BaseConfig
88
*
99
* Base controller configuration
10-
*
1110
* @property disabled - Determines if this controller is enabled
1211
*/
1312
export interface BaseConfig {
@@ -18,7 +17,6 @@ export interface BaseConfig {
1817
* @type BaseState
1918
*
2019
* Base state representation
21-
*
2220
* @property name - Unique name for this controller
2321
*/
2422
export interface BaseState {
@@ -63,8 +61,8 @@ export class BaseController<C extends BaseConfig, S extends BaseState> {
6361
* Creates a BaseController instance. Both initial state and initial
6462
* configuration options are merged with defaults upon initialization.
6563
*
66-
* @param config - Initial options used to configure this controller
67-
* @param state - Initial state to set on this controller
64+
* @param config - Initial options used to configure this controller.
65+
* @param state - Initial state to set on this controller.
6866
*/
6967
constructor(config: Partial<C> = {} as C, state: Partial<S> = {} as S) {
7068
// Use assign since generics can't be spread: https://git.io/vpRhY
@@ -77,7 +75,7 @@ export class BaseController<C extends BaseConfig, S extends BaseState> {
7775
* variable on this instance and triggers any defined setters. This
7876
* also sets initial state and triggers any listeners.
7977
*
80-
* @returns - This controller instance
78+
* @returns This controller instance.
8179
*/
8280
protected initialize() {
8381
this.internalState = this.defaultState;
@@ -88,29 +86,29 @@ export class BaseController<C extends BaseConfig, S extends BaseState> {
8886
}
8987

9088
/**
91-
* Retrieves current controller configuration options
89+
* Retrieves current controller configuration options.
9290
*
93-
* @returns - Current configuration
91+
* @returns The current configuration.
9492
*/
9593
get config() {
9694
return this.internalConfig;
9795
}
9896

9997
/**
100-
* Retrieves current controller state
98+
* Retrieves current controller state.
10199
*
102-
* @returns - Current state
100+
* @returns The current state.
103101
*/
104102
get state() {
105103
return this.internalState;
106104
}
107105

108106
/**
109-
* Updates controller configuration
107+
* Updates controller configuration.
110108
*
111-
* @param config - New configuration options
112-
* @param overwrite - Overwrite config instead of merging
113-
* @param fullUpdate - Boolean that defines if the update is partial or not
109+
* @param config - New configuration options.
110+
* @param overwrite - Overwrite config instead of merging.
111+
* @param fullUpdate - Boolean that defines if the update is partial or not.
114112
*/
115113
configure(config: Partial<C>, overwrite = false, fullUpdate = true) {
116114
if (fullUpdate) {
@@ -135,7 +133,7 @@ export class BaseController<C extends BaseConfig, S extends BaseState> {
135133
}
136134

137135
/**
138-
* Notifies all subscribed listeners of current state
136+
* Notifies all subscribed listeners of current state.
139137
*/
140138
notify() {
141139
if (this.disabled) {
@@ -148,19 +146,19 @@ export class BaseController<C extends BaseConfig, S extends BaseState> {
148146
}
149147

150148
/**
151-
* Adds new listener to be notified of state changes
149+
* Adds new listener to be notified of state changes.
152150
*
153-
* @param listener - Callback triggered when state changes
151+
* @param listener - The callback triggered when state changes.
154152
*/
155153
subscribe(listener: Listener<S>) {
156154
this.internalListeners.push(listener);
157155
}
158156

159157
/**
160-
* Removes existing listener from receiving state changes
158+
* Removes existing listener from receiving state changes.
161159
*
162-
* @param listener - Callback to remove
163-
* @returns - True if a listener is found and unsubscribed
160+
* @param listener - The callback to remove.
161+
* @returns `true` if a listener is found and unsubscribed.
164162
*/
165163
unsubscribe(listener: Listener<S>) {
166164
const index = this.internalListeners.findIndex((cb) => listener === cb);
@@ -169,10 +167,10 @@ export class BaseController<C extends BaseConfig, S extends BaseState> {
169167
}
170168

171169
/**
172-
* Updates controller state
170+
* Updates controller state.
173171
*
174-
* @param state - New state
175-
* @param overwrite - Overwrite state instead of merging
172+
* @param state - The new state.
173+
* @param overwrite - Overwrite state instead of merging.
176174
*/
177175
update(state: Partial<S>, overwrite = false) {
178176
this.internalState = overwrite

src/BaseControllerV2.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ type CountMessenger = RestrictedControllerMessenger<
4141
never
4242
>;
4343

44+
/**
45+
* Constructs a restricted controller messenger for the Count controller.
46+
*
47+
* @param controllerMessenger - The controller messenger.
48+
* @returns A restricted controller messenger for the Count controller.
49+
*/
4450
function getCountMessenger(
4551
controllerMessenger?: ControllerMessenger<
4652
CountControllerAction,

src/BaseControllerV2.ts

+32-24
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ enablePatches();
1818
* the new state along with a set of patches describing the changes since the
1919
* last update.
2020
*
21-
* @param state - The new controller state
21+
* @param state - The new controller state.
2222
* @param patches - A list of patches describing any changes (see here for more
23-
* information: https://immerjs.github.io/immer/docs/patches)
23+
* information: https://immerjs.github.io/immer/docs/patches)
2424
*/
2525
export type Listener<T> = (state: T, patches: Patch[]) => void;
2626

@@ -30,8 +30,8 @@ export type Listener<T> = (state: T, patches: Patch[]) => void;
3030
* This function will accept one piece of the controller state (one property),
3131
* and will return some derivation of that state.
3232
*
33-
* @param value - A piece of controller state
34-
* @returns Something derived from controller state
33+
* @param value - A piece of controller state.
34+
* @returns Something derived from controller state.
3535
*/
3636
export type StateDeriver<T extends Json> = (value: T) => Json;
3737

@@ -49,12 +49,12 @@ export type StateMetadata<T extends Record<string, Json>> = {
4949
* Metadata for a single state property
5050
*
5151
* @property persist - Indicates whether this property should be persisted
52-
* (`true` for persistent, `false` for transient), or is set to a function
53-
* that derives the persistent state from the state.
52+
* (`true` for persistent, `false` for transient), or is set to a function
53+
* that derives the persistent state from the state.
5454
* @property anonymous - Indicates whether this property is already anonymous,
55-
* (`true` for anonymous, `false` if it has potential to be personally
56-
* identifiable), or is set to a function that returns an anonymized
57-
* representation of this state.
55+
* (`true` for anonymous, `false` if it has potential to be personally
56+
* identifiable), or is set to a function that returns an anonymized
57+
* representation of this state.
5858
*/
5959
export interface StatePropertyMetadata<T extends Json> {
6060
persist: boolean | StateDeriver<T>;
@@ -101,12 +101,12 @@ export class BaseController<
101101
/**
102102
* Creates a BaseController instance.
103103
*
104-
* @param options
105-
* @param options.messenger - Controller messaging system
104+
* @param options - Controller options.
105+
* @param options.messenger - Controller messaging system.
106106
* @param options.metadata - State metadata, describing how to "anonymize" the state, and which
107-
* parts should be persisted.
108-
* @param options.name - The name of the controller, used as a namespace for events and actions
109-
* @param options.state - Initial controller state
107+
* parts should be persisted.
108+
* @param options.name - The name of the controller, used as a namespace for events and actions.
109+
* @param options.state - Initial controller state.
110110
*/
111111
constructor({
112112
messenger,
@@ -131,9 +131,9 @@ export class BaseController<
131131
}
132132

133133
/**
134-
* Retrieves current controller state
134+
* Retrieves current controller state.
135135
*
136-
* @returns - Current state
136+
* @returns The current state.
137137
*/
138138
get state() {
139139
return this.internalState;
@@ -152,7 +152,7 @@ export class BaseController<
152152
* applied to the controller state.
153153
*
154154
* @param callback - Callback for updating state, passed a draft state
155-
* object. Return a new state object or mutate the draft to update state.
155+
* object. Return a new state object or mutate the draft to update state.
156156
*/
157157
protected update(callback: (state: Draft<S>) => void | S) {
158158
// We run into ts2589, "infinite type depth", if we don't cast
@@ -193,10 +193,10 @@ export class BaseController<
193193
* By "anonymized" we mean that it should not contain any information that could be personally
194194
* identifiable.
195195
*
196-
* @param state - The controller state
196+
* @param state - The controller state.
197197
* @param metadata - The controller state metadata, which describes how to derive the
198-
* anonymized state
199-
* @returns The anonymized controller state
198+
* anonymized state.
199+
* @returns The anonymized controller state.
200200
*/
201201
export function getAnonymizedState<S extends Record<string, Json>>(
202202
state: S,
@@ -206,11 +206,11 @@ export function getAnonymizedState<S extends Record<string, Json>>(
206206
}
207207

208208
/**
209-
* Returns the subset of state that should be persisted
209+
* Returns the subset of state that should be persisted.
210210
*
211-
* @param state - The controller state
212-
* @param metadata - The controller state metadata, which describes which pieces of state should be persisted
213-
* @returns The subset of controller state that should be persisted
211+
* @param state - The controller state.
212+
* @param metadata - The controller state metadata, which describes which pieces of state should be persisted.
213+
* @returns The subset of controller state that should be persisted.
214214
*/
215215
export function getPersistentState<S extends Record<string, Json>>(
216216
state: S,
@@ -219,6 +219,14 @@ export function getPersistentState<S extends Record<string, Json>>(
219219
return deriveStateFromMetadata(state, metadata, 'persist');
220220
}
221221

222+
/**
223+
* Use the metadata to derive state according to the given metadata property.
224+
*
225+
* @param state - The full controller state.
226+
* @param metadata - The controller metadata.
227+
* @param metadataProperty - The metadata property to use to derive state.
228+
* @returns The metadata-derived controller state.
229+
*/
222230
function deriveStateFromMetadata<S extends Record<string, Json>>(
223231
state: S,
224232
metadata: StateMetadata<S>,

src/ComposableController.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ export class ComposableController extends BaseController<never, any> {
3535
name = 'ComposableController';
3636

3737
/**
38-
* Creates a ComposableController instance
38+
* Creates a ComposableController instance.
3939
*
40-
* @param controllers - Map of names to controller instances
41-
* @param messenger - The controller messaging system, used for communicating with BaseControllerV2 controllers
40+
* @param controllers - Map of names to controller instances.
41+
* @param messenger - The controller messaging system, used for communicating with BaseControllerV2 controllers.
4242
*/
4343
constructor(
4444
controllers: ControllerList,
@@ -86,7 +86,7 @@ export class ComposableController extends BaseController<never, any> {
8686
* of controller name. Instead, all child controller state is merged
8787
* together into a single, flat object.
8888
*
89-
* @returns - Merged state representation of all child controllers
89+
* @returns Merged state representation of all child controllers.
9090
*/
9191
get flatState() {
9292
let flatState = {};

0 commit comments

Comments
 (0)