Skip to content

Commit

Permalink
clean(eslint): Clean global esLint comment to have them more inline
Browse files Browse the repository at this point in the history
Closes #1859
  • Loading branch information
Johann Levesque authored and Johann Levesque committed Feb 27, 2024
1 parent f239a1f commit 30c9026
Show file tree
Hide file tree
Showing 66 changed files with 139 additions and 172 deletions.
1 change: 1 addition & 0 deletions packages/geoview-core/public/templates/codedoc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// Many functions name needs the eslint escape no-unused-vars. It is the reason why we keep it global...
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
Expand Down
2 changes: 2 additions & 0 deletions packages/geoview-core/public/templates/layers/layerlib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-unused-vars */
// cgpv is not define, it is part of window object, we escape the no-undef globally...
// Many functions name needs the eslint escape no-unused-vars. It is the reason why we keep it global...
// ==========================================================================================================================
function listenToLegendLayerSetChanges(elementId, handlerName) {
const mapId = handlerName.split('/')[0];
Expand Down
3 changes: 1 addition & 2 deletions packages/geoview-core/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ export class API {
// Init by function call
initMapDivFromFunctionCall(mapDiv, mapConfig);
} else {
// eslint-disable-next-line no-console
console.error(`Div with id ${divId} does not exist`);
logger.logError(`Div with id ${divId} does not exist`);
}
};
}
2 changes: 1 addition & 1 deletion packages/geoview-core/src/api/events/event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-underscore-dangle */
import EventEmitter from 'eventemitter3';

