From 8e61cac16b22b38827c06d153c1936dad84f56e5 Mon Sep 17 00:00:00 2001 From: CodeWithMaBot <310216433+CodeWithMaBot@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:42:28 +0100 Subject: [PATCH 1/2] chore: remove AI code slop across the codebase - Narrow instead of non-null assertions and casts; drop annotations and generics that inference covers. - Collapse duplicated blocks (provider settings defaults, round-robin comparator, stats counts, home filters, season-editor patches, AniList search query, storage migration loops). - Flatten nesting with early returns and small helpers. - Remove unreachable guards whose callers or schemas already guarantee the condition. - Simplify specs: typed file-selection helper in settings spec, a minimal FileReader double, real Files instead of stubbed text(). Co-Authored-By: Claude Opus 5.5 --- scripts/build.mjs | 14 +-- src/app/app.ts | 1 - .../components/add-item/add-item.component.ts | 33 ++--- .../components/home/home.component.spec.ts | 26 +--- src/app/components/home/home.component.ts | 41 +++--- .../item-card/item-card.component.ts | 15 +-- .../item-detail/item-detail.component.ts | 13 +- .../item-form/item-form.component.ts | 37 ++---- .../item-list/item-list.component.ts | 4 +- .../item-view/item-view.component.ts | 4 +- .../poster-picker.component.spec.ts | 23 ++-- .../poster-picker/poster-picker.component.ts | 4 +- .../season-editor/season-editor.component.ts | 46 +++---- .../settings/settings.component.spec.ts | 91 ++++---------- .../components/settings/settings.component.ts | 45 ++++--- .../stats-heatmap/stats-heatmap.component.ts | 12 +- .../theme-switcher.component.ts | 14 +-- .../components/time-ago/time-ago.component.ts | 31 ++--- .../directives/file-picker-focus.directive.ts | 4 +- src/app/domain/episode-release.ts | 2 +- src/app/domain/item-form.ts | 11 +- src/app/domain/item.constants.ts | 2 +- src/app/domain/storage-schema.ts | 36 ++---- .../services/anilist-suggestion.service.ts | 73 ++++------- .../services/collection-normalization.spec.ts | 4 +- src/app/services/context-conflicts.spec.ts | 2 +- .../services/image-storage.service.spec.ts | 117 +++--------------- src/app/services/image-storage.service.ts | 24 ++-- .../services/import-export.service.spec.ts | 20 +-- src/app/services/import-export.service.ts | 86 ++++++------- .../services/indexeddb-write.test-utils.ts | 6 +- src/app/services/item-mutations.spec.ts | 6 +- src/app/services/item-sort.service.ts | 8 +- src/app/services/jikan-suggestion.service.ts | 29 ++--- .../services/poster-context-conflicts.spec.ts | 16 +-- src/app/services/provider-settings.service.ts | 29 ++--- src/app/services/round-robin.service.spec.ts | 2 +- src/app/services/round-robin.service.ts | 37 ++---- src/app/services/session-recovery.spec.ts | 58 +++------ src/app/services/stats.service.ts | 40 +++--- src/app/services/storage.service.spec.ts | 20 ++- src/app/services/storage.service.ts | 38 ++---- .../suggestion-search.service.spec.ts | 2 +- src/app/services/suggestion-search.service.ts | 6 +- src/app/services/theme.service.ts | 31 ++--- src/app/services/tmdb-suggestion.service.ts | 20 ++- src/app/services/watch-list.service.spec.ts | 19 ++- src/app/services/watch-list.service.ts | 7 +- src/app/utils/date.utils.ts | 2 +- src/app/utils/form.utils.ts | 9 +- src/app/utils/progress.utils.spec.ts | 2 +- src/app/utils/progress.utils.ts | 12 +- src/app/utils/sort.utils.spec.ts | 2 +- src/app/utils/sort.utils.ts | 9 +- src/app/utils/watch-history.utils.ts | 8 +- 55 files changed, 433 insertions(+), 820 deletions(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index 609ea64b..9d755ed6 100755 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -1,7 +1,6 @@ #!/usr/bin/env node -import { spawnSync } from 'node:child_process'; +import { execSync, spawnSync } from 'node:child_process'; import { readFileSync } from 'node:fs'; -import { execSync } from 'node:child_process'; function getVersion() { try { @@ -17,19 +16,18 @@ function getHash() { if (process.env.GITHUB_SHA) return process.env.GITHUB_SHA; if (process.env.COMMIT_HASH) return process.env.COMMIT_HASH; try { - return execSync('git rev-parse HEAD', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] }).trim(); + return execSync('git rev-parse HEAD', { + encoding: 'utf8', + stdio: ['pipe', 'pipe', 'ignore'], + }).trim(); } catch { return 'unknown'; } } -function getBuildDate() { - return new Date().toISOString(); -} - const version = getVersion(); const hash = getHash(); -const buildDate = getBuildDate(); +const buildDate = new Date().toISOString(); const extraArgs = process.argv.slice(2); diff --git a/src/app/app.ts b/src/app/app.ts index 1f5e4962..efbc95a9 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -23,7 +23,6 @@ export class App { private readonly importExportService = inject(ImportExportService); private readonly document = inject(DOCUMENT); private readonly updates = inject(SwUpdate, { optional: true }); - protected readonly title = signal('watch-list'); protected readonly saveError = this.storageService.getSaveErrorSignal(); protected readonly inMemorySession = this.storageService.getInMemorySessionSignal(); protected readonly settingsUnavailable = inject(BrowserSettingsStorage).unavailable; diff --git a/src/app/components/add-item/add-item.component.ts b/src/app/components/add-item/add-item.component.ts index 5d030928..961f1878 100644 --- a/src/app/components/add-item/add-item.component.ts +++ b/src/app/components/add-item/add-item.component.ts @@ -5,7 +5,7 @@ import { of, Subject, switchMap } from 'rxjs'; import { WatchListService } from '../../services/watch-list.service'; import { GroupService } from '../../services/group.service'; import { SuggestionSearchService } from '../../services/suggestion-search.service'; -import { ItemFormComponent } from '../item-form/item-form.component'; +import { ItemFormAutofillPatch, ItemFormComponent } from '../item-form/item-form.component'; import { buildItemMutationInput, createDefaultItemFormValue, @@ -81,7 +81,7 @@ export class AddItemComponent { readonly suggestions = this.search.results; readonly suggestionsLoading = this.search.loading; readonly suggestionsError = this.search.error; - readonly autofillPatch = signal<{ id: number; value: Partial } | null>(null); + readonly autofillPatch = signal(null); private autofillPatchId = 0; readonly duplicateTitleHint = computed(() => { const normalizedTitle = this.normalizeTitle(this.title()); @@ -99,13 +99,7 @@ export class AddItemComponent { constructor() { this.selectedEpisodicRef .pipe( - switchMap((ref) => { - if (ref === null) { - return of(null); - } - - return this.suggestionSearchService.getDetails(ref); - }), + switchMap((ref) => (ref ? this.suggestionSearchService.getDetails(ref) : of(null))), takeUntilDestroyed(this.destroyRef), ) .subscribe((details) => { @@ -113,12 +107,7 @@ export class AddItemComponent { return; } - this.autofillPatch.set({ - id: ++this.autofillPatchId, - value: { - seasons: details.seasons, - }, - }); + this.autofillPatch.set({ id: ++this.autofillPatchId, value: { seasons: details.seasons } }); }); } @@ -136,21 +125,13 @@ export class AddItemComponent { onSuggestionSelected(suggestion: Suggestion): void { this.title.set(suggestion.title); this.search.dismiss(suggestion.title); - - if (!isEpisodicType(suggestion.type)) { - this.autofillPatch.set({ - id: ++this.autofillPatchId, - value: { season: 1, episode: 1, seasons: [] }, - }); - this.selectedEpisodicRef.next(null); - return; - } - this.autofillPatch.set({ id: ++this.autofillPatchId, value: { season: 1, episode: 1, seasons: [] }, }); - this.selectedEpisodicRef.next({ source: suggestion.source, id: suggestion.id }); + this.selectedEpisodicRef.next( + isEpisodicType(suggestion.type) ? { source: suggestion.source, id: suggestion.id } : null, + ); } async onSubmit(formValue: ItemFormValue): Promise { diff --git a/src/app/components/home/home.component.spec.ts b/src/app/components/home/home.component.spec.ts index 60667e78..82d4cfb5 100644 --- a/src/app/components/home/home.component.spec.ts +++ b/src/app/components/home/home.component.spec.ts @@ -208,12 +208,7 @@ describe('HomeComponent', () => { it('markItem delegates to correct service methods', async () => { setup(); const fixture = TestBed.createComponent(HomeComponent); - const svc = TestBed.inject(WatchListService) as unknown as { - markWatched: ReturnType; - markCompleted: ReturnType; - markDropped: ReturnType; - markPaused: ReturnType; - }; + const svc = TestBed.inject(WatchListService); const item = createItem({ id: 'x', title: 'X', status: 'in-progress', isAdult: false }); await fixture.componentInstance.markItem(() => item, 'watched'); @@ -332,26 +327,17 @@ describe('HomeComponent', () => { expect(fixture.nativeElement.textContent).toContain('No movies currently being watched'); }); - it('computes hasSeries and hasMovies correctly', () => { + it('distinguishes an empty watch list from one with nothing in progress', () => { setup({ watchItems: [createItem({ id: '1', title: 'S', type: 'series' })] }); let fixture = TestBed.createComponent(HomeComponent); fixture.detectChanges(); - expect((fixture.componentInstance as unknown as { hasSeries: () => boolean }).hasSeries()).toBe( - true, - ); + expect(fixture.nativeElement.textContent).toContain('No series currently being watched'); + expect(fixture.nativeElement.textContent).toContain('No movies in your watch list'); setup({ watchItems: [createItem({ id: '2', title: 'M', type: 'movie' })] }); fixture = TestBed.createComponent(HomeComponent); fixture.detectChanges(); - expect((fixture.componentInstance as unknown as { hasMovies: () => boolean }).hasMovies()).toBe( - true, - ); - - setup({ watchItems: [] }); - fixture = TestBed.createComponent(HomeComponent); - fixture.detectChanges(); - expect((fixture.componentInstance as unknown as { hasSeries: () => boolean }).hasSeries()).toBe( - false, - ); + expect(fixture.nativeElement.textContent).toContain('No movies currently being watched'); + expect(fixture.nativeElement.textContent).toContain('No series in your watch list'); }); }); diff --git a/src/app/components/home/home.component.ts b/src/app/components/home/home.component.ts index f879b244..7896aa49 100644 --- a/src/app/components/home/home.component.ts +++ b/src/app/components/home/home.component.ts @@ -4,7 +4,7 @@ import { RouterLink } from '@angular/router'; import { RoundRobinService } from '../../services/round-robin.service'; import { WatchListService } from '../../services/watch-list.service'; import { ItemCardComponent } from '../item-card/item-card.component'; -import { ReadonlyItem as Item, ItemType } from '../../models/item.model'; +import { ReadonlyItem as Item, ItemStatus } from '../../models/item.model'; import { isEpisodicType } from '../../domain/item.constants'; import { ProviderSettingsService } from '../../services/provider-settings.service'; import { watchActionFailure } from '../watch-action-feedback'; @@ -53,9 +53,9 @@ import { DiscussionLinkComponent } from '../discussion-link/discussion-link.comp > Next Series - @if (nextSeries()) { + @if (nextSeries(); as series) {
- +