fix: linter errors

This commit is contained in:
Xiaohan-Tian
2026-05-01 14:36:56 -07:00
parent 9be96cd957
commit cd90dc1c99
18 changed files with 90 additions and 80 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ import type { RenderingEvent } from './core/audio-interface/KGOfflineRenderer';
import { KGCore } from './core/KGCore';
import { ConfigManager } from './core/config/ConfigManager';
import { validateFunctionalChordsJSON } from './util/scaleUtil';
import { showAlert } from './components/common/DialogProvider';
import { showAlert } from './util/dialogUtil';
import { KGProjectStorage } from './core/io/KGProjectStorage';
import { RESERVED_PROJECT_NAME } from './util/projectNameUtil';
+1 -1
View File
@@ -14,7 +14,7 @@ import { sliceAudioToWav } from '../util/audioUtil';
import type { KeySignature } from '../core/KGProject';
import { ImportStemsCommand } from '../core/commands';
import type { StemImportEntry } from '../core/commands';
import { showAlert } from './common/DialogProvider';
import { showAlert } from '../util/dialogUtil';
// ─── Types ────────────────────────────────────────────────────────────────────
+1 -1
View File
@@ -33,7 +33,7 @@ import { clearChatHistoryAndUI } from '../util/chatUtil';
import PianoIcon from './common/icons/PianoIcon';
import MetronomeIcon from './common/icons/MetronomeIcon';
import { ConfigManager } from '../core/config/ConfigManager';
import { showAlert, showConfirm, showPrompt, showTimeSigPrompt } from './common/DialogProvider';
import { showAlert, showConfirm, showPrompt, showTimeSigPrompt } from '../util/dialogUtil';
const Toolbar: React.FC = () => {
const {
+3 -58
View File
@@ -1,60 +1,8 @@
import React, { useState, useCallback, useRef } from 'react';
import './DialogProvider.css';
import { FaTimes } from 'react-icons/fa';
export interface ConfirmOptions {
confirmLabel?: string;
cancelLabel?: string;
}
export interface PromptOptions {
confirmLabel?: string;
cancelLabel?: string;
placeholder?: string;
}
export interface TimeSigResult {
numerator: number;
denominator: number;
}
let _showAlertFn: ((message: string) => Promise<void>) | null = null;
let _showConfirmFn: ((message: string, options?: ConfirmOptions) => Promise<boolean>) | null = null;
let _showPromptFn: ((message: string, defaultValue?: string, options?: PromptOptions) => Promise<string | null>) | null = null;
let _showTimeSigFn: ((message: string, defaultValue?: TimeSigResult) => Promise<TimeSigResult | null>) | null = null;
export function showAlert(message: string): Promise<void> {
if (!_showAlertFn) {
window.alert(message);
return Promise.resolve();
}
return _showAlertFn(message);
}
export function showConfirm(message: string, options?: ConfirmOptions): Promise<boolean> {
if (!_showConfirmFn) {
return Promise.resolve(window.confirm(message));
}
return _showConfirmFn(message, options);
}
export function showPrompt(message: string, defaultValue?: string, options?: PromptOptions): Promise<string | null> {
if (!_showPromptFn) {
return Promise.resolve(window.prompt(message, defaultValue));
}
return _showPromptFn(message, defaultValue, options);
}
export function showTimeSigPrompt(message: string, defaultValue?: TimeSigResult): Promise<TimeSigResult | null> {
if (!_showTimeSigFn) {
const raw = window.prompt(message, defaultValue ? `${defaultValue.numerator}/${defaultValue.denominator}` : '4/4');
if (!raw) return Promise.resolve(null);
const [n, d] = raw.split('/').map(Number);
if (!n || !d) return Promise.resolve(null);
return Promise.resolve({ numerator: n, denominator: d });
}
return _showTimeSigFn(message, defaultValue);
}
import { registerDialogFns } from '../../util/dialogUtil';
import type { ConfirmOptions, PromptOptions, TimeSigResult } from '../../util/dialogUtil';
interface DialogInfo {
type: 'alert' | 'confirm' | 'prompt' | 'timesig';
@@ -129,10 +77,7 @@ const DialogProvider: React.FC<{ children: React.ReactNode }> = ({ children }) =
const registered = useRef(false);
if (!registered.current) {
registered.current = true;
_showAlertFn = openAlert;
_showConfirmFn = openConfirm;
_showPromptFn = openPrompt;
_showTimeSigFn = openTimeSig;
registerDialogFns(openAlert, openConfirm, openPrompt, openTimeSig);
}
if (!dialog) {
+1 -1
View File
@@ -1,7 +1,7 @@
import React, { useCallback, useRef, useState } from 'react';
import './FileImportModal.css';
import { FaTimes } from 'react-icons/fa';
import { showAlert } from './DialogProvider';
import { showAlert } from '../../util/dialogUtil';
interface FileImportModalProps {
isVisible: boolean;
+1 -1
View File
@@ -3,7 +3,7 @@ import { FaTimes, FaSortUp, FaSortDown, FaCopy, FaTrash, FaUndo } from 'react-ic
import { KGProjectStorage, type ProjectMeta } from '../../core/io/KGProjectStorage';
import { isValidProjectName } from '../../util/projectNameUtil';
import './OpenProjectModal.css';
import { showAlert, showConfirm, showPrompt } from './DialogProvider';
import { showAlert, showConfirm, showPrompt } from '../../util/dialogUtil';
interface OpenProjectModalProps {
onClose: () => void;
+3 -2
View File
@@ -3,5 +3,6 @@ export { default as Playhead } from './Playhead';
export { default as FileImportModal } from './FileImportModal';
export { default as LoadingOverlay } from './LoadingOverlay';
export { default as OpenProjectModal } from './OpenProjectModal';
export { default as DialogProvider, showAlert, showConfirm, showPrompt, showTimeSigPrompt } from './DialogProvider';
export type { ConfirmOptions, PromptOptions, TimeSigResult } from './DialogProvider';
export { default as DialogProvider } from './DialogProvider';
export { showAlert, showConfirm, showPrompt, showTimeSigPrompt } from '../../util/dialogUtil';
export type { ConfirmOptions, PromptOptions, TimeSigResult } from '../../util/dialogUtil';
+1 -1
View File
@@ -15,7 +15,7 @@ import { ConfigManager } from '../../core/config/ConfigManager';
import { beatsToBar } from '../../util/midiUtil';
import { UpdateRegionCommand } from '../../core/commands';
import { getSuitableChords, noteNameToPitchClass } from '../../util/scaleUtil';
import { showAlert, showPrompt } from '../common/DialogProvider';
import { showAlert, showPrompt } from '../../util/dialogUtil';
interface PianoRollProps {
onClose: () => void;
@@ -2,7 +2,7 @@ import React, { useState, useEffect, useCallback } from 'react';
import { ConfigManager } from '../../../core/config/ConfigManager';
import { validateFunctionalChordsJSON } from '../../../util/scaleUtil';
import { KGCore } from '../../../core/KGCore';
import { showAlert } from '../../common/DialogProvider';
import { showAlert } from '../../../util/dialogUtil';
const ChordGuideSettings: React.FC = () => {
const [chordDefinition, setChordDefinition] = useState<string>('');
+1 -1
View File
@@ -13,7 +13,7 @@ import { KGAudioInterface } from '../../core/audio-interface/KGAudioInterface';
import { KGAudioRegion } from '../../core/region/KGAudioRegion';
import { generateNewRegionName } from '../../util/miscUtil';
import { KGAudioFileStorage } from '../../core/io/KGAudioFileStorage';
import { showAlert } from '../common/DialogProvider';
import { showAlert } from '../../util/dialogUtil';
import { parseMidiFirstTrackNotes } from '../../util/midiUtil';
import * as Tone from 'tone';
+1 -1
View File
@@ -12,7 +12,7 @@ import { FLUIDR3_INSTRUMENT_MAP } from '../../constants/generalMidiConstants';
import { DEBUG_MODE } from '../../constants/uiConstants';
import { KGAudioInterface } from '../../core/audio-interface/KGAudioInterface';
import { AUDIO_INTERFACE_CONSTANTS } from '../../constants/coreConstants';
import { showAlert, showConfirm, showPrompt } from '../common/DialogProvider';
import { showAlert, showConfirm, showPrompt } from '../../util/dialogUtil';
const UNITY_POS = 750;
const SLIDER_MAX = 1000;
+2 -4
View File
@@ -513,8 +513,7 @@ export class KGDebugger {
try {
textarea.selectionStart = textarea.selectionEnd = typed.length;
} catch {
}
} catch { /* setting cursor position can fail in read-only or special inputs */ }
textarea.scrollTop = textarea.scrollHeight;
@@ -583,8 +582,7 @@ export class KGDebugger {
try {
textarea.selectionStart = textarea.selectionEnd = typed.length;
} catch {
}
} catch { /* setting cursor position can fail in read-only or special inputs */ }
textarea.scrollTop = textarea.scrollHeight;
@@ -47,9 +47,8 @@ class MockFileHandle {
async getFile() { return { text: () => Promise.resolve(this._content) }; }
async createWritable() {
const w = new MockWritable();
const self = this;
const origClose = w.close.bind(w);
w.close = async () => { self._content = w.data; await origClose(); };
w.close = async () => { this._content = w.data; await origClose(); };
return w;
}
}
+1 -2
View File
@@ -19,10 +19,9 @@ class MockFileSystemFileHandle {
async createWritable() {
const stream = new MockFileSystemWritableFileStream();
// When stream closes, update our content
const self = this;
const origClose = stream.close.bind(stream);
stream.close = async () => {
self._content = stream.data;
this._content = stream.data;
await origClose();
};
return stream;
+3
View File
@@ -5,11 +5,13 @@
import { vi } from 'vitest';
// In-memory storage for tests
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mockStorage = new Map<string, any>();
export const mockIndexedDB = {
openDB: vi.fn().mockImplementation(() => {
return Promise.resolve({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
put: vi.fn().mockImplementation((storeName: string, data: any, key?: string) => {
const actualKey = key || data.id || 'default';
mockStorage.set(`${storeName}:${actualKey}`, data);
@@ -21,6 +23,7 @@ export const mockIndexedDB = {
}),
getAll: vi.fn().mockImplementation((storeName: string) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const results: any[] = [];
for (const [key, value] of mockStorage.entries()) {
if (key.startsWith(`${storeName}:`)) {
+65
View File
@@ -0,0 +1,65 @@
export interface ConfirmOptions {
confirmLabel?: string;
cancelLabel?: string;
}
export interface PromptOptions {
confirmLabel?: string;
cancelLabel?: string;
placeholder?: string;
}
export interface TimeSigResult {
numerator: number;
denominator: number;
}
let _showAlertFn: ((message: string) => Promise<void>) | null = null;
let _showConfirmFn: ((message: string, options?: ConfirmOptions) => Promise<boolean>) | null = null;
let _showPromptFn: ((message: string, defaultValue?: string, options?: PromptOptions) => Promise<string | null>) | null = null;
let _showTimeSigFn: ((message: string, defaultValue?: TimeSigResult) => Promise<TimeSigResult | null>) | null = null;
export function registerDialogFns(
alertFn: (message: string) => Promise<void>,
confirmFn: (message: string, options?: ConfirmOptions) => Promise<boolean>,
promptFn: (message: string, defaultValue?: string, options?: PromptOptions) => Promise<string | null>,
timeSigFn: (message: string, defaultValue?: TimeSigResult) => Promise<TimeSigResult | null>,
) {
_showAlertFn = alertFn;
_showConfirmFn = confirmFn;
_showPromptFn = promptFn;
_showTimeSigFn = timeSigFn;
}
export function showAlert(message: string): Promise<void> {
if (!_showAlertFn) {
window.alert(message);
return Promise.resolve();
}
return _showAlertFn(message);
}
export function showConfirm(message: string, options?: ConfirmOptions): Promise<boolean> {
if (!_showConfirmFn) {
return Promise.resolve(window.confirm(message));
}
return _showConfirmFn(message, options);
}
export function showPrompt(message: string, defaultValue?: string, options?: PromptOptions): Promise<string | null> {
if (!_showPromptFn) {
return Promise.resolve(window.prompt(message, defaultValue));
}
return _showPromptFn(message, defaultValue, options);
}
export function showTimeSigPrompt(message: string, defaultValue?: TimeSigResult): Promise<TimeSigResult | null> {
if (!_showTimeSigFn) {
const raw = window.prompt(message, defaultValue ? `${defaultValue.numerator}/${defaultValue.denominator}` : '4/4');
if (!raw) return Promise.resolve(null);
const [n, d] = raw.split('/').map(Number);
if (!n || !d) return Promise.resolve(null);
return Promise.resolve({ numerator: n, denominator: d });
}
return _showTimeSigFn(message, defaultValue);
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { KGProjectStorage } from '../core/io/KGProjectStorage';
import { KGCore } from '../core/KGCore';
import { RESERVED_PROJECT_NAME } from './projectNameUtil';
import { showAlert } from '../components/common/DialogProvider';
import { showAlert } from './dialogUtil';
/**
* Save project utility function.
+2 -2
View File
@@ -214,8 +214,8 @@ describe('xmlUtil', () => {
it('should handle empty input', () => {
expect(wrapXmlBlocksInContent('')).toBe('');
expect(wrapXmlBlocksInContent(null as any)).toBeNull();
expect(wrapXmlBlocksInContent(undefined as any)).toBeUndefined();
expect(wrapXmlBlocksInContent(null as unknown as string)).toBeNull();
expect(wrapXmlBlocksInContent(undefined as unknown as string)).toBeUndefined();
});
it('should wrap XML blocks from multipleXmlBlocks fixture', () => {