From 07450df1a1f9d5f2d2b10a52e8f35961bfe2558e Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Thu, 5 Oct 2023 21:16:02 +0200 Subject: [PATCH] Add no-console eslint rule (#1890) * Add no-console eslint rule * Remove unused test --- front/.eslintrc.js | 7 + .../modules/apollo/services/apollo.factory.ts | 5 +- front/src/modules/apollo/utils/index.ts | 23 ++- .../hooks/useUpdateCompanyBoardColumns.ts | 3 +- .../debug/components/RecoilDebugObserver.tsx | 5 +- .../pipeline/components/PipelineAddButton.tsx | 7 +- .../profile/components/NameFields.tsx | 3 +- .../workspace/components/NameField.tsx | 3 +- .../__stories__/MatchColumns.stories.tsx | 2 +- .../__stories__/SelectHeader.stories.tsx | 2 +- .../__stories__/SelectSheet.stories.tsx | 2 +- .../components/__stories__/Upload.stories.tsx | 2 +- .../__stories__/Validation.stories.tsx | 2 +- .../spreadsheet-import/tests/mockRsiValues.ts | 171 ------------------ .../ui/board/components/BoardColumnMenu.tsx | 5 +- .../ui/board/components/EntityBoard.tsx | 3 +- .../components/RelationFieldDisplay.tsx | 3 +- .../components/ChipDisplay.tsx | 3 +- .../debug/components/TimingProfiler.tsx | 4 +- .../hotkey/hooks/useScopedHotkeyCallback.ts | 6 +- front/src/utils/cast-as-integer-or-null.ts | 14 +- front/src/utils/logDebug.ts | 4 + front/src/utils/logError.ts | 1 + front/src/utils/measureTotalFrameLoad.ts | 1 + 24 files changed, 69 insertions(+), 212 deletions(-) delete mode 100644 front/src/modules/spreadsheet-import/tests/mockRsiValues.ts create mode 100644 front/src/utils/logDebug.ts diff --git a/front/.eslintrc.js b/front/.eslintrc.js index eaccabd46..d1ea86f85 100644 --- a/front/.eslintrc.js +++ b/front/.eslintrc.js @@ -24,6 +24,12 @@ module.exports = { jest: true, }, overrides: [ + { + files: ['*.stories.tsx', '*.test.ts'], + rules: { + 'no-console': 'off', + } + }, { files: ['*.js', '*.jsx', '*.ts', '*.tsx'], rules: { @@ -96,5 +102,6 @@ module.exports = { }, ], "@typescript-eslint/consistent-type-imports": ["error", { "prefer": "no-type-imports" }], + 'no-console': ['error', { allow: ['group', 'groupCollapsed', 'groupEnd'] }], } }; diff --git a/front/src/modules/apollo/services/apollo.factory.ts b/front/src/modules/apollo/services/apollo.factory.ts index 7b5128842..6eb2f5a92 100644 --- a/front/src/modules/apollo/services/apollo.factory.ts +++ b/front/src/modules/apollo/services/apollo.factory.ts @@ -15,6 +15,7 @@ import { createUploadLink } from 'apollo-upload-client'; import { renewToken } from '@/auth/services/AuthService'; import { AuthTokenPair } from '~/generated/graphql'; import { assertNotNull } from '~/utils/assert'; +import { logDebug } from '~/utils/logDebug'; import { ApolloManager } from '../types/apolloManager.interface'; import { loggerLink } from '../utils'; @@ -105,7 +106,7 @@ export class ApolloFactory implements ApolloManager { } default: if (isDebugMode) { - console.warn( + logDebug( `[GraphQL error]: Message: ${ graphQLError.message }, Location: ${ @@ -121,7 +122,7 @@ export class ApolloFactory implements ApolloManager { if (networkError) { if (isDebugMode) { - console.warn(`[Network error]: ${networkError}`); + logDebug(`[Network error]: ${networkError}`); } onNetworkError?.(networkError); } diff --git a/front/src/modules/apollo/utils/index.ts b/front/src/modules/apollo/utils/index.ts index 8c91a2b80..0dc3317f7 100644 --- a/front/src/modules/apollo/utils/index.ts +++ b/front/src/modules/apollo/utils/index.ts @@ -1,5 +1,8 @@ import { ApolloLink, gql, Operation } from '@apollo/client'; +import { logDebug } from '~/utils/logDebug'; +import { logError } from '~/utils/logError'; + import formatTitle from './format-title'; const getGroup = (collapsed: boolean) => @@ -36,10 +39,10 @@ export const loggerLink = (getSchemaName: (operation: Operation) => string) => console.groupCollapsed(...titleArgs); if (variables && Object.keys(variables).length !== 0) { - console.log('VARIABLES', variables); + logDebug('VARIABLES', variables); } - console.log('QUERY', query); + logDebug('QUERY', query); console.groupEnd(); @@ -64,7 +67,7 @@ export const loggerLink = (getSchemaName: (operation: Operation) => string) => if (errors) { // eslint-disable-next-line @typescript-eslint/no-explicit-any errors.forEach((err: any) => { - console.log( + logDebug( `%c${err.message}`, // eslint-disable-next-line twenty/no-hardcoded-colors 'color: #F51818; font-weight: lighter', @@ -72,29 +75,29 @@ export const loggerLink = (getSchemaName: (operation: Operation) => string) => }); } - console.log('HEADERS: ', headers); + logDebug('HEADERS: ', headers); if (variables && Object.keys(variables).length !== 0) { - console.log('VARIABLES', variables); + logDebug('VARIABLES', variables); } - console.log('QUERY', query); + logDebug('QUERY', query); if (result.data) { - console.log('RESULT', result.data); + logDebug('RESULT', result.data); } if (errors) { - console.log('ERRORS', errors); + logDebug('ERRORS', errors); } console.groupEnd(); } catch { // this may happen if console group is not supported - console.log( + logDebug( `${operationType} ${schemaName}::${queryName} (in ${time} ms)`, ); if (errors) { - console.error(errors); + logError(errors); } } diff --git a/front/src/modules/companies/hooks/useUpdateCompanyBoardColumns.ts b/front/src/modules/companies/hooks/useUpdateCompanyBoardColumns.ts index 773cfbe36..5562813a2 100644 --- a/front/src/modules/companies/hooks/useUpdateCompanyBoardColumns.ts +++ b/front/src/modules/companies/hooks/useUpdateCompanyBoardColumns.ts @@ -9,6 +9,7 @@ import { entityFieldsFamilyState } from '@/ui/field/states/entityFieldsFamilySta import { isThemeColor } from '@/ui/theme/utils/castStringAsThemeColor'; import { Pipeline } from '~/generated/graphql'; import { isDeeplyEqual } from '~/utils/isDeeplyEqual'; +import { logError } from '~/utils/logError'; import { companyProgressesFamilyState } from '../states/companyProgressesFamilyState'; import { @@ -98,7 +99,7 @@ export const useUpdateCompanyBoard = () => const newBoardColumns: BoardColumnDefinition[] = orderedPipelineStages?.map((pipelineStage) => { if (!isThemeColor(pipelineStage.color)) { - console.warn( + logError( `Color ${pipelineStage.color} is not recognized in useUpdateCompanyBoard.`, ); } diff --git a/front/src/modules/debug/components/RecoilDebugObserver.tsx b/front/src/modules/debug/components/RecoilDebugObserver.tsx index e9d69f206..20bb725cf 100644 --- a/front/src/modules/debug/components/RecoilDebugObserver.tsx +++ b/front/src/modules/debug/components/RecoilDebugObserver.tsx @@ -2,6 +2,7 @@ import { useEffect } from 'react'; import { useRecoilSnapshot, useRecoilValue } from 'recoil'; import { isDebugModeState } from '@/client-config/states/isDebugModeState'; +import { logDebug } from '~/utils/logDebug'; const formatTitle = (stateName: string) => { const headerCss = [ @@ -33,9 +34,9 @@ export const RecoilDebugObserverEffect = () => { console.groupCollapsed(...titleArgs); - console.log('STATE', loadable.state); + logDebug('STATE', loadable.state); - console.log('CONTENTS', loadable.contents); + logDebug('CONTENTS', loadable.contents); console.groupEnd(); } diff --git a/front/src/modules/pipeline/components/PipelineAddButton.tsx b/front/src/modules/pipeline/components/PipelineAddButton.tsx index 88c19dd65..4014c997f 100644 --- a/front/src/modules/pipeline/components/PipelineAddButton.tsx +++ b/front/src/modules/pipeline/components/PipelineAddButton.tsx @@ -8,6 +8,7 @@ import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelec import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope'; import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar'; import { ViewBarDropdownButton } from '@/ui/view-bar/components/ViewBarDropdownButton'; +import { logError } from '~/utils/logError'; export const PipelineAddButton = () => { const { enqueueSnackBar } = useSnackBar(); @@ -30,9 +31,7 @@ export const PipelineAddButton = () => { }, ); - console.error( - 'There was a problem with the company selection, please retry.', - ); + logError('There was a problem with the company selection, please retry.'); return; } @@ -44,7 +43,7 @@ export const PipelineAddButton = () => { }, ); - console.error('There was a problem with the pipeline stage selection.'); + logError('There was a problem with the pipeline stage selection.'); return; } closeDropdown(); diff --git a/front/src/modules/settings/profile/components/NameFields.tsx b/front/src/modules/settings/profile/components/NameFields.tsx index 20b1cb517..28c5ce0ef 100644 --- a/front/src/modules/settings/profile/components/NameFields.tsx +++ b/front/src/modules/settings/profile/components/NameFields.tsx @@ -8,6 +8,7 @@ import { currentUserState } from '@/auth/states/currentUserState'; import { TextInputSettings } from '@/ui/input/text/components/TextInputSettings'; import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser'; import { useUpdateUserMutation } from '~/generated/graphql'; +import { logError } from '~/utils/logError'; const StyledComboInputContainer = styled.div` display: flex; @@ -63,7 +64,7 @@ export const NameFields = ({ } } } catch (error) { - console.error(error); + logError(error); } }, 500); diff --git a/front/src/modules/settings/workspace/components/NameField.tsx b/front/src/modules/settings/workspace/components/NameField.tsx index 57b444113..14cba84a3 100644 --- a/front/src/modules/settings/workspace/components/NameField.tsx +++ b/front/src/modules/settings/workspace/components/NameField.tsx @@ -8,6 +8,7 @@ import { currentUserState } from '@/auth/states/currentUserState'; import { TextInputSettings } from '@/ui/input/text/components/TextInputSettings'; import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser'; import { useUpdateWorkspaceMutation } from '~/generated/graphql'; +import { logError } from '~/utils/logError'; const StyledComboInputContainer = styled.div` display: flex; @@ -55,7 +56,7 @@ export const NameField = ({ autoSave = true, onNameUpdate }: OwnProps) => { throw errors; } } catch (error) { - console.error(error); + logError(error); } }, 500), [updateWorkspace], diff --git a/front/src/modules/spreadsheet-import/steps/components/__stories__/MatchColumns.stories.tsx b/front/src/modules/spreadsheet-import/steps/components/__stories__/MatchColumns.stories.tsx index a0ee07056..7b484dd17 100644 --- a/front/src/modules/spreadsheet-import/steps/components/__stories__/MatchColumns.stories.tsx +++ b/front/src/modules/spreadsheet-import/steps/components/__stories__/MatchColumns.stories.tsx @@ -3,7 +3,7 @@ import { Meta } from '@storybook/react'; import { ModalWrapper } from '@/spreadsheet-import/components/ModalWrapper'; import { Providers } from '@/spreadsheet-import/components/Providers'; import { MatchColumnsStep } from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep'; -import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues'; +import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues.test'; const meta: Meta = { title: 'Modules/SpreadsheetImport/MatchColumnsStep', diff --git a/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectHeader.stories.tsx b/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectHeader.stories.tsx index 8a28599df..a3c859467 100644 --- a/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectHeader.stories.tsx +++ b/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectHeader.stories.tsx @@ -6,7 +6,7 @@ import { SelectHeaderStep } from '@/spreadsheet-import/steps/components/SelectHe import { headerSelectionTableFields, mockRsiValues, -} from '@/spreadsheet-import/tests/mockRsiValues'; +} from '@/spreadsheet-import/tests/mockRsiValues.test'; const meta: Meta = { title: 'Modules/SpreadsheetImport/SelectHeaderStep', diff --git a/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectSheet.stories.tsx b/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectSheet.stories.tsx index 4ec059c66..6bfc34910 100644 --- a/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectSheet.stories.tsx +++ b/front/src/modules/spreadsheet-import/steps/components/__stories__/SelectSheet.stories.tsx @@ -3,7 +3,7 @@ import { Meta } from '@storybook/react'; import { ModalWrapper } from '@/spreadsheet-import/components/ModalWrapper'; import { Providers } from '@/spreadsheet-import/components/Providers'; import { SelectSheetStep } from '@/spreadsheet-import/steps/components/SelectSheetStep/SelectSheetStep'; -import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues'; +import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues.test'; const meta: Meta = { title: 'Modules/SpreadsheetImport/SelectSheetStep', diff --git a/front/src/modules/spreadsheet-import/steps/components/__stories__/Upload.stories.tsx b/front/src/modules/spreadsheet-import/steps/components/__stories__/Upload.stories.tsx index 8ff0b5808..11d3ee1f9 100644 --- a/front/src/modules/spreadsheet-import/steps/components/__stories__/Upload.stories.tsx +++ b/front/src/modules/spreadsheet-import/steps/components/__stories__/Upload.stories.tsx @@ -3,7 +3,7 @@ import { Meta } from '@storybook/react'; import { ModalWrapper } from '@/spreadsheet-import/components/ModalWrapper'; import { Providers } from '@/spreadsheet-import/components/Providers'; import { UploadStep } from '@/spreadsheet-import/steps/components/UploadStep/UploadStep'; -import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues'; +import { mockRsiValues } from '@/spreadsheet-import/tests/mockRsiValues.test'; const meta: Meta = { title: 'Modules/SpreadsheetImport/UploadStep', diff --git a/front/src/modules/spreadsheet-import/steps/components/__stories__/Validation.stories.tsx b/front/src/modules/spreadsheet-import/steps/components/__stories__/Validation.stories.tsx index 32fc9547b..6aacc76c5 100644 --- a/front/src/modules/spreadsheet-import/steps/components/__stories__/Validation.stories.tsx +++ b/front/src/modules/spreadsheet-import/steps/components/__stories__/Validation.stories.tsx @@ -6,7 +6,7 @@ import { ValidationStep } from '@/spreadsheet-import/steps/components/Validation import { editableTableInitialData, mockRsiValues, -} from '@/spreadsheet-import/tests/mockRsiValues'; +} from '@/spreadsheet-import/tests/mockRsiValues.test'; const meta: Meta = { title: 'Modules/SpreadsheetImport/ValidationStep', diff --git a/front/src/modules/spreadsheet-import/tests/mockRsiValues.ts b/front/src/modules/spreadsheet-import/tests/mockRsiValues.ts deleted file mode 100644 index 7a5466e8d..000000000 --- a/front/src/modules/spreadsheet-import/tests/mockRsiValues.ts +++ /dev/null @@ -1,171 +0,0 @@ -import { defaultSpreadsheetImportProps } from '@/spreadsheet-import/provider/components/SpreadsheetImport'; -import { Fields, SpreadsheetOptions } from '@/spreadsheet-import/types'; - -const fields = [ - { - icon: null, - label: 'Name', - key: 'name', - alternateMatches: ['first name', 'first'], - fieldType: { - type: 'input', - }, - example: 'Stephanie', - validations: [ - { - rule: 'required', - errorMessage: 'Name is required', - }, - ], - }, - { - icon: null, - label: 'Surname', - key: 'surname', - alternateMatches: ['second name', 'last name', 'last'], - fieldType: { - type: 'input', - }, - example: 'McDonald', - validations: [ - { - rule: 'unique', - errorMessage: 'Last name must be unique', - level: 'info', - }, - ], - description: 'Family / Last name', - }, - { - icon: null, - label: 'Age', - key: 'age', - alternateMatches: ['years'], - fieldType: { - type: 'input', - }, - example: '23', - validations: [ - { - rule: 'regex', - value: '^\\d+$', - errorMessage: 'Age must be a number', - level: 'warning', - }, - ], - }, - { - icon: null, - label: 'Team', - key: 'team', - alternateMatches: ['department'], - fieldType: { - type: 'select', - options: [ - { label: 'Team One', value: 'one' }, - { label: 'Team Two', value: 'two' }, - ], - }, - example: 'Team one', - validations: [ - { - rule: 'required', - errorMessage: 'Team is required', - }, - ], - }, - { - icon: null, - label: 'Is manager', - key: 'is_manager', - alternateMatches: ['manages'], - fieldType: { - type: 'checkbox', - booleanMatches: {}, - }, - example: 'true', - }, -] as Fields; - -const mockComponentBehaviourForTypes = ( - props: SpreadsheetOptions, -) => props; - -export const mockRsiValues = mockComponentBehaviourForTypes({ - ...defaultSpreadsheetImportProps, - fields: fields, - onSubmit: async (data) => { - console.log(data.all.map((value) => value)); - }, - isOpen: true, - onClose: () => { - console.log('onClose'); - }, - uploadStepHook: async (data) => { - await new Promise((resolve) => { - setTimeout(() => resolve(data), 4000); - }); - return data; - }, - selectHeaderStepHook: async (hData, data) => { - await new Promise((resolve) => { - setTimeout( - () => - resolve({ - headerValues: hData, - data, - }), - 4000, - ); - }); - return { - headerValues: hData, - data, - }; - }, - // Runs after column matching and on entry change, more performant - matchColumnsStepHook: async (data) => { - await new Promise((resolve) => { - setTimeout(() => resolve(data), 4000); - }); - return data; - }, -}); - -export const editableTableInitialData = [ - { - name: 'Hello', - surname: 'Hello', - age: '123123', - team: 'one', - is_manager: true, - }, - { - name: 'Hello', - surname: 'Hello', - age: '12312zsas3', - team: 'two', - is_manager: true, - }, - { - name: 'Whooaasdasdawdawdawdiouasdiuasdisdhasd', - surname: 'Hello', - age: '123123', - team: undefined, - is_manager: false, - }, - { - name: 'Goodbye', - surname: 'Goodbye', - age: '111', - team: 'two', - is_manager: true, - }, -]; - -export const headerSelectionTableFields = [ - ['text', 'num', 'select', 'bool'], - ['Hello', '123', 'one', 'true'], - ['Hello', '123', 'one', 'true'], - ['Hello', '123', 'one', 'true'], -]; diff --git a/front/src/modules/ui/board/components/BoardColumnMenu.tsx b/front/src/modules/ui/board/components/BoardColumnMenu.tsx index 76c805e00..524a00a1c 100644 --- a/front/src/modules/ui/board/components/BoardColumnMenu.tsx +++ b/front/src/modules/ui/board/components/BoardColumnMenu.tsx @@ -17,6 +17,7 @@ import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousH import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys'; import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside'; import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState'; +import { logError } from '~/utils/logError'; import { BoardColumnContext } from '../contexts/BoardColumnContext'; import { useBoardColumns } from '../hooks/useBoardColumns'; @@ -65,9 +66,7 @@ export const BoardColumnMenu = ({ }, ); - console.error( - 'There was a problem with the company selection, please retry.', - ); + logError('There was a problem with the company selection, please retry.'); return; } diff --git a/front/src/modules/ui/board/components/EntityBoard.tsx b/front/src/modules/ui/board/components/EntityBoard.tsx index 83f8d7b34..60eef28d2 100644 --- a/front/src/modules/ui/board/components/EntityBoard.tsx +++ b/front/src/modules/ui/board/components/EntityBoard.tsx @@ -19,6 +19,7 @@ import { PipelineStage, useUpdateOnePipelineProgressStageMutation, } from '~/generated/graphql'; +import { logError } from '~/utils/logError'; import { useCurrentCardSelected } from '../hooks/useCurrentCardSelected'; import { useSetCardSelected } from '../hooks/useSetCardSelected'; @@ -126,7 +127,7 @@ export const EntityBoard = ({ ); } } catch (e) { - console.error(e); + logError(e); } }, [boardColumns, updatePipelineProgressStageInDB, updateBoardCardIds], diff --git a/front/src/modules/ui/field/meta-types/display/components/RelationFieldDisplay.tsx b/front/src/modules/ui/field/meta-types/display/components/RelationFieldDisplay.tsx index 62e8690d2..5e075c9cc 100644 --- a/front/src/modules/ui/field/meta-types/display/components/RelationFieldDisplay.tsx +++ b/front/src/modules/ui/field/meta-types/display/components/RelationFieldDisplay.tsx @@ -3,6 +3,7 @@ import { PersonChip } from '@/people/components/PersonChip'; import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect'; import { UserChip } from '@/users/components/UserChip'; import { getLogoUrlFromDomainName } from '~/utils'; +import { logError } from '~/utils/logError'; import { useRelationField } from '../../hooks/useRelationField'; @@ -42,7 +43,7 @@ export const RelationFieldDisplay = () => { ); } default: - console.warn( + logError( `Unknown relation type: "${fieldDefinition.metadata.relationType}" in RelationFieldDisplay`, ); diff --git a/front/src/modules/ui/field/meta-types/display/content-display/components/ChipDisplay.tsx b/front/src/modules/ui/field/meta-types/display/content-display/components/ChipDisplay.tsx index bd8798c8f..edde4e470 100644 --- a/front/src/modules/ui/field/meta-types/display/content-display/components/ChipDisplay.tsx +++ b/front/src/modules/ui/field/meta-types/display/content-display/components/ChipDisplay.tsx @@ -2,6 +2,7 @@ import { CompanyChip } from '@/companies/components/CompanyChip'; import { PersonChip } from '@/people/components/PersonChip'; import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect'; import { getLogoUrlFromDomainName } from '~/utils'; +import { logError } from '~/utils/logError'; type OwnProps = { entityType: Entity; @@ -36,7 +37,7 @@ export const ChipDisplay = ({ ); } default: - console.warn( + logError( `Unknown relation type: "${entityType}" in DoubleTextChipDisplay`, ); return <> ; diff --git a/front/src/modules/ui/utilities/debug/components/TimingProfiler.tsx b/front/src/modules/ui/utilities/debug/components/TimingProfiler.tsx index 6a56d33b5..133588f6c 100644 --- a/front/src/modules/ui/utilities/debug/components/TimingProfiler.tsx +++ b/front/src/modules/ui/utilities/debug/components/TimingProfiler.tsx @@ -1,6 +1,8 @@ import { Profiler } from 'react'; import { Interaction } from 'scheduler/tracing'; +import { logDebug } from '~/utils/logDebug'; + type OwnProps = { id: string; children: React.ReactNode; @@ -16,7 +18,7 @@ export const TimingProfiler = ({ id, children }: OwnProps) => { commitTime: number, interactions: Set, ) => { - console.debug( + logDebug( 'TimingProfiler', JSON.stringify( { diff --git a/front/src/modules/ui/utilities/hotkey/hooks/useScopedHotkeyCallback.ts b/front/src/modules/ui/utilities/hotkey/hooks/useScopedHotkeyCallback.ts index 1bee34ec8..7ec2ad718 100644 --- a/front/src/modules/ui/utilities/hotkey/hooks/useScopedHotkeyCallback.ts +++ b/front/src/modules/ui/utilities/hotkey/hooks/useScopedHotkeyCallback.ts @@ -1,6 +1,8 @@ import { Hotkey } from 'react-hotkeys-hook/dist/types'; import { useRecoilCallback } from 'recoil'; +import { logDebug } from '~/utils/logDebug'; + import { internalHotkeysEnabledScopesState } from '../states/internal/internalHotkeysEnabledScopesState'; const DEBUG_HOTKEY_SCOPE = true; @@ -27,7 +29,7 @@ export const useScopedHotkeyCallback = () => if (!currentHotkeyScopes.includes(scope)) { if (DEBUG_HOTKEY_SCOPE) { - console.debug( + logDebug( `%cI can't call hotkey (${ hotkeysEvent.keys }) because I'm in scope [${scope}] and the active scopes are : [${currentHotkeyScopes.join( @@ -41,7 +43,7 @@ export const useScopedHotkeyCallback = () => } if (DEBUG_HOTKEY_SCOPE) { - console.debug( + logDebug( `%cI can call hotkey (${ hotkeysEvent.keys }) because I'm in scope [${scope}] and the active scopes are : [${currentHotkeyScopes.join( diff --git a/front/src/utils/cast-as-integer-or-null.ts b/front/src/utils/cast-as-integer-or-null.ts index aa181ef70..d5ed76d22 100644 --- a/front/src/utils/cast-as-integer-or-null.ts +++ b/front/src/utils/cast-as-integer-or-null.ts @@ -1,28 +1,30 @@ +import { logError } from './logError'; + const DEBUG_MODE = false; export const canBeCastAsIntegerOrNull = ( probableNumberOrNull: string | undefined | number | null, ): probableNumberOrNull is number | null => { if (probableNumberOrNull === undefined) { - if (DEBUG_MODE) console.log('probableNumberOrNull === undefined'); + if (DEBUG_MODE) logError('probableNumberOrNull === undefined'); return false; } if (typeof probableNumberOrNull === 'number') { - if (DEBUG_MODE) console.log('typeof probableNumberOrNull === "number"'); + if (DEBUG_MODE) logError('typeof probableNumberOrNull === "number"'); return Number.isInteger(probableNumberOrNull); } if (probableNumberOrNull === null) { - if (DEBUG_MODE) console.log('probableNumberOrNull === null'); + if (DEBUG_MODE) logError('probableNumberOrNull === null'); return true; } if (probableNumberOrNull === '') { - if (DEBUG_MODE) console.log('probableNumberOrNull === ""'); + if (DEBUG_MODE) logError('probableNumberOrNull === ""'); return true; } @@ -31,12 +33,12 @@ export const canBeCastAsIntegerOrNull = ( const stringAsNumber = +probableNumberOrNull; if (isNaN(stringAsNumber)) { - if (DEBUG_MODE) console.log('isNaN(stringAsNumber)'); + if (DEBUG_MODE) logError('isNaN(stringAsNumber)'); return false; } if (Number.isInteger(stringAsNumber)) { - if (DEBUG_MODE) console.log('Number.isInteger(stringAsNumber)'); + if (DEBUG_MODE) logError('Number.isInteger(stringAsNumber)'); return true; } diff --git a/front/src/utils/logDebug.ts b/front/src/utils/logDebug.ts new file mode 100644 index 000000000..049dad71f --- /dev/null +++ b/front/src/utils/logDebug.ts @@ -0,0 +1,4 @@ +/* eslint-disable no-console */ +export const logDebug = (message: any, ...optionalParams: any[]) => { + console.debug(message, optionalParams); +}; diff --git a/front/src/utils/logError.ts b/front/src/utils/logError.ts index a3e270564..957156fe3 100644 --- a/front/src/utils/logError.ts +++ b/front/src/utils/logError.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ export const logError = (message: any) => { console.error(message); }; diff --git a/front/src/utils/measureTotalFrameLoad.ts b/front/src/utils/measureTotalFrameLoad.ts index 8f7f8987d..ee98812d5 100644 --- a/front/src/utils/measureTotalFrameLoad.ts +++ b/front/src/utils/measureTotalFrameLoad.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import afterFrame from 'afterframe'; export const measureTotalFrameLoad = (id: string) => {