Skip to content

Commit

Permalink
Updated to eslint 9+. What a PITA. ESLint is really a mess...
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinfrei committed Apr 28, 2024
1 parent afeeb8b commit ea3bcdf
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 99 deletions.
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

2 changes: 1 addition & 1 deletion electron/Communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function setSaveMenu(enabled: boolean): Promise<void> {
await Promise.resolve();
}
}
// eslint-disable-next-line @typescript-eslint/no-empty-function

return;
}

Expand Down
16 changes: 9 additions & 7 deletions electron/Transcoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ const cp = {

const cwd = process.cwd();

const deQuote = (str: string): string => str.replace(/\"/g, '~!~');
const deQuote = (str: string): string => str.replace(/"/g, '~!~');

function reQuote(str: string): { [key: string]: string } {
let res: string = str.replace(/\\/g, '\\\\');
res = res.replace(/\"/g, '\\"');
res = res.replace(/"/g, '\\"');
res = res.replace(/~!~/g, '"');
return JSON.parse(res) as { [key: string]: string };
}

/// vvvv Hurray for a Typescript compiler bug
// eslint-disable-next-line no-shadow

enum XcodeResCode {
alreadyExists,
mediaInfoFailure,
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function toMp4Async(
hasFieldType(res.error, 'toString', isFunction)
) {
// MediaInfo failed: no continue, sorry
// eslint-disable-next-line @typescript-eslint/no-base-to-string

const resStr = asString(res.error.toString(), 'Unknown error');
return tr(
XcodeResCode.mediaInfoFailure,
Expand Down Expand Up @@ -124,7 +124,7 @@ export async function toMp4Async(
await Encode.FfmpegAsync(
originalFile,
newFile,
// eslint-disable-next-line @typescript-eslint/naming-convention

{ 'b:a': bitrate.toString(), movflags: '+faststart' },
metadata as unknown as Attributes,
)
Expand Down Expand Up @@ -511,20 +511,22 @@ export async function startTranscode(settings: TranscodeInfo): Promise<void> {
// TODO: Handle artwork for this stuff
const db = await GetAudioDB();
switch (settings.source.type) {
case TranscodeSourceType.Album:
case TranscodeSourceType.Album: {
const album = db.getAlbum(settings.source.loc);
if (album) {
workQueue.push(...album.songs);
}
// TODO: Report no such album
break;
case TranscodeSourceType.Artist:
}
case TranscodeSourceType.Artist: {
const artist = db.getArtist(settings.source.loc);
if (artist) {
workQueue.push(...artist.songs);
}
// TODO: Report no such album
break;
}
case TranscodeSourceType.Playlist:
workQueue.push(...(await LoadPlaylist(settings.source.loc)));
break;
Expand Down
4 changes: 2 additions & 2 deletions electron/cover-art.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
isSetOfString,
} from '@freik/typechk';
import albumArt from 'album-art';
// eslint-disable-next-line @typescript-eslint/naming-convention

import Jimp from 'jimp';
import { promises as fs } from 'node:fs';
import https from 'node:https';
Expand Down Expand Up @@ -298,7 +298,7 @@ export async function PictureHandler(req: Request): Promise<Response> {
: GetDefaultAlbumPicBuffer());
return new Response(
buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength),
// eslint-disable-next-line @typescript-eslint/naming-convention

{ headers: { 'Content-Type': 'image/svg+xml' } },
);
}
Expand Down
3 changes: 1 addition & 2 deletions electron/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type ClickHandler = (

const isMac = process.platform === 'darwin';

// eslint-disable-next-line
const ___: MenuItemConstructorOptions = { type: 'separator' };

function getClick<T>(handler?: ClickHandler | T): ClickHandler | undefined {
Expand Down Expand Up @@ -249,7 +248,7 @@ export function MakeMainMenu(): void {
});
Persistence.subscribe('CurrentView', (val: string) => {
let id: keyof typeof CurrentView;
// eslint-disable-next-line guard-for-in

for (id in CurrentView) {
const item = CurrentView[id];
const mnu = menu.getMenuItemById(id);
Expand Down
1 change: 0 additions & 1 deletion electron/playlists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export type PlaylistSaveData = {
songs: SongKey[];
};

// eslint-disable-next-line
export const isPlaylistSaveData: typecheck<PlaylistSaveData> =
chkObjectOfExactType<PlaylistSaveData>({
name: isString,
Expand Down
4 changes: 2 additions & 2 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ function useLoading(): {

// ----------------------------------------------------------------------

// eslint-disable-next-line react-hooks/rules-of-hooks
// es-lint-disable-next-line react-hooks/rules-of-hooks
const { appendLoading, removeLoading } = useLoading();
// eslint-disable-next-line no-console

domReady().then(appendLoading).catch(console.error);

window.onmessage = (ev: MessageEvent<{ payload?: string }>) => {
Expand Down
5 changes: 2 additions & 3 deletions electron/protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function GetDefaultAlbumPicUri(): Promise<string> {
svg = svg.replace(/\s{2,}/g, ' ');
svg = svg.trim();
// Encode the uri-unsafe characters
svg = svg.replace(/[%#<>?\[\\\]^`{|}]/g, encodeURIComponent);
svg = svg.replace(/[%#<>?[\\\]^`{|}]/g, encodeURIComponent);
defaultAlbumPicUri = `data:image/svg+xml,${svg}`;
}
return asString(defaultAlbumPicUri, '');
Expand Down Expand Up @@ -155,7 +155,6 @@ async function tuneNewProtocolHandler(req: Request): Promise<Response> {
const arr = buf.buffer;
return new Response(arr, {
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': mimeType + ', audio/flac',
// 'Access-Control-Allow-Origin': '*',
// 'Last-Modified': 'Thu, 01 Jan 1995 00:01:12 GMT',
Expand Down Expand Up @@ -205,7 +204,7 @@ export function RegisterProtocols(): void {
protocol.handle('tune', tuneNewProtocolHandler);
Comms.registerOldProtocolHandler(
'trune://song/',
// eslint-disable-next-line @typescript-eslint/unbound-method

protocol.registerFileProtocol,
tuneProtocolHandler,
);
Expand Down
25 changes: 25 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pluginJs from '@eslint/js';
import prettierConfig from 'eslint-config-prettier';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default [
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
// pluginReactConfig,
prettierConfig,
{
ignores: [
'/node_modules',
'src/**/*.d.ts',
'static/**/*.d.ts',
'electron/**/*.d.ts',
'shared/**/*',
'packages/**/*',
],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
},
];
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"testnode": "jest --config config/jest.node.js --watch",
"justtest": "jest --config config/jest.jsdom.js && jest --pass-with-no-tests --config config/jest.node.js",
"format": "ftool format",
"lint": "yarn eslint --fix --ext .ts --ext .tsx ./src ./electron ./renderer",
"lint": "yarn eslint --fix ./src ./electron ./renderer",
"linecount": "ftool linecount .css .ts .tsx .html -__ -.d.ts",
"postinstall": "husky install",
"typecheck": "tsc --noEmit",
Expand Down Expand Up @@ -70,6 +70,7 @@
]
},
"devDependencies": {
"@eslint/js": "^9.1.1",
"@freik/build-tools": "^3.6.10",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^15.0.5",
Expand All @@ -95,6 +96,7 @@
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.6",
"globals": "^15.1.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
Expand All @@ -108,6 +110,7 @@
"tree-kill": "^1.2.2",
"ts-jest": "29.1.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.7.1",
"vite": "^5.2.10",
"vite-plugin-electron": "^0.28.7",
"vite-plugin-electron-renderer": "^0.14.5"
Expand Down
1 change: 0 additions & 1 deletion src/FluentInit.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { registerIcons } from '@fluentui/react/lib/Styling';
// Note: This approach works with any SVG icon set, not just @fluentui/react-icons-mdl2
import {
Expand Down
1 change: 0 additions & 1 deletion src/Recoil/Likes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Effects } from '@freik/electron-render';
import { SongKey } from '@freik/media-core';
import { isArrayOfString } from '@freik/typechk';
Expand Down
1 change: 0 additions & 1 deletion src/Recoil/PlaylistsState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Ipc } from '@freik/electron-render';
import { PlaylistName, SongKey } from '@freik/media-core';
import { isArray, isArrayOfString, isSetOfString } from '@freik/typechk';
Expand Down
3 changes: 1 addition & 2 deletions src/Recoil/ReadOnly.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { FlatAudioDatabase } from '@freik/audiodb';
import { Effects, Ipc } from '@freik/electron-render';
import { IgnoreItem, IpcId, isIgnoreItemArrayFn } from '@freik/emp-shared';
Expand Down Expand Up @@ -33,7 +32,7 @@ import {
} from './ReadWrite';
import { songListState } from './SongPlaying';

const { wrn, log } = MakeLog('EMP:render:ReadOnly:log'); // eslint-disable-line
const { wrn, log } = MakeLog('EMP:render:ReadOnly:log');

// type GetRecoilValue = <T>(recoilVal: RecoilValue<T>) => T;

Expand Down
1 change: 0 additions & 1 deletion src/Recoil/ReadWrite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Effects } from '@freik/electron-render';
import { isAlbumKey, isArtistKey, isSongKey, SongKey } from '@freik/media-core';
import { atom, selector, selectorFamily } from 'recoil';
Expand Down
2 changes: 1 addition & 1 deletion src/Recoil/TranscodeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const xcodeErr = (curStatus: string) => ({ ...emptyXcodeInfo, curStatus });
export const transcodeStatusState = atom<TranscodeState>({
key: IpcId.TranscodingUpdate,
default: emptyXcodeInfo,
// eslint-disable-next-line @typescript-eslint/naming-convention

effects: [
Effects.oneWayFromMain(
// TODO: I don't think I need to initialize this thing...
Expand Down
1 change: 0 additions & 1 deletion src/Recoil/__tests__/testApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function flushPromisesAndTimers(): Promise<void> {
return act(
() =>
new Promise((resolve) => {
// eslint-disable-next-line no-restricted-globals
setTimeout(resolve, 100);
jest.runAllTimers();
}),
Expand Down
1 change: 0 additions & 1 deletion src/Recoil/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export function PlaySongs(
listToPlay: Iterable<SongKey>,
playlistName?: PlaylistName,
): void {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { reset, set, get } = xact;
const playList = GetFilteredSongs(xact, listToPlay);
if (isPlaylist(playlistName)) {
Expand Down
2 changes: 1 addition & 1 deletion src/UI/MenuHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function updateTime({ set, get }: MyTransactionInterface, offset: number) {
curTime.duration,
Math.max(0, curTime.position + offset),
);
// eslint-disable-next-line id-blacklist

if (position < Number.MAX_SAFE_INTEGER && position >= 0) {
set(mediaTimeState, { position, duration: curTime.duration });
set(mediaTimePercentFunc, position / curTime.duration);
Expand Down
5 changes: 2 additions & 3 deletions src/UI/SongPlaying.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ function ArtistAlbum(): JSX.Element {
}
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export const SongPlaying = forwardRef(
(_props, audioRef: ForwardedRef<HTMLAudioElement>): JSX.Element => {
const songKey = useRecoilValue(currentSongKeyFunc);
Expand Down Expand Up @@ -173,7 +172,7 @@ export const SongPlaying = forwardRef(
const ae = ev.currentTarget;
log('time update');
log(ev);
// eslint-disable-next-line id-blacklist

if (!Number.isNaN(ae.duration)) {
set(mediaTimeState, (prevTime: MediaTime) => {
if (
Expand Down Expand Up @@ -212,7 +211,7 @@ export const SongPlaying = forwardRef(
if (isMutableRefObject(audioRef)) {
const targetTime = audioRef.current.duration * playbackPercent;
const currentTime = audioRef.current.currentTime;
// eslint-disable-next-line id-blacklist

if (
targetTime < Number.MAX_SAFE_INTEGER &&
targetTime >= 0 &&
Expand Down
5 changes: 2 additions & 3 deletions src/UI/Utilities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import { isSearchBox } from './Sidebar';
const { wrn } = MakeLog('EMP:render:Utilities');

// Used by the key buffer to know when to reset the keys
// eslint-disable-next-line @typescript-eslint/no-empty-function

let lastHeard: () => void = () => {};

// In order to allow scrolling to work, we need to clear out the key buffer
// once it's been "consumed"
// eslint-disable-next-line @typescript-eslint/naming-convention

const ResetTheKeyBufferTimer = DebouncedDelay(() => lastHeard(), 750);

function TypingListener(): JSX.Element {
Expand Down Expand Up @@ -146,7 +146,6 @@ export const mySliderStyles: Partial<ISliderStyles> = {
},
};

// eslint-disable-next-line @typescript-eslint/naming-convention
export const HostOs: 'mac' | 'windows' | 'linux' = (() => {
const ua = window.navigator.userAgent;
if (ua.indexOf('Mac') >= 0) {
Expand Down
1 change: 0 additions & 1 deletion src/UI/Views/NuAlbums.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const classNames = mergeStyleSets({
float: 'left',
// background: palette.neutralLighter,
selectors: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'focus:after': {
content: '',
position: 'absolute',
Expand Down
22 changes: 10 additions & 12 deletions src/UI/Views/Selector.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { CurrentView } from '@freik/emp-shared';
import { CSSProperties, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { CurrentView } from '@freik/emp-shared';
import { curViewFunc } from '../../Recoil/ReadWrite';
import { GroupedAlbumList } from './Albums';
import { GroupedAristList } from './Artists';
import { MixedSongsList } from './MixedSongs';
import { NowPlayingView } from './NowPlaying';
import { NuAlbumView } from './NuAlbums';
import { PlaybackOrder } from './PlaybackOrder';
import { PlaylistView } from './Playlists';
import { RecentlyAddedView } from './RecentlyAdded';
import { SearchResultsView } from './SearchResults';
import { SettingsView } from './Settings';
import './styles/Selector.css';
import { ToolsView } from './Tools';
import './styles/Selector.css';

function ignore(view: CurrentView): boolean {
return view === CurrentView.settings || view === CurrentView.tools;
Expand Down Expand Up @@ -51,14 +49,14 @@ export function ViewSelector(): JSX.Element {
) {
contents.push([CurrentView.now_playing, <NowPlayingView />]);
}
if (false) {
// (rendered.has(CurrentView.albums) || which === CurrentView.recent)
contents.push([CurrentView.recent, <RecentlyAddedView />]);
}
if (false) {
// (rendered.has(CurrentView.albums) || which === CurrentView.recent)
contents.push([CurrentView.disabled, <NuAlbumView />]);
}
// if (false) {
// // (rendered.has(CurrentView.albums) || which === CurrentView.recent)
// contents.push([CurrentView.recent, <RecentlyAddedView />]);
// }
// if (false) {
// // (rendered.has(CurrentView.albums) || which === CurrentView.recent)
// contents.push([CurrentView.disabled, <NuAlbumView />]);
// }
if (which === CurrentView.settings) {
contents.push([CurrentView.settings, <SettingsView />]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/UI/Views/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
useBoolRecoilState,
useMyTransaction,
} from '@freik/web-utils';
// eslint-disable-next-line @typescript-eslint/naming-convention

import React, { useState } from 'react';
import { useRecoilState, useRecoilValue } from 'recoil';
import { AddIgnoreItem, RemoveIgnoreItem } from '../../ipc';
Expand Down
Loading

0 comments on commit ea3bcdf

Please sign in to comment.