Skip to content

Commit 18782e5

Browse files
Add ESLint rules for type safety and fix violations
- Add @typescript-eslint/no-floating-promises: error - Add @typescript-eslint/no-non-null-assertion: error - Add @typescript-eslint/prefer-nullish-coalescing: error - Change @typescript-eslint/no-explicit-any from off to error Fixes: - Fix floating promise in NotebookPicker constructor by adding .catch() - Fix non-null assertion in NotebookPicker.onAfterAttach with null check - Fix prefer-nullish-coalescing in handler.ts by using ?? instead of || - Add inline eslint-disable comments for legitimate any usage in handler.ts
1 parent ef0931b commit 18782e5

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,12 @@
161161
"args": "none"
162162
}
163163
],
164-
"@typescript-eslint/no-explicit-any": "off",
164+
"@typescript-eslint/no-explicit-any": "error",
165165
"@typescript-eslint/no-namespace": "off",
166166
"@typescript-eslint/no-use-before-define": "off",
167+
"@typescript-eslint/no-floating-promises": "error",
168+
"@typescript-eslint/no-non-null-assertion": "error",
169+
"@typescript-eslint/prefer-nullish-coalescing": "error",
167170
"@typescript-eslint/quotes": [
168171
"error",
169172
"single",

src/components/NotebookPicker.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,23 @@ export class NotebookPicker extends ReactWidget {
1212
constructor(private panel: NotebookPanel) {
1313
super();
1414

15-
void panel.context.ready.then(() => {
16-
const deepnoteMetadata = this.panel.context.model.getMetadata('deepnote');
17-
const metadataNames = deepnoteMetadata?.notebook_names;
18-
const names =
19-
Array.isArray(metadataNames) &&
20-
metadataNames.every(n => typeof n === 'string')
21-
? metadataNames
22-
: [];
15+
panel.context.ready
16+
.then(() => {
17+
const deepnoteMetadata =
18+
this.panel.context.model.getMetadata('deepnote');
19+
const metadataNames = deepnoteMetadata?.notebook_names;
20+
const names =
21+
Array.isArray(metadataNames) &&
22+
metadataNames.every(n => typeof n === 'string')
23+
? metadataNames
24+
: [];
2325

24-
this.selected = names.length === 0 ? null : (names[0] ?? null);
25-
this.update();
26-
});
26+
this.selected = names.length === 0 ? null : (names[0] ?? null);
27+
this.update();
28+
})
29+
.catch(error => {
30+
console.error('Failed to initialize NotebookPicker:', error);
31+
});
2732
}
2833

2934
private handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
@@ -68,7 +73,9 @@ export class NotebookPicker extends ReactWidget {
6873
protected onAfterAttach(msg: Message): void {
6974
super.onAfterAttach(msg);
7075
requestAnimationFrame(() => {
71-
MessageLoop.sendMessage(this.parent!, Widget.ResizeMessage.UnknownSize);
76+
if (this.parent) {
77+
MessageLoop.sendMessage(this.parent, Widget.ResizeMessage.UnknownSize);
78+
}
7279
});
7380
}
7481

src/handler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ export async function requestAPI(
2525
try {
2626
response = await ServerConnection.makeRequest(requestUrl, init, settings);
2727
} catch (error) {
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2829
throw new ServerConnection.NetworkError(error as any);
2930
}
3031

32+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3133
let data: any = await response.text();
3234

3335
if (data.length > 0) {
@@ -39,7 +41,7 @@ export async function requestAPI(
3941
}
4042

4143
if (!response.ok) {
42-
throw new ServerConnection.ResponseError(response, data.message || data);
44+
throw new ServerConnection.ResponseError(response, data.message ?? data);
4345
}
4446

4547
return data;

0 commit comments

Comments
 (0)