Skip to content

Commit a214d20

Browse files
committed
lint fixes
1 parent 3ebb26a commit a214d20

11 files changed

Lines changed: 99 additions & 61 deletions

File tree

src/glide/browser/base/content/browser-commandline.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class TabsCompletionSource implements GlideCompletionSource<TabCompletion
210210
tab.label,
211211
],
212212
}),
213-
DOM.create_element("td", { className: "url", children: tab.linkedBrowser.currentURI.spec }),
213+
DOM.create_element("td", { className: "url", children: tab.linkedBrowser?.currentURI.spec }),
214214
],
215215
}),
216216

src/glide/browser/base/content/browser-excmds.mts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class GlideExcmdsClass {
293293
}
294294

295295
case "tab_next": {
296-
const all_tabs = gBrowser.tabContainer.allTabs as unknown[];
296+
const all_tabs = gBrowser.tabContainer.allTabs;
297297
let next_index = gBrowser.tabContainer.selectedIndex + 1;
298298
if (next_index >= all_tabs.length) {
299299
next_index = 0;
@@ -349,6 +349,9 @@ class GlideExcmdsClass {
349349

350350
case "tab_pin_toggle": {
351351
const tab = gBrowser.selectedTab;
352+
if (!tab) {
353+
throw new Error("No tab to pin/unpin");
354+
}
352355
if (tab.pinned) {
353356
gBrowser.unpinTab(tab);
354357
} else {
@@ -362,6 +365,9 @@ class GlideExcmdsClass {
362365
}
363366

364367
case "tab_duplicate": {
368+
if (!gBrowser.selectedTab) {
369+
throw new Error("No tab to duplicate");
370+
}
365371
gBrowser.duplicateTab(gBrowser.selectedTab, undefined, { inBackground: false });
366372
break;
367373
}

src/glide/browser/base/content/browser.mts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,9 @@ class GlideBrowserClass {
893893
url: location.spec,
894894
get tab_id() {
895895
return assert_present(
896-
GlideBrowser.extension.tabManager.getWrapper(gBrowser.selectedTab),
896+
GlideBrowser.extension.tabManager.getWrapper(
897+
assert_present(gBrowser.selectedTab, "could not resolve selected tab"),
898+
),
897899
"could not resolve tab wrapper",
898900
).id;
899901
},
@@ -1899,6 +1901,9 @@ class GlideBrowserClass {
18991901
*/
19001902
async upsert_commandline(opts: GlideCommandLineShowOptions = {}) {
19011903
const tab = gBrowser.selectedTab;
1904+
if (!tab) {
1905+
return null;
1906+
}
19021907
const cached = this.#get_cached_commandline(tab);
19031908
if (cached) {
19041909
cached.show(opts);
@@ -1931,6 +1936,9 @@ class GlideBrowserClass {
19311936
}
19321937

19331938
async toggle_commandline() {
1939+
if (!gBrowser.selectedTab) {
1940+
return;
1941+
}
19341942
const commandline = this.#get_cached_commandline(gBrowser.selectedTab);
19351943
if (!commandline) {
19361944
await this.upsert_commandline();
@@ -1950,6 +1958,9 @@ class GlideBrowserClass {
19501958
* This only returns anything **if** the commandline is open **and** it is focused.
19511959
*/
19521960
#get_active_commandline(): GlideCommandLine | null {
1961+
if (!gBrowser.selectedTab) {
1962+
return null;
1963+
}
19531964
const commandline = this.#get_cached_commandline(gBrowser.selectedTab);
19541965
if (!commandline) {
19551966
return null;
@@ -1971,6 +1982,9 @@ class GlideBrowserClass {
19711982
}
19721983

19731984
get_commandline(): GlideCommandLine | null {
1985+
if (!gBrowser.selectedTab) {
1986+
return null;
1987+
}
19741988
return this.#get_cached_commandline(gBrowser.selectedTab);
19751989
}
19761990

@@ -1982,7 +1996,7 @@ class GlideBrowserClass {
19821996
return tab._glide_commandline;
19831997
}
19841998

1985-
#cache_commandline(tab: BrowserTab, excmdbar: Element): void {
1999+
#cache_commandline(tab: BrowserTab, excmdbar: GlideCommandLine): void {
19862000
tab._glide_commandline = excmdbar;
19872001
}
19882002
}

src/glide/browser/base/content/test/config/browser_document_mirror.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ add_task(async function test_addEventListener__multiple_listeners_same_element__
846846
});
847847

848848
add_task(async function test_addEventListener__preventDefault() {
849-
using _ = await GlideTestUtils.new_tab();
849+
const _ = await GlideTestUtils.new_tab();
850850

851851
await GlideTestUtils.reload_config(() => {
852852
glide.g.value = 0;

src/glide/browser/base/content/test/config/browser_options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ async function newtab() {
2626

2727
return {
2828
[Symbol.dispose]() {
29+
if (!tab) {
30+
return;
31+
}
2932
gBrowser.removeTab(tab);
3033
},
3134
};

src/glide/browser/base/content/test/excmds/browser_excmds.ts

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ function current_url() {
2121
}
2222

2323
add_task(async function test_tab_switching() {
24-
const browser = gBrowser.tabContainer.allTabs.at(0).linkedBrowser;
24+
const browser = gBrowser.tabContainer.allTabs.at(0)?.linkedBrowser;
25+
if (!browser) {
26+
throw new Error("No browser found");
27+
}
2528
BrowserTestUtils.startLoadingURIString(browser, INPUT_TEST_FILE + "?i=0");
2629
await BrowserTestUtils.browserLoaded(browser);
27-
using _tab2 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=1");
28-
using _tab3 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=2");
30+
const _tab2 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=1");
31+
const _tab3 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=2");
2932

3033
is(current_url(), INPUT_TEST_FILE + "?i=2");
3134

@@ -46,8 +49,8 @@ add_task(async function test_tab_close() {
4649
await reload_config(function _() {
4750
glide.g.mapleader = "<Space>";
4851
});
49-
using _tab2 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=1");
50-
using _tab3 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=2");
52+
const _tab2 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=1");
53+
const _tab3 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=2");
5154

5255
is(current_url(), INPUT_TEST_FILE + "?i=2");
5356

@@ -271,12 +274,12 @@ add_task(async function test_tab_pin() {
271274
await reload_config(function _() {});
272275

273276
const initial_tab_count = gBrowser.tabs.length;
274-
using tab1 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=1");
275-
using _tab2 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=2");
277+
const tab1 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=1");
278+
const _tab2 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=2");
276279

277-
is(gBrowser.selectedTab.pinned, false, "Current tab should not be pinned initially");
280+
is(gBrowser.selectedTab!.pinned, false, "Current tab should not be pinned initially");
278281
await keys(":tab_pin<CR>");
279-
is(gBrowser.selectedTab.pinned, true, "Current tab should be pinned after :tab_pin");
282+
is(gBrowser.selectedTab!.pinned, true, "Current tab should be pinned after :tab_pin");
280283

281284
const tab1_id = GlideBrowser.extension?.tabManager?.getWrapper?.(tab1)?.id;
282285
isnot(tab1_id, undefined, "Tab ID should be available");
@@ -291,14 +294,14 @@ add_task(async function test_tab_unpin() {
291294
await reload_config(function _() {});
292295

293296
const initial_tab_count = gBrowser.tabs.length;
294-
using tab1 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=1");
295-
using _tab2 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=2");
297+
const tab1 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=1");
298+
const _tab2 = await GlideTestUtils.new_tab(INPUT_TEST_FILE + "?i=2");
296299

297-
gBrowser.pinTab(gBrowser.selectedTab);
300+
gBrowser.pinTab(gBrowser.selectedTab!);
298301

299-
is(gBrowser.selectedTab.pinned, true, "Current tab should be pinned initially");
302+
is(gBrowser.selectedTab!.pinned, true, "Current tab should be pinned initially");
300303
await keys(":tab_unpin<CR>");
301-
is(gBrowser.selectedTab.pinned, false, "Current tab should be unpinned after :tab_unpin");
304+
is(gBrowser.selectedTab!.pinned, false, "Current tab should be unpinned after :tab_unpin");
302305

303306
gBrowser.pinTab(tab1);
304307
const tab1_id = GlideBrowser.extension?.tabManager?.getWrapper?.(tab1)?.id;
@@ -313,44 +316,44 @@ add_task(async function test_tab_unpin() {
313316
add_task(async function test_tab_pin_toggle_excmd() {
314317
await reload_config(function _() {});
315318

316-
using tab = await GlideTestUtils.new_tab(KEY_TEST_FILE + "?i=1");
319+
const tab = await GlideTestUtils.new_tab(KEY_TEST_FILE + "?i=1");
317320
is(gBrowser.selectedTab, tab);
318-
is(gBrowser.selectedTab.pinned, false, "Current tab should not be pinned initially");
321+
is(gBrowser.selectedTab!.pinned, false, "Current tab should not be pinned initially");
319322

320323
await keys(":tab_pin_toggle<CR>");
321324
if (gBrowser.selectedTab !== tab) {
322325
// idk man, Firefox seems to create an extra tab based off of the *other* tab that is active?
323-
gBrowser.removeTab(gBrowser.selectedTab);
324-
gBrowser.removeTab(gBrowser.selectedTab);
326+
gBrowser.removeTab(gBrowser.selectedTab!);
327+
gBrowser.removeTab(gBrowser.selectedTab!);
325328
}
326329

327-
is(gBrowser.selectedTab.pinned, true, "Current tab should be pinned after :tab_pin_toggle");
330+
is(gBrowser.selectedTab!.pinned, true, "Current tab should be pinned after :tab_pin_toggle");
328331

329332
await keys(":tab_pin_toggle<CR>");
330-
is(gBrowser.selectedTab.pinned, false, "Current tab should be unpinned after :tab_pin_toggle");
333+
is(gBrowser.selectedTab!.pinned, false, "Current tab should be unpinned after :tab_pin_toggle");
331334
});
332335

333336
add_task(async function test_tab_pin_toggle_keymap() {
334337
await reload_config(function _() {});
335338

336-
using tab = await GlideTestUtils.new_tab(KEY_TEST_FILE + "?i=1");
339+
const tab = await GlideTestUtils.new_tab(KEY_TEST_FILE + "?i=1");
337340
is(gBrowser.selectedTab, tab);
338-
is(gBrowser.selectedTab.pinned, false, "Current tab should not be pinned initially");
341+
is(gBrowser.selectedTab!.pinned, false, "Current tab should not be pinned initially");
339342

340343
await keys("<esc>");
341344
await wait_for_mode("normal");
342345

343346
await keys("<A-p>");
344347
if (gBrowser.selectedTab !== tab) {
345348
// idk man, Firefox seems to create an extra tab based off of the *other* tab that is active?
346-
gBrowser.removeTab(gBrowser.selectedTab);
347-
gBrowser.removeTab(gBrowser.selectedTab);
349+
gBrowser.removeTab(gBrowser.selectedTab!);
350+
gBrowser.removeTab(gBrowser.selectedTab!);
348351
}
349352

350-
await waiter(() => gBrowser.selectedTab.pinned).is(true, "Tab should be pinned after <A-p>");
353+
await waiter(() => gBrowser.selectedTab!.pinned).is(true, "Tab should be pinned after <A-p>");
351354

352355
await keys("<A-p>");
353-
await waiter(() => gBrowser.selectedTab.pinned).is(false, "Tab should be unpinned after <A-p>");
356+
await waiter(() => gBrowser.selectedTab!.pinned).is(false, "Tab should be unpinned after <A-p>");
354357
});
355358

356359
add_task(async function test_tab_reopen() {
@@ -382,7 +385,7 @@ add_task(async function test_tab_duplicate() {
382385
const initial_tab_count = gBrowser.tabs.length;
383386
const test_url = INPUT_TEST_FILE + "?duplicate_test";
384387

385-
using _tab = await GlideTestUtils.new_tab(test_url);
388+
const _tab = await GlideTestUtils.new_tab(test_url);
386389
is(gBrowser.tabs.length, initial_tab_count + 1);
387390
is(current_url(), test_url);
388391

src/glide/browser/base/content/test/hints/browser_hints.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ add_task(async function test_F_opens_new_tab() {
9494
is(GlideBrowser.state.mode, "normal", "Mode should return to 'normal' after following hint");
9595

9696
if (final_tab_count > initial_tab_count) {
97-
gBrowser.removeTab(gBrowser.selectedTab);
97+
gBrowser.removeTab(gBrowser.selectedTab!);
9898
}
9999
});
100100
});
@@ -438,7 +438,7 @@ add_task(async function test_numeric_hint_generator() {
438438
is(GlideBrowser.state.mode, "normal", "Mode should return to 'normal' after following hint");
439439

440440
if (final_tab_count > initial_tab_count) {
441-
gBrowser.removeTab(gBrowser.selectedTab);
441+
gBrowser.removeTab(gBrowser.selectedTab!);
442442
}
443443
});
444444
});

src/glide/browser/base/content/test/mode/browser_keys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ add_task(async function test_buf_local_keymaps_override_global() {
367367
is(glide.g.invoked_global, 0, "Global mapping should be shadowed by the buffer-local mapping");
368368

369369
// Open a new tab to clear buffer-local mappings.
370-
using _tab = await GlideTestUtils.new_tab(KEYS_TEST_URI);
370+
const _tab = await GlideTestUtils.new_tab(KEYS_TEST_URI);
371371

372372
await keys("q");
373373
await sleep_frames(3);

src/glide/browser/base/content/test/navigation/browser_jumplist.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ function current_url() {
1818
}
1919

2020
add_task(async function test_jumplist_basic_navigation() {
21-
const browser = gBrowser.tabContainer.allTabs.at(0).linkedBrowser;
21+
const browser = gBrowser.tabContainer.allTabs.at(0)?.linkedBrowser;
22+
if (!browser) {
23+
throw new Error("No browser found");
24+
}
2225
BrowserTestUtils.startLoadingURIString(browser, uri(0));
2326
await BrowserTestUtils.browserLoaded(browser);
2427

25-
using _tab1 = await GlideTestUtils.new_tab(uri(1));
26-
using _tab2 = await GlideTestUtils.new_tab(uri(2));
28+
const _tab1 = await GlideTestUtils.new_tab(uri(1));
29+
const _tab2 = await GlideTestUtils.new_tab(uri(2));
2730

2831
is(current_url(), uri(2));
2932

@@ -47,17 +50,20 @@ add_task(async function test_jumplist_basic_navigation() {
4750
});
4851

4952
add_task(async function test_jumplist_prunes_forward_slice() {
50-
const browser = gBrowser.tabContainer.allTabs.at(0).linkedBrowser;
53+
const browser = gBrowser.tabContainer.allTabs.at(0)?.linkedBrowser;
54+
if (!browser) {
55+
throw new Error("No browser found");
56+
}
5157
BrowserTestUtils.startLoadingURIString(browser, uri(0));
5258
await BrowserTestUtils.browserLoaded(browser);
5359

54-
using _tab1 = await GlideTestUtils.new_tab(uri(1));
55-
using _tab2 = await GlideTestUtils.new_tab(uri(2));
60+
const _tab1 = await GlideTestUtils.new_tab(uri(1));
61+
const _tab2 = await GlideTestUtils.new_tab(uri(2));
5662

5763
await keys("<C-o>");
5864
await waiter(current_url).is(uri(1), "<C-o> moves back to tab1");
5965

60-
using _tab3 = await GlideTestUtils.new_tab(uri(3));
66+
const _tab3 = await GlideTestUtils.new_tab(uri(3));
6167
is(current_url(), uri(3));
6268

6369
await keys("<C-i>");
@@ -68,7 +74,10 @@ add_task(async function test_jumplist_prunes_forward_slice() {
6874
});
6975

7076
add_task(async function test_jumplist_max_entries_trim() {
71-
const browser = gBrowser.tabContainer.allTabs.at(0).linkedBrowser;
77+
const browser = gBrowser.tabContainer.allTabs.at(0)?.linkedBrowser;
78+
if (!browser) {
79+
throw new Error("No browser found");
80+
}
7281
BrowserTestUtils.startLoadingURIString(browser, uri(0));
7382
await BrowserTestUtils.browserLoaded(browser);
7483

@@ -102,14 +111,17 @@ add_task(async function test_jumplist_max_entries_trim() {
102111
});
103112

104113
add_task(async function test_jumplist_deleted_intermediary_tab() {
105-
const browser = gBrowser.tabContainer.allTabs.at(0).linkedBrowser;
114+
const browser = gBrowser.tabContainer.allTabs.at(0)?.linkedBrowser;
115+
if (!browser) {
116+
throw new Error("No browser found");
117+
}
106118
BrowserTestUtils.startLoadingURIString(browser, uri(0));
107119
await BrowserTestUtils.browserLoaded(browser);
108120

109-
using _tab1 = await GlideTestUtils.new_tab(uri(1));
110-
using tab2 = await GlideTestUtils.new_tab(uri(2));
111-
using tab3 = await GlideTestUtils.new_tab(uri(3));
112-
using _tab4 = await GlideTestUtils.new_tab(uri(4));
121+
const _tab1 = await GlideTestUtils.new_tab(uri(1));
122+
const tab2 = await GlideTestUtils.new_tab(uri(2));
123+
const tab3 = await GlideTestUtils.new_tab(uri(3));
124+
const _tab4 = await GlideTestUtils.new_tab(uri(4));
113125

114126
is(current_url(), uri(4), "Currently on tab4");
115127

src/glide/browser/base/content/test/search/browser_search_engines.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ add_task(async function test_add_search_engine_with_multiple_keywords() {
8989
for (const alias of ["first", "second", "third"]) {
9090
await sleep_frames(2);
9191

92-
using __ = await GlideTestUtils.new_tab();
92+
const __ = await GlideTestUtils.new_tab();
9393

9494
await focus_address_bar();
9595
await keys(`@${alias}<CR>${alias}`);

0 commit comments

Comments
 (0)