import { EventStringId } from './event-types';
Expand Down Expand Up @@ -86,6 +85,7 @@ export class Event {
* @param {string} eventTypeToKeep the handler name prefix composed of handlerNamePrefix/eventTypeToKeep to keep
*/
offAll = (handlerNamePrefix: string, eventTypeToKeep?: string): void => {
// eslint-disable-next-line no-underscore-dangle
(Object.keys(this.eventEmitter._events) as EventStringId[]).forEach((eventNameId) => {
if (eventNameId.startsWith(handlerNamePrefix)) {
if (eventTypeToKeep) {
Expand Down
3 changes: 1 addition & 2 deletions packages/geoview-core/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ export async function initMapDivFromFunctionCall(mapDiv: HTMLElement, mapConfig:
// Render the map
await renderMap(mapDiv);
} else {
// eslint-disable-next-line no-console
console.warn(`Div with id ${mapDiv.id} has a class 'geoview-map' and should be initialized via a cgpv.init() call.`);
logger.logWarning(`Div with id ${mapDiv.id} has a class 'geoview-map' and should be initialized via a cgpv.init() call.`);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-underscore-dangle */
import { useState } from 'react';

import { useTheme } from '@mui/material/styles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function useFooterPanelHeight({ footerPanelTab }: UseFooterPanelHeightTyp

if (leftPanelRef.current && isMapFullScreen && (activeFooterBarTabId === footerPanelTab || footerPanelTab === 'default')) {
const panelTitleHeight = panelTitleRef.current?.clientHeight ?? 0;
const tabsContainer = document.getElementById('tabsContainer')!;
const tabsContainer = document.getElementById(`mapId-tabsContainer`)!;
const firstChild = tabsContainer?.firstElementChild?.firstElementChild;
const firstChildHeight = firstChild?.clientHeight ?? 0;
const leftPanelHeight = (window.screen.height * footerPanelResizeValue) / 100 - panelTitleHeight - firstChildHeight;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { useCallback, useEffect, useMemo, useRef, useState, memo, ReactNode, isValidElement } from 'react';

import { useTranslation } from 'react-i18next';
Expand All @@ -15,7 +14,6 @@ import { MRT_Localization_EN as MRTLocalizationEN } from 'material-react-table/l

import { Extent } from 'ol/extent'; // only for typing

import { darken } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import { HtmlToReact } from '@/core/containers/html-to-react';

Expand All @@ -42,7 +40,7 @@ import {
import ExportButton from './export-button';
import JSONExportButton from './json-export-button';
import FilterMap from './filter-map';
import { AbstractGeoViewVector, TypeLayerEntryConfig, api, TypeFieldEntry, TypeFeatureInfoEntry, isImage, EsriDynamic } from '@/app';
import { TypeFeatureInfoEntry, api, isImage } from '@/app';
import { getSxClasses } from './data-table-style';
import { useMapStoreActions } from '@/core/stores/store-interface-and-intial-values/map-state';
import {
Expand Down Expand Up @@ -161,8 +159,7 @@ function DataTable({ data, layerPath, tableHeight = 600 }: DataTableProps) {
try {
rowVirtualizerInstanceRef.current?.scrollToIndex?.(0);
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
logger.logError('Data table error on sorting action', error);
}
}, [sorting]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { getCenter } from 'ol/extent';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/no-array-index-key */
import { useState } from 'react';

import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -130,6 +129,7 @@ export function FeatureInfoTable({ featureInfoList }: FeatureInfoTableProps): JS
color: index % 2 > 0 ? theme.palette.geoViewColor.bgColor.darken(0.9) : '',
marginBottom: '20px',
}}
// eslint-disable-next-line react/no-array-index-key
key={index}
>
<Grid item xs="auto" sx={{ fontWeight: 'bold', width: '80% !important' }}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-param-reassign */
import { MutableRefObject, ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { camelCase } from 'lodash';
import { useTheme } from '@mui/material/styles';
Expand Down Expand Up @@ -400,38 +399,18 @@ export function FooterBar(): JSX.Element | null {

// Handle focus using dynamic focus button
const handleDynamicFocus = () => {
const mapIdDiv = document.getElementById(mapId);

if (mapIdDiv) {
if (isFocusToMap) {
// scroll to map
window.scrollTo({
top: mapIdDiv.offsetTop - 30,
behavior: 'smooth',
});
setIsFocusToMap(false);
} else {
const focusButtonId = document.getElementById(`map-${mapId}`);
if (focusButtonId) {
const targetY = focusButtonId.getBoundingClientRect().bottom + window.pageYOffset - 70;
// scroll to footer
window.scrollTo({
top: targetY,
behavior: 'smooth',
});
}

setIsFocusToMap(true);
}
}
const shell = document.getElementById(`shell-${mapId}`);
const block = isFocusToMap ? 'start' : 'end';
shell?.scrollIntoView({ behavior: 'smooth', block });
setIsFocusToMap(!isFocusToMap);
};

return footerBarTabs.length > 0 ? (
<Box
ref={tabsContainerRef as MutableRefObject<HTMLDivElement>}
sx={sxClasses.tabsContainer}
className="tabsContainer"
id="tabsContainer"
id={`${mapId}-tabsContainer`}
>
<Tabs
activeTrap={activeTrapGeoView}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import React, { useState, ReactNode, memo, useEffect } from 'react';
import Markdown from 'markdown-to-jsx';
import { useTranslation } from 'react-i18next';
Expand All @@ -19,6 +18,7 @@ interface GuideListItem extends LayerListEntry {
}

interface GuidePanelType {
// eslint-disable-next-line react/require-default-props
fullWidth?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import React, { useEffect, useState, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useTheme, Theme } from '@mui/material/styles';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-nested-ternary */
/* eslint-disable react/require-default-props */
import React from 'react';
import { useTheme } from '@mui/material/styles';
import { Box, IconButton, BrowserNotSupportedIcon } from '@/ui';
Expand Down Expand Up @@ -29,6 +27,8 @@ export function IconStack({ layerPath, onIconClick, onStackIconClick }: TypeIcon
const numOfIcons: number | undefined = iconData?.length;

const iconStackContent = () => {
// TODO: refactor - try to remove the nested ternary to simplify reading
// eslint-disable-next-line no-nested-ternary
return numOfIcons === 1 ? (
<IconButton sx={sxClasses.iconPreview} color="primary" size="small" onClick={iconImage === 'no data' ? undefined : onIconClick}>
{iconImage === 'no data' ? (
Expand All @@ -39,7 +39,8 @@ export function IconStack({ layerPath, onIconClick, onStackIconClick }: TypeIcon
</Box>
)}
</IconButton>
) : numOfIcons && numOfIcons > 0 ? (
) : // eslint-disable-next-line no-nested-ternary
numOfIcons && numOfIcons > 0 ? (
<Box tabIndex={0} onClick={onIconClick} sx={sxClasses.stackIconsBox} onKeyPress={(e) => onStackIconClick?.(e)}>
<IconButton sx={sxClasses.iconPreviewStacked} color="primary" size="small" tabIndex={-1}>
<Box sx={sxClasses.legendIconTransparent}>
Expand Down
19 changes: 14 additions & 5 deletions packages/geoview-core/src/core/components/layers/layers-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,21 @@ export function LayersPanel() {
return <LayerDetails layerDetails={selectedLayer} />;
}
if (displayState === 'remove') {
// TODO: refactor - remove the need for markup and danger Eslint
const markup = { __html: t('layers.removeLayerDescription') };
/* eslint-disable react/no-danger */
return (
// eslint-disable-next-line react/no-danger
<Paper sx={{ padding: '20px' }}>
<h3>{t('layers.removingLayers')}</h3>
<Box sx={{ display: 'flex', flexDirection: 'row', gap: '2', alignItems: 'center' }}>
<IconButton edge="end" size="small">
<DeleteOutlineIcon color="error" />
</IconButton>
<Box>
<div dangerouslySetInnerHTML={markup} />
{
/* eslint-disable-next-line react/no-danger */
<div dangerouslySetInnerHTML={markup} />
}
</Box>
</Box>
</Paper>
Expand All @@ -74,7 +78,10 @@ export function LayersPanel() {
<Paper sx={{ padding: '20px' }}>
<h3>{t('layers.reArrangeLayers')}</h3>
<Box sx={sxClasses.buttonDescriptionContainer}>
<div dangerouslySetInnerHTML={markup} />
{
/* eslint-disable-next-line react/no-danger */
<div dangerouslySetInnerHTML={markup} />
}
</Box>
</Paper>
);
Expand All @@ -85,11 +92,13 @@ export function LayersPanel() {
<Paper sx={{ padding: '20px' }}>
<h3>{t('layers.addingNewLayer')}</h3>
<Box sx={sxClasses.buttonDescriptionContainer}>
<div dangerouslySetInnerHTML={markup} />
{
/* eslint-disable-next-line react/no-danger */
<div dangerouslySetInnerHTML={markup} />
}
</Box>
</Paper>
);
/* eslint-disable react/no-danger */
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ export function SingleLayer({ isDragging, depth, layer, setIsLayersListPanelVisi
logger.logWarning('reloading layer not implemented...');
};

// TODO: refactor - this button function does nothing as it is the whole container that can be draggable
const handleReArrangeLayer = () => {
// eslint-disable-next-line no-console
console.log('re-arrange layer');
logger.logWarning('re-arrange layer');
};

function renderEditModeButtons() {
Expand Down
2 changes: 1 addition & 1 deletion packages/geoview-core/src/core/containers/focus-trap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export function FocusTrapDialog(props: FocusTrapProps): JSX.Element {

return (
<Modal
container={document.getElementById(focusTrapId)}
container={document.getElementById(focusTrapId)!}
mapId={focusTrapId}
open={open}
aria-labelledby="wcag-dialog-title"
Expand Down
4 changes: 3 additions & 1 deletion packages/geoview-core/src/core/containers/html-to-react.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import { CSSProperties, ReactNode } from 'react';
import parse from 'html-react-parser';

Expand All @@ -7,8 +6,11 @@ import parse from 'html-react-parser';
*/
interface HtmlToReactProps {
htmlContent: string;
// eslint-disable-next-line react/require-default-props
className?: string;
// eslint-disable-next-line react/require-default-props
style?: CSSProperties;
// eslint-disable-next-line react/require-default-props
extraOptions?: Record<string, unknown>;
}

Expand Down
1 change: 0 additions & 1 deletion packages/geoview-core/src/core/containers/shell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/jsx-props-no-spreading */
import { useEffect, useState, useCallback, Fragment } from 'react';
import { useTranslation } from 'react-i18next';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable no-restricted-syntax */
// this esLint is used in many places for findLayerByPath function. It is why we keep it global...
import { useStore } from 'zustand';
import _ from 'lodash';

Expand Down Expand Up @@ -267,6 +267,8 @@ function setOpacityInLayerAndChildren(layer: TypeLegendLayer, opacity: number, m
}

function findLayerByPath(layers: TypeLegendLayer[], layerPath: string): TypeLegendLayer | undefined {
// TODO: refactor - iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations
// eslint-disable-next-line no-restricted-syntax
for (const l of layers) {
if (layerPath === l.layerPath) {
return l;
Expand All @@ -287,6 +289,8 @@ function deleteSingleLayer(layers: TypeLegendLayer[], layerPath: string) {
if (indexToDelete >= 0) {
layers.splice(indexToDelete, 1);
} else {
// TODO: refactor - iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations
// eslint-disable-next-line no-restricted-syntax
for (const l of layers) {
if (l.children && l.children.length > 0) {
deleteSingleLayer(l.children, layerPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console, no-underscore-dangle, no-param-reassign */
/* eslint-disable no-underscore-dangle, no-param-reassign */
// We have a lot of private function with dangle nad many reassigne. We keep it global...
import { Extent } from 'ol/extent';

import Ajv from 'ajv';
Expand Down
1 change: 0 additions & 1 deletion packages/geoview-core/src/core/utils/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { TypeDisplayLanguage, TypeListOfLayerEntryConfig, layerEntryIsGroupLayer } from '@/geo/map/map-schema-types';
import { CONST_LAYER_ENTRY_TYPE, TypeGeoviewLayerType } from '@/geo/layer/geoview-layers/abstract-geoview-layers';
import { logger } from '@/core/utils/logger';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { TypeJsonValue, TypeMapFeaturesConfig } from '@/core/types/global-types';
import { getLocalizedMessage, isJsonString, removeCommentsFromJSON, replaceParams, showError } from '../../utilities';
import { logger } from '@/core/utils/logger';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { TypeMapFeaturesConfig } from '@/core/types/global-types';
import { logger } from '@/core/utils/logger';

Expand Down
2 changes: 1 addition & 1 deletion packages/geoview-core/src/core/utils/date-mgt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable prefer-destructuring */
import dayjs, { Dayjs } from 'dayjs';
import utc from 'dayjs/plugin/utc';
import duration from 'dayjs/plugin/duration';
Expand Down Expand Up @@ -530,6 +529,7 @@ export class DateMgt {
inputFragments[TIME] = 3;
outputFragments[TIME] = 3;
// Get time zone.
// eslint-disable-next-line prefer-destructuring
separators[TIME_ZONE] = timeString.split(/[+-]/)[1];
}

Expand Down
1 change: 1 addition & 0 deletions packages/geoview-core/src/core/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
// console is use at 3 places (error, warn, info). We keep it global...
import { isArray } from 'lodash';
import { getItemAsNumber, getItemAsNumberOrNumberArraySetValue } from './localStorage';

Expand Down
1 change: 1 addition & 0 deletions packages/geoview-core/src/core/utils/useWhatChanged.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
// this utility file uses console to show react hooks. Not mean tu use the logger. We keep it global...
import { useEffect, useRef } from 'react';

// Indicates if currently logging useWhatChanged
Expand Down
Loading

0 comments on commit 30c9026

Please sign in to comment.