Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lovegaoshi committed May 31, 2024
1 parent d7571e0 commit 9f8bbd6
Show file tree
Hide file tree
Showing 26 changed files with 73 additions and 62 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ module.exports = {
'react/jsx-one-expression-per-line': 'off',
'react/react-in-jsx-scope': 'off',
'react/no-unescaped-entities': 'off',
// no.
radix: 'off',
// && and ||? maybe. math operators? no. learn math.
'no-mixed-operators': 'off',
// i dont do this, but one line arrow functions interpreted I'm returning even though i dont use return.
'no-return-assign': 'off',
'no-param-reassign': 'off',
Expand All @@ -93,8 +89,6 @@ module.exports = {
'no-bitwise': 'off',
// for the convenience to work with stupid async chrome API calls.
'no-await-in-loop': 'off',
// actually a feature not oversight. no.
'no-fallthrough': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
// no. its readable.
'no-nested-ternary': 'off',
Expand Down
24 changes: 23 additions & 1 deletion .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
- name: yarn build
run: |
yarn ci:format
yarn build
zip -r NoxPlayer.zip build
Expand All @@ -42,3 +41,26 @@ jobs:
zipFilePath: 'NoxPlayer.zip'
crxFilePath: 'NoxPlayer.crx'
privateKey: ${{ secrets.PEM_KEY }}

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Setup Yarn
uses: threeal/setup-yarn-action@v2.0.0

- name: Install dependencies
run: yarn; git submodule update --init --recursive

- name: yarn ci
run: |
yarn ci:format
yarn ci:lint
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface Props {
usePlaylist: UsePlaylist;
}

export default function ({ usePlaylist }: Props) {
export default function PlaylistSelectBtn({ usePlaylist }: Props) {
const onClick = () => {
if (usePlaylist.checking) {
usePlaylist.resetSelected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Props {
playlist: NoxMedia.Playlist;
}

export default function ({ sortPlaylist, playlist }: Props) {
export default function PlaylistSortButton({ sortPlaylist, playlist }: Props) {
const [showDialog, setShowDialog] = React.useState(false);
const [ascending, setAscending] = React.useState(false);
const sortOptions = Object.values(SortOptions);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Playlist/SongMenu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable react/jsx-no-bind */
/* eslint-disable */
import React from 'react';
import { Menu, Item, Separator, useContextMenu } from 'react-contexify';
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
Expand Down
5 changes: 3 additions & 2 deletions src/components/Playlist/hooks/usePlaylistPaginated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ export default (playlist: NoxMedia.Playlist): UsePlaylistP => {
resetToFirstPage = false,
songList = getCurrentRow(),
) => {
for (let i = 0, n = songList.length; i < n; i++) {
if (songList[i]!.id === currentPlayingId) {
// eslint-disable-next-line no-restricted-syntax
for (const [i, v] of songList.entries()) {
if (v.id === currentPlayingId) {
return setPage(Math.floor(i / defaultRowsPerPage));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Playlists/Playlists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Search from './PlaylistsHeader/Search';
import PlaylistHeaderButtons from './PlaylistsHeader/PlaylistHeaderButtons';
import PlaylistList from './PlaylistsList/PlaylistList';

export default function () {
export default function Playlists() {
const playlistCRUD = usePlaylistCRUD();
const { colorTheme } = useApp((state) => state.playerStyle);
const AddFavIcon = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface Props {
sx: SxProps;
color?: string;
}
export default function ({ sx, color }: Props) {
export default function PlaylistHeaderButtons({ sx, color }: Props) {
return (
<Grid container spacing={2}>
<Grid item xs={4}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Playlists/PlaylistsList/PlaylistList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function PlaylistList({ playlistCRUD }: Props) {
const favoritePlaylist = useNoxSetting((state) => state.favoritePlaylist);

// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _ = useNoxSetting((state) => state.playlistShouldReRender);
const {
playlists,
Expand Down Expand Up @@ -97,7 +98,7 @@ export default function PlaylistList({ playlistCRUD }: Props) {
)}
<DragDropContext onDragEnd={onDragEnd}>
<Droppable droppableId='droppable'>
{(provided, _snapshot) => (
{(provided) => (
<div {...provided.droppableProps} ref={provided.innerRef}>
{playlistIds.map((item, index) => (
<Draggable
Expand Down
2 changes: 1 addition & 1 deletion src/components/lyric/LyricSearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function LyricSearchBar({ currentAudio, usedLyric }: Props) {
initTrackLrcLoad();
}, [currentAudio]);

const onOptionSet = (_: any, newValue?: NoxNetwork.NoxFetchedLyric) => {
const onOptionSet = (_: any, newValue?: NoxLyric.NoxFetchedLyric) => {
if (newValue === undefined) return;
searchAndSetCurrentLyric(0, [newValue]);
};
Expand Down
1 change: 1 addition & 0 deletions src/components/menus/DummyMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import React from 'react';
import { Menu, Item, useContextMenu } from 'react-contexify';
import TerminalIcon from '@mui/icons-material/Terminal';
Expand Down
2 changes: 1 addition & 1 deletion src/components/menus/PlaylistMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable react/jsx-no-bind */
/* eslint-disable */
import React from 'react';
import { Menu, Item, useContextMenu } from 'react-contexify';
import YoutubeSearchedForIcon from '@mui/icons-material/YoutubeSearchedFor';
Expand Down
5 changes: 3 additions & 2 deletions src/components/setting/sync/DropboxAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ let dbx = new _Dropbox({
* @param {function} errorHandling
*/
const getAuth = async (
callback = (_v?: string) => checkAuthentication(dbx).then(console.debug),
callback: (v: string) => Promise<void> = () =>
checkAuthentication(dbx).then(console.debug),
errorHandling = console.error,
) =>
chrome.identity.launchWebAuthFlow(
Expand All @@ -62,7 +63,7 @@ const getAuth = async (
);

const loginDropbox = async (
callback = async (_v?: string) => {},
callback: () => Promise<void> = async () => {},
errorCallback = console.error,
) => {
try {
Expand Down
6 changes: 3 additions & 3 deletions src/components/setting/sync/GenericSyncButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function ImportSyncFavButton({
sx,
}: ImportPropsR) {
// @ts-ignore
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
const { enqueueSnackbar } = useSnackbar();
const [loading, setLoading] = useState(false);

const errorHandling = (
Expand Down Expand Up @@ -82,7 +82,7 @@ function ImportSyncFavButton({

function ExportSyncFavButton({ noxBackup, login, sx }: ExportPropsR) {
// @ts-ignore
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
const { enqueueSnackbar } = useSnackbar();
const [loading, setLoading] = useState(false);

const errorHandling = (e: Error) => {
Expand Down Expand Up @@ -127,7 +127,7 @@ function ExportSyncFavButton({ noxBackup, login, sx }: ExportPropsR) {
);
}

export default function ({
export default function GenericSyncBtn({
restoreFromUint8Array,
login,
noxBackup,
Expand Down
2 changes: 1 addition & 1 deletion src/components/setting/sync/GiteeAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const clientSecret = process.env.GITEE_SECRET;
const redirectURI = chrome.identity.getRedirectURL();

export const getAuth = async (
callback = (_v?: string) =>
callback: (v: string) => Promise<void> = () =>
checkAuthentication(authToken).then(console.debug),
errorHandling = logger.error,
) =>
Expand Down
2 changes: 1 addition & 1 deletion src/components/setting/sync/GithubAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const clientSecret = process.env.GITHUB_SECRET;
const redirectURI = chrome.identity.getRedirectURL();

export const getAuth = async (
callback = (_v?: string) =>
callback: (v: string) => Promise<void> = () =>
checkAuthentication(authToken).then(console.debug),
errorHandling = logger.error,
) =>
Expand Down
16 changes: 6 additions & 10 deletions src/components/setting/sync/LocalSyncButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ export function ExportFavButton({ AddFavIcon }: SyncFavButtonProps) {
// alls sync buttons are loaded/unloaded depending on the current sync setting;
// thus they all must have exactly the same states for react to mount and unmount to another set.
// even though they are not used.
// @ts-ignore
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
// @ts-ignore
const dummy = enqueueSnackbar;
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { enqueueSnackbar } = useSnackbar();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [loading, setLoading] = useState(false);
return (
<Tooltip title='导入歌单'>
Expand All @@ -36,11 +34,9 @@ export function ExportFavButton({ AddFavIcon }: SyncFavButtonProps) {
}

export function ImportFavButton({ AddFavIcon }: SyncFavButtonProps) {
// @ts-ignore
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
// @ts-ignore
const dummy = enqueueSnackbar;
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { enqueueSnackbar } = useSnackbar();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [loading, setLoading] = useState(false);
return (
<Tooltip title='导出歌单'>
Expand Down
4 changes: 2 additions & 2 deletions src/components/setting/sync/PersonalSyncButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function ImportSyncFavButton({
}: SyncFavButtonProps) {
const { initializeFromSync } = useInitializeStore();
// @ts-ignore
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
const { enqueueSnackbar } = useSnackbar();
const [loading, setLoading] = useState(false);

const errorHandling = (
Expand Down Expand Up @@ -70,7 +70,7 @@ export function ExportSyncFavButton({
cloudAddress = '',
}: SyncFavButtonProps) {
// @ts-ignore
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
const { enqueueSnackbar } = useSnackbar();
const [loading, setLoading] = useState(false);

const errorHandling = (e: Object) => {
Expand Down
33 changes: 13 additions & 20 deletions src/hooks/useLyric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ export default (currSong: NoxMedia.Song) => {
};

const loadLocalLrc = async (
lyricPromise: Promise<NoxNetwork.NoxFetchedLyric[]>,
lyricPromise: Promise<NoxLyric.NoxFetchedLyric[]>,
) => {
const localLrcColle = getLrcFromLocal(currSong);
return usedLyric.loadLocalLrc(getLrcFromLocal(currSong), async () =>
searchAndSetCurrentLyric(
undefined,
await lyricPromise,
(await localLrcColle)?.lrcDetail,
),
searchAndSetCurrentLyric({
resolvedLrcOptions: await lyricPromise,
resolvedLyric: (await localLrcColle)?.lrcDetail,
}),
);
};

Expand All @@ -43,13 +42,7 @@ export default (currSong: NoxMedia.Song) => {
song,
lrc,
currentTimeOffset,
}: {
resolvedLrc?: NoxNetwork.NoxFetchedLyric;
newLrcDetail?: Partial<NoxMedia.LyricDetail>;
lrc: string;
song: NoxMedia.Song;
currentTimeOffset: number;
}) => {
}: NoxLyric.UpdateLyricMapping) => {
if (resolvedLrc) {
const lyricDeatail: NoxMedia.LyricDetail = {
songId: song.id,
Expand All @@ -65,19 +58,19 @@ export default (currSong: NoxMedia.Song) => {
}
};

const searchAndSetCurrentLyric = (
const searchAndSetCurrentLyric = ({
index = 0,
resolvedLrcOptions = usedLyric.lrcOptions,
resolvedLyric?: NoxMedia.LyricDetail,
mSong = currSong,
) =>
usedLyric.searchAndSetCurrentLyric(
resolvedLyric,
song = currSong,
}: NoxLyric.SearchLyricL) =>
usedLyric.searchAndSetCurrentLyric({
updateLyricMapping,
index,
resolvedLrcOptions,
resolvedLyric,
mSong,
);
song,
});

const initTrackLrcLoad = () =>
usedLyric.initTrackLrcLoad(
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/usePlayback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export default () => {
const musicSrcParser = async (v: NoxMedia.Song) => {
try {
const resolvedUrl = await fetchPlayUrlPromise({ song: v });
if (false) {
return currentAudioInst?.playNext?.();
}
// return currentAudioInst?.playNext?.();
parseR128Gain(v, async () => resolvedUrl);
return resolvedUrl.url;
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions src/popup/wdyr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react';

if (process.env.DEV === 'dev') {
// eslint-disable-next-line import/no-extraneous-dependencies, global-require
const whyDidYouRender = require('@welldone-software/why-did-you-render');
whyDidYouRender(React, {
trackAllPureComponents: true,
Expand Down
1 change: 1 addition & 0 deletions src/utils/mediafetch/ytbvideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const resolveURL = async (song: NoxMedia.Song) => {
let maxAudioQualityStream = { bitrate: 0, url: '' };
const formats =
extractedVideoInfo.adaptive_formats ?? extractedVideoInfo.formats ?? [];
// eslint-disable-next-line no-restricted-syntax
for (const videoStream of formats) {
if (
videoStream.has_audio &&
Expand Down
2 changes: 1 addition & 1 deletion src/utils/rgba2rgb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export default function rgba2rgb(rgbaVal: string) {
// rgba(30,30,30,0.5) -> #303030
const extracted = /rgba\((\d+),(\d+),(\d+),.+\)/.exec(rgbaVal)!;
const toHex = (val: string) => parseInt(val).toString(16);
const toHex = (val: string) => parseInt(val, 10).toString(16);
try {
return `#${toHex(extracted[1]!).padStart(2, '0')}${toHex(
extracted[2]!,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/types/NoxMedia.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace NoxMediaChrome {
// this is a special audio intance that is passed from react-music-player
// TODO: fill in the types
Expand Down
2 changes: 2 additions & 0 deletions src/utils/versionupdater/versionupdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ export default async () => {
const currVer = getVersion();
const updatedString = `Noxplayer is updated from ${oldVer} to ${currVer}! \nRead what's new in settings.\n电闹播放器更新了!去帮助里更新说明看更新了什么鬼玩意儿。`;
let updated = false;
// eslint-disable-next-line no-restricted-syntax
for (const update of updates) {
if (needUpdate(oldVerParsed, update[0])) {
await update[1]();
updated = true;
}
}
// eslint-disable-next-line no-alert
if (updated) alert(updatedString);
saveItem('nox-version', currVer);
};

0 comments on commit 9f8bbd6

Please sign in to comment.