chore(eslint): add ESLint toolchain and clean src to strict 0/0 (#1165)

* chore(eslint): add eslint toolchain and configs

* fix(eslint): resolve gradual-config errors (rules-of-hooks, no-empty, prefer-const, …)

* chore(eslint): clear unused vars in config, contexts, app and test

* chore(eslint): clear unused vars in api and music-network

* chore(eslint): clear unused vars in utils

* chore(eslint): clear unused vars in store

* chore(eslint): clear unused vars in cover and hooks

* chore(eslint): clear unused vars in components

* chore(eslint): clear unused vars in pages

* chore(eslint): remove explicit any in src

* chore(eslint): align react-hooks exhaustive-deps

* chore(eslint): zero gradual config on src

* chore(eslint): strict hook rules in store and utils

* chore(eslint): strict hook rules in hooks and cover

* chore(eslint): strict hook rules in components

* chore(eslint): strict hook rules in pages and contexts

* chore(eslint): document scripts ignore in eslint config

* chore(eslint): add lint script and zero strict findings

* chore(eslint): address review round 1 (gradual 0/0, per-site disable reasons)

* chore(eslint): tighten two set-state disable comments (review round 2 LOW)

* chore(nix): sync npmDepsHash with package-lock.json

* docs(changelog): add Under the Hood entry for ESLint setup (PR #1165)

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Psychotoxical
2026-06-24 01:33:34 +02:00
committed by GitHub
parent c7d76af790
commit 7c724a642f
258 changed files with 2987 additions and 601 deletions
@@ -9,7 +9,6 @@ import type { ShareQueuePreviewState } from '../../hooks/useShareQueuePreview';
import { sharePayloadTotal, type QueueableShareSearchPayload } from '../../utils/share/shareSearch';
import OverlayScrollArea from '../OverlayScrollArea';
import { usePlayerStore } from '../../store/playerStore';
import { CoverArtImage } from '../../cover/CoverArtImage';
import { COVER_DENSE_SEARCH_CSS_PX } from '../../cover/layoutSizes';
import { COVER_SCOPE_ACTIVE, type CoverServerScope } from '../../cover/types';
import { AlbumCoverArtImage } from '../../cover/AlbumCoverArtImage';
+3 -1
View File
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
import { Disc3, Eye, Link2, ListPlus, Music, Users } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import type { TFunction } from 'i18next';
import type { SubsonicAlbum, SubsonicArtist, SubsonicSong } from '../../api/subsonicTypes';
import type { SubsonicArtist } from '../../api/subsonicTypes';
import type { ServerProfile } from '../../store/authStoreTypes';
import { songToTrack } from '../../utils/playback/songToTrack';
import { activateShareSearchServer } from '../../utils/share/enqueueShareSearchPayload';
@@ -80,6 +80,8 @@ function ShareArtistThumb({
coverServer?: ServerProfile | null;
}) {
const [failed, setFailed] = useState(false);
// React Compiler set-state-in-effect rule: local state synced with store/prop inputs when the effects dependencies change.
// eslint-disable-next-line react-hooks/set-state-in-effect
useEffect(() => { setFailed(false); }, [artist.id, artist.coverArt]);
if (failed) {
+175
View File
@@ -0,0 +1,175 @@
import type { KeyboardEvent, MouseEvent } from 'react';
import { ALL_NAV_ITEMS } from '../../config/navItems';
import type { LiveSearchScope } from '../../store/liveSearchScopeStore';
import { isAlbumsBrowsePath, isNewReleasesBrowsePath } from '../../store/albumBrowseSessionStore';
import { isTracksBrowsePath } from '../../store/advancedSearchSessionStore';
import { isArtistsBrowsePath } from '../../store/artistBrowseSessionStore';
import { isComposersBrowsePath } from '../../store/composerBrowseSessionStore';
export const SCOPE_NAV_ITEM: Record<LiveSearchScope, keyof typeof ALL_NAV_ITEMS> = {
artists: 'artists',
albums: 'allAlbums',
newReleases: 'newReleases',
tracks: 'tracks',
composers: 'composers',
};
/** Scope to restore when on a browse route but the badge was cleared (global search mode). */
export function resolveLiveSearchScopeGhost(
pathname: string,
activeScope: LiveSearchScope | null,
): LiveSearchScope | null {
if (activeScope != null) return null;
if (isArtistsBrowsePath(pathname)) return 'artists';
if (isAlbumsBrowsePath(pathname)) return 'albums';
if (isNewReleasesBrowsePath(pathname)) return 'newReleases';
if (isTracksBrowsePath(pathname)) return 'tracks';
if (isComposersBrowsePath(pathname)) return 'composers';
return null;
}
export function liveSearchScopePlaceholderKey(scope: LiveSearchScope | null): string {
switch (scope) {
case 'artists':
return 'search.scopeArtistsPlaceholder';
case 'albums':
return 'search.scopeAlbumsPlaceholder';
case 'newReleases':
return 'search.scopeNewReleasesPlaceholder';
case 'tracks':
return 'search.scopeTracksPlaceholder';
case 'composers':
return 'search.scopeComposersPlaceholder';
default:
return 'search.placeholder';
}
}
/** Scoped browse mode filters the page only — no live-search dropdown. */
export function isLiveSearchDropdownBlocked(scope: LiveSearchScope | null): boolean {
return scope != null;
}
export function liveSearchScopeBadgeTooltipKey(scope: LiveSearchScope): string {
switch (scope) {
case 'artists':
return 'search.scopeArtistsBadgeTooltip';
case 'albums':
return 'search.scopeAlbumsBadgeTooltip';
case 'newReleases':
return 'search.scopeNewReleasesBadgeTooltip';
case 'tracks':
return 'search.scopeTracksBadgeTooltip';
case 'composers':
return 'search.scopeComposersBadgeTooltip';
default:
return 'search.scopeArtistsBadgeTooltip';
}
}
export function liveSearchScopeGhostTooltipKey(scope: LiveSearchScope): string {
switch (scope) {
case 'artists':
return 'search.scopeArtistsGhostTooltip';
case 'albums':
return 'search.scopeAlbumsGhostTooltip';
case 'newReleases':
return 'search.scopeNewReleasesGhostTooltip';
case 'tracks':
return 'search.scopeTracksGhostTooltip';
case 'composers':
return 'search.scopeComposersGhostTooltip';
default:
return 'search.scopeArtistsGhostTooltip';
}
}
/** Tracks Backspace-on-empty badge removal (double after prior text input). */
export type LiveSearchScopeBackspaceState = {
hadQueryInput: boolean;
emptyBackspaceStreak: number;
};
export function createLiveSearchScopeBackspaceState(): LiveSearchScopeBackspaceState {
return { hadQueryInput: false, emptyBackspaceStreak: 0 };
}
export function resetLiveSearchScopeBackspaceState(state: LiveSearchScopeBackspaceState): void {
state.hadQueryInput = false;
state.emptyBackspaceStreak = 0;
}
/** Call when the scoped field query changes (typing, paste, clear button, undo). */
export function noteLiveSearchScopeQueryInput(
state: LiveSearchScopeBackspaceState,
query: string,
): void {
if (query !== '') state.hadQueryInput = true;
}
/**
* Backspace on an empty scoped field removes the badge.
* After the user typed text (even if cleared), two consecutive Backspaces on empty are required.
*/
export function handleLiveSearchScopeBackspace(
e: KeyboardEvent<HTMLInputElement>,
query: string,
scope: LiveSearchScope | null,
clearScope: (options?: { recordUndo?: boolean }) => void,
state: LiveSearchScopeBackspaceState,
): boolean {
if (e.key !== 'Backspace' || !scope) return false;
if (query !== '') {
state.emptyBackspaceStreak = 0;
return false;
}
e.preventDefault();
if (!state.hadQueryInput) {
clearScope({ recordUndo: true });
resetLiveSearchScopeBackspaceState(state);
return true;
}
state.emptyBackspaceStreak += 1;
if (state.emptyBackspaceStreak >= 2) {
clearScope({ recordUndo: true });
resetLiveSearchScopeBackspaceState(state);
return true;
}
return true;
}
/** Single click removes the scope badge. */
export function handleLiveSearchScopeBadgeClick(
e: MouseEvent<HTMLElement>,
clearScope: (options?: { recordUndo?: boolean }) => void,
): void {
e.preventDefault();
e.stopPropagation();
clearScope({ recordUndo: true });
}
/** Single click restores scope after the user cleared the badge on this browse route. */
export function handleLiveSearchScopeGhostClick(
e: MouseEvent<HTMLElement>,
scope: LiveSearchScope,
setScope: (scope: LiveSearchScope, options?: { recordUndo?: boolean }) => void,
): void {
e.preventDefault();
e.stopPropagation();
setScope(scope, { recordUndo: true });
}
/** Field-local undo (Ctrl/Cmd+Z) for live search query and scope badge. */
export function handleLiveSearchScopeUndo(
e: KeyboardEvent<HTMLInputElement>,
undo: () => boolean,
): boolean {
const isUndoKey = e.code === 'KeyZ' || e.key.toLowerCase() === 'z';
if (!isUndoKey || !(e.ctrlKey || e.metaKey) || e.shiftKey) return false;
e.preventDefault();
return undo();
}
@@ -11,7 +11,7 @@ import {
noteLiveSearchScopeQueryInput,
resetLiveSearchScopeBackspaceState,
resolveLiveSearchScopeGhost,
} from './liveSearchScopeUi';
} from './liveSearchScope';
function keyEvent(
key: string,
+7 -173
View File
@@ -1,89 +1,13 @@
import type { KeyboardEvent, MouseEvent } from 'react';
import { useTranslation } from 'react-i18next';
import { ALL_NAV_ITEMS } from '../../config/navItems';
import type { LiveSearchScope } from '../../store/liveSearchScopeStore';
import { isAlbumsBrowsePath, isNewReleasesBrowsePath } from '../../store/albumBrowseSessionStore';
import { isTracksBrowsePath } from '../../store/advancedSearchSessionStore';
import { isArtistsBrowsePath } from '../../store/artistBrowseSessionStore';
import { isComposersBrowsePath } from '../../store/composerBrowseSessionStore';
const SCOPE_NAV_ITEM: Record<LiveSearchScope, keyof typeof ALL_NAV_ITEMS> = {
artists: 'artists',
albums: 'allAlbums',
newReleases: 'newReleases',
tracks: 'tracks',
composers: 'composers',
};
/** Scope to restore when on a browse route but the badge was cleared (global search mode). */
export function resolveLiveSearchScopeGhost(
pathname: string,
activeScope: LiveSearchScope | null,
): LiveSearchScope | null {
if (activeScope != null) return null;
if (isArtistsBrowsePath(pathname)) return 'artists';
if (isAlbumsBrowsePath(pathname)) return 'albums';
if (isNewReleasesBrowsePath(pathname)) return 'newReleases';
if (isTracksBrowsePath(pathname)) return 'tracks';
if (isComposersBrowsePath(pathname)) return 'composers';
return null;
}
export function liveSearchScopePlaceholderKey(scope: LiveSearchScope | null): string {
switch (scope) {
case 'artists':
return 'search.scopeArtistsPlaceholder';
case 'albums':
return 'search.scopeAlbumsPlaceholder';
case 'newReleases':
return 'search.scopeNewReleasesPlaceholder';
case 'tracks':
return 'search.scopeTracksPlaceholder';
case 'composers':
return 'search.scopeComposersPlaceholder';
default:
return 'search.placeholder';
}
}
/** Scoped browse mode filters the page only — no live-search dropdown. */
export function isLiveSearchDropdownBlocked(scope: LiveSearchScope | null): boolean {
return scope != null;
}
export function liveSearchScopeBadgeTooltipKey(scope: LiveSearchScope): string {
switch (scope) {
case 'artists':
return 'search.scopeArtistsBadgeTooltip';
case 'albums':
return 'search.scopeAlbumsBadgeTooltip';
case 'newReleases':
return 'search.scopeNewReleasesBadgeTooltip';
case 'tracks':
return 'search.scopeTracksBadgeTooltip';
case 'composers':
return 'search.scopeComposersBadgeTooltip';
default:
return 'search.scopeArtistsBadgeTooltip';
}
}
export function liveSearchScopeGhostTooltipKey(scope: LiveSearchScope): string {
switch (scope) {
case 'artists':
return 'search.scopeArtistsGhostTooltip';
case 'albums':
return 'search.scopeAlbumsGhostTooltip';
case 'newReleases':
return 'search.scopeNewReleasesGhostTooltip';
case 'tracks':
return 'search.scopeTracksGhostTooltip';
case 'composers':
return 'search.scopeComposersGhostTooltip';
default:
return 'search.scopeArtistsGhostTooltip';
}
}
import {
SCOPE_NAV_ITEM,
handleLiveSearchScopeBadgeClick,
handleLiveSearchScopeGhostClick,
liveSearchScopeBadgeTooltipKey,
liveSearchScopeGhostTooltipKey,
} from './liveSearchScope';
type LiveSearchScopeIconProps = {
scope: LiveSearchScope;
@@ -96,85 +20,6 @@ export function LiveSearchScopeIcon({ scope, size = 14 }: LiveSearchScopeIconPro
return <Icon size={size} aria-hidden />;
}
/** Tracks Backspace-on-empty badge removal (double after prior text input). */
export type LiveSearchScopeBackspaceState = {
hadQueryInput: boolean;
emptyBackspaceStreak: number;
};
export function createLiveSearchScopeBackspaceState(): LiveSearchScopeBackspaceState {
return { hadQueryInput: false, emptyBackspaceStreak: 0 };
}
export function resetLiveSearchScopeBackspaceState(state: LiveSearchScopeBackspaceState): void {
state.hadQueryInput = false;
state.emptyBackspaceStreak = 0;
}
/** Call when the scoped field query changes (typing, paste, clear button, undo). */
export function noteLiveSearchScopeQueryInput(
state: LiveSearchScopeBackspaceState,
query: string,
): void {
if (query !== '') state.hadQueryInput = true;
}
/**
* Backspace on an empty scoped field removes the badge.
* After the user typed text (even if cleared), two consecutive Backspaces on empty are required.
*/
export function handleLiveSearchScopeBackspace(
e: KeyboardEvent<HTMLInputElement>,
query: string,
scope: LiveSearchScope | null,
clearScope: (options?: { recordUndo?: boolean }) => void,
state: LiveSearchScopeBackspaceState,
): boolean {
if (e.key !== 'Backspace' || !scope) return false;
if (query !== '') {
state.emptyBackspaceStreak = 0;
return false;
}
e.preventDefault();
if (!state.hadQueryInput) {
clearScope({ recordUndo: true });
resetLiveSearchScopeBackspaceState(state);
return true;
}
state.emptyBackspaceStreak += 1;
if (state.emptyBackspaceStreak >= 2) {
clearScope({ recordUndo: true });
resetLiveSearchScopeBackspaceState(state);
return true;
}
return true;
}
/** Single click removes the scope badge. */
export function handleLiveSearchScopeBadgeClick(
e: MouseEvent<HTMLElement>,
clearScope: (options?: { recordUndo?: boolean }) => void,
): void {
e.preventDefault();
e.stopPropagation();
clearScope({ recordUndo: true });
}
/** Single click restores scope after the user cleared the badge on this browse route. */
export function handleLiveSearchScopeGhostClick(
e: MouseEvent<HTMLElement>,
scope: LiveSearchScope,
setScope: (scope: LiveSearchScope, options?: { recordUndo?: boolean }) => void,
): void {
e.preventDefault();
e.stopPropagation();
setScope(scope, { recordUndo: true });
}
type LiveSearchScopeBadgeProps = {
scope: LiveSearchScope;
className: string;
@@ -224,14 +69,3 @@ export function LiveSearchScopeGhostBadge({ scope, className, setScope }: LiveSe
</span>
);
}
/** Field-local undo (Ctrl/Cmd+Z) for live search query and scope badge. */
export function handleLiveSearchScopeUndo(
e: KeyboardEvent<HTMLInputElement>,
undo: () => boolean,
): boolean {
const isUndoKey = e.code === 'KeyZ' || e.key.toLowerCase() === 'z';
if (!isUndoKey || !(e.ctrlKey || e.metaKey) || e.shiftKey) return false;
e.preventDefault();
return undo();
}