Skip to content

Commit

Permalink
build: migrate to eslint@9 and apply fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rocka committed Oct 20, 2024
1 parent 5f93e57 commit 63a2444
Show file tree
Hide file tree
Showing 19 changed files with 149 additions and 88 deletions.
40 changes: 0 additions & 40 deletions .eslintrc.js

This file was deleted.

86 changes: 86 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import js from '@eslint/js';
import vue from 'eslint-plugin-vue';
import stylisticJs from '@stylistic/eslint-plugin-js';

import globals from 'globals';
import babelParser from '@babel/eslint-parser';

/** @type {import('eslint').Linter.Config[]} */
export default [
{
ignores: [
'build/',
'dist/',
'script/'
]
},
js.configs.recommended,
{
// js options
plugins: {
'@stylistic/js': stylisticJs
},
rules: {
'no-console': 'error',
'@stylistic/js/semi': ['error', 'always'],
'@stylistic/js/quotes': ['error', 'single', { 'avoidEscape': true }],
'@stylistic/js/indent': ['warn', 4, { 'SwitchCase': 1 }],
'@stylistic/js/eol-last': ['error', 'always']
}
},
{
files: [
'src/main/**/*.js'
],
languageOptions: {
globals: globals.node,
parser: babelParser,
parserOptions: {
requireConfigFile: false,
babelOptions: {
babelrc: false,
plugins: [
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }]
]
}
}
},
},
{
files: [
'src/renderer/**/*.js'
],
languageOptions: {
globals: {
'process': 'readonly',
...globals.browser
}
}
},
...vue.configs['flat/vue2-essential'],
{
// vue sfc options
files: ['src/renderer/**/*.vue'],
languageOptions: {
parser: vue.parser,
parserOptions: {
sourceType: 'module'
}
},
rules: {
'vue/multi-word-component-names': 'off', // TODO turn on this
'vue/html-indent': ['warn', 4, {
'alignAttributesVertically': false
}],
'vue/html-self-closing': ['warn', {
'html': {
'void': 'never',
'normal': 'never',
'component': 'any' // TODO turn on this
},
'svg': 'never',
'math': 'never'
}],
}
}
];
4 changes: 2 additions & 2 deletions src/main/api/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Cache {
const externalData = fs.readFileSync(this.mapPath, 'utf8');
const data = JSON.parse(externalData);
this.external = new Map(data);
} catch (e) {
} catch {
this.external = new Map();
}

