refactor: sonarcloud code smells

This commit is contained in:
Fernando Fernández
2022-05-02 10:06:01 +02:00
committed by Thibault
parent e51f098e75
commit 44eccb5027
10 changed files with 25 additions and 36 deletions
+5 -4
View File
@@ -148,7 +148,10 @@ declare module 'vue/types/vue' {
}
}
const apiPlugin: Plugin = (context, inject) => {
export default function (
context: Context,
inject: (key: string, value: any) => void
) {
const config = new Configuration();
const contextAxios = context.$axios;
@@ -216,6 +219,4 @@ const apiPlugin: Plugin = (context, inject) => {
};
inject('api', api);
};
export default apiPlugin;
}
+2 -5
View File
@@ -1,9 +1,8 @@
import { Plugin } from '@nuxt/types';
import isNil from 'lodash/isNil';
import { authStore, ServerInfo } from '~/store';
import { parseServerListString } from '~/utils/servers';
const appInit: Plugin = () => {
export default function (): void {
const auth = authStore();
/**
@@ -36,6 +35,4 @@ const appInit: Plugin = () => {
for (const serverUrl of missingServers) {
auth.connectServer(serverUrl, true);
}
};
export default appInit;
}
+6 -5
View File
@@ -1,4 +1,4 @@
import { Context, Plugin } from '@nuxt/types/app';
import { Context } from '@nuxt/types/app';
import axios, { AxiosResponse, AxiosError, AxiosInstance } from 'axios';
import { BaseItemDto } from '@jellyfin/client-axios';
import { itemsStore, authStore, snackbarStore } from '~/store';
@@ -27,7 +27,10 @@ declare module 'vue/types/vue' {
* by components)
*/
const axiosPlugin: Plugin = (ctx: Context, inject): void => {
export default function (
ctx: Context,
inject: (key: string, value: any) => void
) {
const axiosInstance = axios.create();
/**
@@ -77,6 +80,4 @@ const axiosPlugin: Plugin = (ctx: Context, inject): void => {
axiosInstance.interceptors.response.use(onResponse, onResponseError);
inject('axios', axiosInstance);
};
export default axiosPlugin;
}
+1 -1
View File
@@ -2,7 +2,7 @@ import { Plugin, Context } from '@nuxt/types';
import persistence from './plugins/persistence';
import preferencesSync from './plugins/preferencesSync';
import watchAuth from './watchers/auth';
import watchPlaybackReporting from './watchers/playbackReporting';
import watchPlaybackReporting from './watchers/playbackManager';
import watchSocket from './watchers/socket';
const piniaPlugins: Plugin = (ctx: Context): void => {
+1 -2
View File
@@ -17,9 +17,8 @@ import { authLogic } from '~/middleware/auth';
*
* The logic to handle logouts and user switches during initialization lives inside Nuxt's auth plugin (~/plugins/nuxt/auth)
*
* @param ctx
*/
export default function watchAuth(ctx: Context): void {
export default function (ctx: Context): void {
const auth = authStore();
const clientSettings = clientSettingsStore();
const homeSection = homeSectionStore();
@@ -7,14 +7,12 @@ import { msToTicks } from '~/mixins/timeUtils';
* Playback reporting logic
*
* Reports the state of the playback to the server
*
* @param ctx
*/
export default function watchPlaybackReporting(ctx: Context): void {
export default function (ctx: Context): void {
const playbackManager = playbackManagerStore();
playbackManager.$onAction(({ name, after }) => {
// @ts-expect-error - For some reason, types are not recognised properly here
// @ts-expect-error - Typings are not recognised properly here for some reason
after(async () => {
switch (name) {
case 'setNextTrack':
+1 -2
View File
@@ -5,9 +5,8 @@ import { authStore, itemsStore, socketStore } from '~/store';
/**
* Handle socket messages that are relevant to items inside the items store.
*
* @param ctx
*/
export default function watchSocket(ctx: Context): void {
export default function (ctx: Context): void {
const auth = authStore();
const socket = socketStore();
const items = itemsStore();
+3 -5
View File
@@ -40,7 +40,7 @@ export const authStore = defineStore('auth', {
* @param serverUrl
* @param isDefault
*/
async connectServer(serverUrl: string, isDefault?: boolean) {
async connectServer(serverUrl: string, isDefault = false) {
serverUrl = serverUrl.replace(/\/$/, '');
const snackbar = snackbarStore();
@@ -54,7 +54,7 @@ export const authStore = defineStore('auth', {
data = (await this.$nuxt.$api.system.getPublicSystemInfo())
.data as ServerInfo;
data.PublicAddress = serverUrl;
data.isDefault = !!isDefault;
data.isDefault = isDefault;
} catch (err) {
snackbar.push(this.$nuxt.i18n.t('login.serverNotFound'), 'error');
throw new Error(err as string);
@@ -172,9 +172,7 @@ export const authStore = defineStore('auth', {
* @param serverUrl
*/
async deleteServer(serverUrl: string): Promise<void> {
const server = this.servers.find(
(server) => server.PublicAddress === serverUrl
);
const server = this.servers.find((s) => s.PublicAddress === serverUrl);
if (!server) {
throw new Error("This server doesn't exist in the store");
+3 -3
View File
@@ -139,11 +139,11 @@ export const itemsStore = defineStore('items', {
return (ids: string[]): BaseItemDto[] => {
const res = [] as BaseItemDto[];
for (const id of ids) {
const item = state.byId[id];
for (const i of ids) {
const item = state.byId[i];
if (!item) {
throw new Error(`Item ${id} doesn't exist in the store`);
throw new Error(`Item ${i} doesn't exist in the store`);
}
res.push(item);
+1 -5
View File
@@ -47,7 +47,7 @@ export const socketStore = defineStore('socket', {
* @param url
* @param reconnect
*/
connect(url: string, reconnect?: boolean): void {
connect(url: string, reconnect = true): void {
const isDifferentWebsocket = this.instance && url !== this.instance.url;
if (!this.instance || isDifferentWebsocket) {
@@ -55,10 +55,6 @@ export const socketStore = defineStore('socket', {
this.closeSocket();
}
if (reconnect === undefined) {
reconnect = true;
}
console.info(`[WebSocket] Connecting to ${url}...`);
this.isConnecting = true;