Explorar el Código

Resolve sonar code smells

Nicolas Meienberger hace 3 años
padre
commit
0d62ebe1bf

+ 1 - 1
packages/dashboard/src/components/Layout/Layout.tsx

@@ -4,7 +4,7 @@ import Link from 'next/link';
 import React from 'react';
 import { FiChevronRight } from 'react-icons/fi';
 import Header from './Header';
-import Menu from './Menu';
+import Menu from './SideMenu';
 import MenuDrawer from './MenuDrawer';
 
 interface IProps {

+ 0 - 0
packages/dashboard/src/components/Layout/Menu.tsx → packages/dashboard/src/components/Layout/SideMenu.tsx


+ 0 - 22
packages/dashboard/src/constants/apps.ts

@@ -1,22 +0,0 @@
-// import validator from 'validator';
-
-// interface IFormField {
-//   name: string;
-//   type: string;
-//   required: boolean;
-//   description?: string;
-//   placeholder?: string;
-//   validate?: (value: string) => boolean;
-// }
-
-// interface IAppConfig {
-//   id: string;
-//   name: string;
-//   description: string;
-//   logo: string;
-//   url: string;
-//   color: string;
-//   install_form: { fields: IFormField[] };
-// }
-
-export {};

+ 1 - 1
packages/dashboard/src/modules/AppStore/helpers/table.helpers.ts

@@ -21,7 +21,7 @@ export const sortTable = (data: AppConfig[], col: keyof Pick<AppConfig, 'name'>,
 };
 
 export const limitText = (text: string, limit: number) => {
-  return text.length > limit ? `${text.substr(0, limit)}...` : text;
+  return text.length > limit ? `${text.substring(0, limit)}...` : text;
 };
 
 export const colorSchemeForCategory: Record<AppCategoriesEnum, string> = {

+ 1 - 1
packages/dashboard/src/pages/api/ip.tsx

@@ -1,4 +1,4 @@
-export default function handler(_: any, res: any) {
+export default function ip(_: any, res: any) {
   const { INTERNAL_IP } = process.env;
 
   res.status(200).json({ ip: INTERNAL_IP });

+ 3 - 3
packages/dashboard/src/state/appsStore.ts

@@ -19,7 +19,7 @@ type AppsStore = {
 
 type Set = SetState<AppsStore>;
 
-const sortApps = (apps: AppConfig[]) => apps.sort((a, b) => a.name.localeCompare(b.name));
+const sortApps = (a: AppConfig, b: AppConfig) => a.name.localeCompare(b.name);
 
 const setAppStatus = (appId: string, status: AppStatusEnum, set: Set) => {
   set((state) => {
@@ -45,7 +45,7 @@ const fetchApp = async (appId: string, set: Set) => {
     const apps = state.apps.filter((app) => app.id !== appId);
     apps.push(response);
 
-    return { ...state, apps: sortApps(apps) };
+    return { ...state, apps: apps.sort(sortApps) };
   });
 };
 
@@ -61,7 +61,7 @@ export const useAppsStore = create<AppsStore>((set, get) => ({
       method: 'get',
     });
 
-    const apps = sortApps(response);
+    const apps = response.sort(sortApps);
 
     set({ apps, status: RequestStatus.SUCCESS });
   },

+ 0 - 1
packages/dashboard/src/state/authStore.ts

@@ -44,7 +44,6 @@ export const useAuthStore = create<AppsStore>((set) => ({
     }
   },
   logout: async () => {
-    // Cookies.remove('token2');
     Cookies.remove('tipi_token');
 
     set({ user: null, loading: false });

+ 1 - 1
packages/system-api/__mocks__/child_process.ts

@@ -1,6 +1,6 @@
 const childProcess: { execFile: typeof execFile } = jest.genMockFromModule('child_process');
 
-const execFile = (path: string, args: string[], thing: any, callback: Function) => {
+const execFile = (_path: string, _args: string[], _thing: any, callback: Function) => {
   callback();
 };
 

+ 0 - 0
packages/system-api/src/config/cache.ts → packages/system-api/src/config/TipiCache.ts


+ 1 - 1
packages/system-api/src/modules/apps/apps.controller.ts

@@ -68,7 +68,7 @@ const getAppInfo = async (req: Request, res: Response<AppConfig>, next: NextFunc
   }
 };
 
-const listApps = async (req: Request, res: Response, next: NextFunction) => {
+const listApps = async (_req: Request, res: Response, next: NextFunction) => {
   try {
     const apps = await AppsService.listApps();
 

+ 1 - 1
packages/system-api/src/modules/auth/auth.controller.ts

@@ -57,7 +57,7 @@ const me = async (req: Request, res: Response, next: NextFunction) => {
   }
 };
 
-const isConfigured = async (req: Request, res: Response, next: NextFunction) => {
+const isConfigured = async (_req: Request, res: Response, next: NextFunction) => {
   try {
     const users: IUser[] = readJsonFile('/state/users.json');
 

+ 1 - 3
packages/system-api/src/modules/auth/auth.helpers.ts

@@ -7,9 +7,7 @@ import config from '../../config';
 const getUser = (email: string): Maybe<IUser> => {
   const savedUser: IUser[] = readJsonFile('/state/users.json');
 
-  const user = savedUser.find((u) => u.email === email);
-
-  return user;
+  return savedUser.find((u) => u.email === email);
 };
 
 const compareHashPassword = (password: string, hash = ''): Promise<boolean> => {

+ 1 - 3
packages/system-api/src/modules/auth/auth.service.ts

@@ -10,9 +10,7 @@ const login = async (email: string, password: string) => {
     throw new Error('User not found');
   }
 
-  const token = await AuthHelpers.getJwtToken(user, password);
-
-  return token;
+  return AuthHelpers.getJwtToken(user, password);
 };
 
 const register = async (email: string, password: string, name: string) => {

+ 1 - 1
packages/system-api/src/modules/network/network.controller.ts

@@ -13,7 +13,7 @@ const isPortOpen = async (req: Request, res: Response<boolean>) => {
   res.status(200).send(isOpen);
 };
 
-const getInternalIp = async (req: Request, res: Response<string>) => {
+const getInternalIp = async (_req: Request, res: Response<string>) => {
   const ip = await internalIp.v4();
 
   res.status(200).send(ip);

+ 5 - 5
packages/system-api/src/modules/system/system.controller.ts

@@ -1,7 +1,7 @@
 import axios from 'axios';
 import { Request, Response } from 'express';
 import config from '../../config';
-import TipiCache from '../../config/cache';
+import TipiCache from '../../config/TipiCache';
 import { readJsonFile } from '../fs/fs.helpers';
 
 type CpuData = {
@@ -31,7 +31,7 @@ type SystemInfo = {
  * @param req
  * @param res
  */
-const getCpuInfo = async (req: Request, res: Response<CpuData>) => {
+const getCpuInfo = async (_req: Request, res: Response<CpuData>) => {
   const systemInfo: SystemInfo = readJsonFile('/state/system-info.json');
 
   const cpu = systemInfo.cpu;
@@ -44,7 +44,7 @@ const getCpuInfo = async (req: Request, res: Response<CpuData>) => {
  * @param req
  * @param res
  */
-const getDiskInfo = async (req: Request, res: Response<DiskData>) => {
+const getDiskInfo = async (_req: Request, res: Response<DiskData>) => {
   const systemInfo: SystemInfo = readJsonFile('/state/system-info.json');
 
   const result: DiskData = systemInfo.disk;
@@ -57,7 +57,7 @@ const getDiskInfo = async (req: Request, res: Response<DiskData>) => {
  * @param req
  * @param res
  */
-const getMemoryInfo = async (req: Request, res: Response<MemoryData>) => {
+const getMemoryInfo = async (_req: Request, res: Response<MemoryData>) => {
   const systemInfo: SystemInfo = readJsonFile('/state/system-info.json');
 
   const result: MemoryData = systemInfo.memory;
@@ -65,7 +65,7 @@ const getMemoryInfo = async (req: Request, res: Response<MemoryData>) => {
   res.status(200).json(result);
 };
 
-const getVersion = async (req: Request, res: Response<{ current: string; latest?: string }>) => {
+const getVersion = async (_req: Request, res: Response<{ current: string; latest?: string }>) => {
   let version = TipiCache.get<string>('latestVersion');
 
   if (!version) {

+ 3 - 4
packages/system-api/src/server.ts

@@ -1,7 +1,6 @@
 /* eslint-disable no-unused-vars */
 import express, { NextFunction, Request, Response } from 'express';
 import compression from 'compression';
-// import suExec from 'su-exec';
 import helmet from 'helmet';
 import cors from 'cors';
 import { isProd } from './constants/constants';
@@ -31,7 +30,7 @@ app.use(
       if (!origin) return callback(null, true);
 
       if (config.CLIENT_URLS.indexOf(origin) === -1) {
-        var message = "The CORS policy for this origin doesn't allow access from the particular origin.";
+        const message = "The CORS policy for this origin doesn't allow access from the particular origin.";
         return callback(new Error(message), false);
       }
 
@@ -41,7 +40,7 @@ app.use(
 );
 
 // Get user from token
-app.use((req, res, next) => {
+app.use((req, _res, next) => {
   let user = null;
 
   if (req?.cookies?.tipi_token) {
@@ -65,7 +64,7 @@ app.use('/system', restrict, systemRoutes);
 app.use('/apps', restrict, appsRoutes);
 
 // eslint-disable-next-line @typescript-eslint/no-unused-vars
-app.use((err: Error, req: Request, res: Response, _: NextFunction) => {
+app.use((err: Error, _req: Request, res: Response, _: NextFunction) => {
   res.status(200).json({ error: err.message });
 });