Expand Down Expand Up @@ -130,7 +130,7 @@ class Cache {
try {
await fsp.access(this.fullPath(fileName));
return true;
} catch (e) {
} catch {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/api/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const d = debug('Downloader');
*/
function escapeSlash(text) {
if (process.platform === 'win32') {
return text.replace(/[<>:"\/\\\|\?\*]/g, ' ');
return text.replace(/[<>:"/\\|?*]/g, ' ');
}
return text.replace(/\//g, ' ');
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1444,15 +1444,15 @@ export function getUserEvents(id, time = -1, limit = 20, getcounts = true) {
* @returns {Promise<Types.UserTopEventsRes>}
*/
export function getUserTopEvents(userId) {
return client.postE(`/event/top/get`, { userId });
return client.postE('/event/top/get', { userId });
}

/**
* 用户的大学信息
* @param {number} userId
*/
export function getUserCollege(userId) {
return client.postE(`/college/usercollege/get`, { userId });
return client.postE('/college/usercollege/get', { userId });
}

/**
Expand All @@ -1468,13 +1468,13 @@ export function getLikedSongIds() {
* @returns {Promise<Types.PrivateCloudListRes>}
*/
export function getPrivateCloudList(limit = 500, offset = 0) {
return client.postE(`/v1/cloud/get`, { limit, offset });
return client.postE('/v1/cloud/get', { limit, offset });
}

/**
* 删除云盘歌曲
* @param {number[]} songIds
*/
export function removePrivateCloudItem(songIds) {
return client.postE(`/cloud/del`, { songIds });
return client.postE('/cloud/del', { songIds });
}
5 changes: 2 additions & 3 deletions src/main/api/media/flac.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import {
getMIMEType,
getJPEGSize,
Expand All @@ -9,8 +8,8 @@ import {
uint24toBuffer,
uint32toBuffer,
uint32toBufferR
} from "./utils";
import { getVersionName } from "..";
} from './utils';
import { getVersionName } from '../index';

/**
* @typedef FLACMetadataBlock
Expand Down
6 changes: 3 additions & 3 deletions src/main/api/musicServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MusicServer {
range[1] = parseInt(ranges[1]);
range[1] = range[1] < 16 ? 16 : range[1];
}
} catch (e) {
} catch {
// ignore it
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ class MusicServer {
// check unexpected request method or url
if (req.method !== 'GET' || location.pathname !== '/music') {
d('What a Terrible Failure');
res.writeHead(418, `I'm a teapot`);
res.writeHead(418, "I'm a teapot");
res.end('@see https://tools.ietf.org/html/rfc2324');
return;
}
Expand All @@ -126,7 +126,7 @@ class MusicServer {
d('ignoreCache set, delete cache for music id=%d', id);
try {
await this.cache.rm(fileName);
} catch (e) { /* nothing happened */ }
} catch { /* nothing happened */ }
} else {
const filePath = this.cache.fullPath(fileName);
d('Hit cache for music id=%d', id);
Expand Down
12 changes: 8 additions & 4 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ app.on('activate', () => {

ipcMain.on('Settings', async (event, /** @type {string} */ type, ...args) => {
switch (type) {
case 'recreateWindow':
case 'recreateWindow': {
// prevent App quit
shouldAppQuit = false;
// ensure window can be closed
Expand All @@ -159,7 +159,8 @@ ipcMain.on('Settings', async (event, /** @type {string} */ type, ...args) => {
}
shouldAppQuit = settings.exitOnWindowClose;
break;
case 'showTrayIcon':
}
case 'showTrayIcon': {
if (args[0] === true) {
const settings = await Settings.get();
appTray = new AppTray(settings.trayIconVariety);
Expand All @@ -171,12 +172,14 @@ ipcMain.on('Settings', async (event, /** @type {string} */ type, ...args) => {
}
}
break;
case 'trayIconVariety':
}
case 'trayIconVariety': {
if (appTray) {
appTray.setColor(args[0]);
}
break;
case 'exitOnWindowClose':
}
case 'exitOnWindowClose': {
if (IsDarwin) return;
shouldAppQuit = args[0];
if (args[0] === true) {
Expand All @@ -185,6 +188,7 @@ ipcMain.on('Settings', async (event, /** @type {string} */ type, ...args) => {
mainWindow.on('close', preventQuitHandler);
}
break;
}
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/main/mpris/mpris.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,4 @@ class MPRISEmitter extends EventEmitter {
}
}

export default new MPRISEmitter();
export default new MPRISEmitter();
4 changes: 2 additions & 2 deletions src/main/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function readFile() {
export async function set(target) {
try {
await fsp.access(configDir);
} catch (e) {
} catch {
fsp.mkdir(configDir);
}
return writeFile(target);
Expand All @@ -65,7 +65,7 @@ export async function get() {
await fsp.access(configPath);
const json = JSON.parse(await readFile());
settings = trimSettings(json);
} catch (e) {
} catch {
set(defaultSettings);
}
return settings;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/AppNav/AppNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import { mapActions } from 'vuex';
import Routes from '@/routes';
import SearchBox from './SearchBox.vue';
import LoginDialog from './LoginDialog.vue';
import { bkgImg, sizeImg, HiDpiPx } from "@/util/image";
import { bkgImg, sizeImg, HiDpiPx } from '@/util/image';
import { isDarwin, browserWindow } from '@/util/globals';
import { UPDATE_SETTINGS, SET_USER_SIGN_STATUS } from '@/store/mutation-types';
Expand Down
10 changes: 3 additions & 7 deletions src/renderer/components/VideoDetail/VideoDetail.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<component ref="detailCompo"
:is="compoName"
:is="compo"
v-bind="bindProp"></component>
</template>

Expand All @@ -18,8 +18,8 @@ export default {
}
},
computed: {
compoName() {
return this.video.type === 0 ? 'MV' : 'Video';
compo() {
return this.video.type === 0 ? MV : Video;
},
bindProp() {
return this.video.type === 0 ? { mv: this.video } : { video: this.video };
Expand Down Expand Up @@ -80,10 +80,6 @@ export default {
this._vid.removeEventListener('auxclick', this.toggleMute);
this._vid.removeEventListener('wheel', this.onMouseWheel);
this._vid = null;
},
components: {
MV,
Video
}
};
</script>
Expand Down
12 changes: 7 additions & 5 deletions src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import './transition.css';
import 'vue-resize/dist/vue-resize.css';
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css';

import * as tray from '@/util/tray';
import * as mpris from '@/util/mpris';

Vue.use(Router);
Vue.use(MuseUI);
Vue.use(Toast);
Expand Down Expand Up @@ -50,9 +53,9 @@ try {
primary: settings.themePrimaryColor,
secondary: settings.themeSecondaryColor
}, themeVariety);
} catch (e) { sessionStorage.removeItem('settings'); }
} catch { sessionStorage.removeItem('settings'); }

require('@/util/tray').injectStore(store);
tray.injectStore(store);

function restoreUserInfoOnline() {
store.dispatch('restoreUserInfo').catch(e => {
Expand Down Expand Up @@ -116,9 +119,8 @@ darkMediaQuery.addEventListener('change', e => {

if (isLinux) {
app.$once('audio-ready', audio => {
const m = require('@/util/mpris');
m.injectStore(store);
m.bindAudioElement(audio);
mpris.injectStore(store);
mpris.bindAudioElement(audio);
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/renderer/page/Settings/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default {
switch (key) {
case 'themePrimaryColor':
case 'themeSecondaryColor':
case 'themeVariety':
case 'themeVariety': {
const variety = state.settings.themeVariety === 'auto'
? (this.darkMediaQuery.matches ? 'dark' : 'light')
: state.settings.themeVariety;
Expand All @@ -182,6 +182,7 @@ export default {
secondary: state.settings.themeSecondaryColor
}, variety);
break;
}
case 'windowBorder':
this.$nextTick(() => this.recreateWindow());
break;
Expand Down
Loading

0 comments on commit 63a2444

Please sign in to comment.