From 13ff2940a38b92146e5300eafcd6c848eb51a4fd Mon Sep 17 00:00:00 2001 From: Facundo Inza Date: Mon, 2 Oct 2023 10:41:18 -0400 Subject: [PATCH] feat: Eslint without console.logs for production --- .eslintrc.json | 11 ++++++----- app/error.tsx | 7 ------- components/commons/buttons/ButtonStartDay.tsx | 1 - .../commons/buttons/CancelInteractiveButtons.tsx | 11 +++-------- .../commons/buttons/StartInteractiveButtons.tsx | 11 +++-------- components/commons/switch/Switch.tsx | 1 - components/ui/locationMap/LocationMap.tsx | 9 ++------- components/ui/locationMap/SimpleLocationMap.tsx | 4 +--- components/ui/statusBadge/StatusBadge.tsx | 1 - 9 files changed, 15 insertions(+), 41 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 04b0214..640ba29 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -16,7 +16,7 @@ "eslint:recommended", "plugin:react/recommended", "plugin:react-hooks/recommended", - "plugin:prettier/recommended" // Agrega esta línea para utilizar las reglas de Prettier + "plugin:prettier/recommended" ], "parserOptions": { "ecmaFeatures": { @@ -26,7 +26,7 @@ "sourceType": "module", "requireConfigFile": false }, - "plugins": ["react", "cypress", "prettier"], // Agrega "prettier" a la lista de plugins + "plugins": ["react", "cypress", "prettier"], "rules": { "indent": ["warn", "tab"], "linebreak-style": ["warn", "unix"], @@ -36,7 +36,7 @@ "react/display-name": "off", "react-hooks/exhaustive-deps": "off", "react-hooks/rules-of-hooks": "error", - "prettier/prettier": "warn" // Asegúrate de activar la verificación de Prettier en ESLint + "prettier/prettier": "warn" }, "overrides": [ { @@ -46,7 +46,7 @@ "extends": [ "eslint:recommended", "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended" // Agrega esta línea para utilizar las reglas de Prettier en TypeScript + "plugin:prettier/recommended" ], "rules": { "indent": ["warn", 4], @@ -56,7 +56,8 @@ "@typescript-eslint/no-explicit-any": "off", "jsdoc/require-param-type": "off", "jsdoc/require-returns-type": "off", - "prettier/prettier": "warn" // Asegúrate de activar la verificación de Prettier en ESLint para TypeScript + "prettier/prettier": "warn", + "no-console": "error" // Agrega la regla para prohibir console.log en archivos JS } } ] diff --git a/app/error.tsx b/app/error.tsx index 189959a..0d7c7c8 100644 --- a/app/error.tsx +++ b/app/error.tsx @@ -1,6 +1,5 @@ 'use client'; // Error components must be Client Components -import { useEffect } from 'react'; import React from 'react'; import Link from 'next/link'; import logo from '../assets/deliverit-full.png'; @@ -8,17 +7,11 @@ import Image from 'next/image'; import { Navbar } from '../components/ui/navbar'; export default function Error({ - error, reset, }: { error: Error & { digest?: string }; reset: () => void; }) { - useEffect(() => { - // Log the error to an error reporting service - console.error(error); - }, [error]); - return ( <>
diff --git a/components/commons/buttons/ButtonStartDay.tsx b/components/commons/buttons/ButtonStartDay.tsx index 012a8ac..966bea2 100644 --- a/components/commons/buttons/ButtonStartDay.tsx +++ b/components/commons/buttons/ButtonStartDay.tsx @@ -40,7 +40,6 @@ const ButtonStartDay: FC = ({ enabled, isBlocked, blockUntil }) => { setShowModal(false); router.push('/dealer/home'); } catch (error: any) { - console.log(error); const { message } = error.response.data.error.data; setIsSuccess(false); setButtonText('Ok'); diff --git a/components/commons/buttons/CancelInteractiveButtons.tsx b/components/commons/buttons/CancelInteractiveButtons.tsx index 6f5c131..8522857 100644 --- a/components/commons/buttons/CancelInteractiveButtons.tsx +++ b/components/commons/buttons/CancelInteractiveButtons.tsx @@ -27,17 +27,15 @@ const CancelInteractiveButtons: FC<{ delivery: IDeliveryResponse }> = ({ const id = delivery.data._id; const postponeDelivery = async () => { - console.log('postpone delivery called'); try { - const result = await api.put(`/api/delivery/${id}`, { + await api.put(`/api/delivery/${id}`, { status: 'pending', }); - console.log('Postpone Result', result); + setModalMessage('Delivery postponed!'); setIsModalSuccess(true); setShowModal(true); } catch (error) { - console.log('Postpone Delivery error', error); const axiosError = error as AxiosError; const errorMessage = axiosError?.response?.data?.error?.data?.message ?? @@ -49,17 +47,14 @@ const CancelInteractiveButtons: FC<{ delivery: IDeliveryResponse }> = ({ } }; const cancelDelivery = async () => { - console.log('cancel delivery called'); try { - const result = await api.put(`/api/delivery/${id}`, { + await api.put(`/api/delivery/${id}`, { status: 'cancelled', }); - console.log('Cancel Result', result); setModalMessage('Delivery cancelled!'); setIsModalSuccess(true); setShowModal(true); } catch (error) { - console.log('Cancel Delivery error', error); setModalMessage((error as Error).message); setIsModalSuccess(false); setShowModal(true); diff --git a/components/commons/buttons/StartInteractiveButtons.tsx b/components/commons/buttons/StartInteractiveButtons.tsx index 74efd5a..c33d1ca 100644 --- a/components/commons/buttons/StartInteractiveButtons.tsx +++ b/components/commons/buttons/StartInteractiveButtons.tsx @@ -27,17 +27,15 @@ const StartInteractiveButtons: FC<{ delivery: IDeliveryResponse }> = ({ const id = delivery.data._id; const startDelivery = async () => { - console.log('start delivery called'); try { - const result = await api.put(`/api/delivery/${id}`, { + await api.put(`/api/delivery/${id}`, { status: 'on-course', }); - console.log('Start Result', result); + setModalMessage('Delivery started!'); setIsModalSuccess(true); setShowModal(true); } catch (error) { - console.log('Start Delivery error', error); const axiosError = error as AxiosError; const errorMessage = axiosError?.response?.data?.error?.data?.message ?? @@ -49,17 +47,14 @@ const StartInteractiveButtons: FC<{ delivery: IDeliveryResponse }> = ({ } }; const completeDelivery = async () => { - console.log('complete delivery called'); try { - const result = await api.put(`/api/delivery/${id}`, { + await api.put(`/api/delivery/${id}`, { status: 'delivered', }); - console.log('Complete Result', result); setModalMessage('Delivery completed!'); setIsModalSuccess(true); setShowModal(true); } catch (error) { - console.log('Complete Delivery error', error); setModalMessage((error as Error).message); setIsModalSuccess(false); setShowModal(true); diff --git a/components/commons/switch/Switch.tsx b/components/commons/switch/Switch.tsx index 7806105..64d7201 100644 --- a/components/commons/switch/Switch.tsx +++ b/components/commons/switch/Switch.tsx @@ -6,7 +6,6 @@ export const Switch: FC = () => { const [isActive, setIsActive] = useState(false); const toggle = () => { - console.log('Activated!'); setIsActive(!isActive); }; diff --git a/components/ui/locationMap/LocationMap.tsx b/components/ui/locationMap/LocationMap.tsx index 76cb25a..af7c3d2 100644 --- a/components/ui/locationMap/LocationMap.tsx +++ b/components/ui/locationMap/LocationMap.tsx @@ -33,8 +33,9 @@ const LocationMap: FC = ({ id: 'google-map-script', googleMapsApiKey: apikey, }); - + //eslint-disable-next-line const [map, setMap] = useState(null); + const [directions, setDirections] = useState(null); @@ -49,8 +50,6 @@ const LocationMap: FC = ({ setMap(null); }, []); - console.log('Map created', map); - useEffect(() => { if (isLoaded && navigator.geolocation) { navigator.geolocation.getCurrentPosition((position) => { @@ -69,10 +68,6 @@ const LocationMap: FC = ({ (result, status) => { if (status === google.maps.DirectionsStatus.OK) { setDirections(result); - } else { - console.error( - `error fetching directions ${result}` - ); } } ); diff --git a/components/ui/locationMap/SimpleLocationMap.tsx b/components/ui/locationMap/SimpleLocationMap.tsx index 474973c..7ae1b1c 100644 --- a/components/ui/locationMap/SimpleLocationMap.tsx +++ b/components/ui/locationMap/SimpleLocationMap.tsx @@ -33,7 +33,7 @@ const SimpleLocationMap: FC = ({ id: 'google-map-script', googleMapsApiKey: apikey, }); - + //eslint-disable-next-line const [map, setMap] = useState(null); const [showInfoWindow, setShowInfoWindow] = useState(true); @@ -48,8 +48,6 @@ const SimpleLocationMap: FC = ({ setMap(null); }, []); - console.log('Map created', map); - return isLoaded ? ( = ({ status }) => { const color = colorMap[status]; if (!color) { - console.error(`Status desconocido: ${status}`); return null; } return (