Skip to content

Commit

Permalink
CAT-1079 NickAkhmetov/Linting updates (#3646)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickAkhmetov authored Dec 18, 2024
1 parent 4c128f7 commit a333c5b
Show file tree
Hide file tree
Showing 32 changed files with 1,834 additions and 2,056 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-eslint-v9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Update to ESLint v9.
- Update minor versions of development dependencies to resolve security concerns.
4 changes: 0 additions & 4 deletions context/.eslintignore

This file was deleted.

134 changes: 0 additions & 134 deletions context/.eslintrc.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Extracts the CLID from a cell name string provided in the format <Cell Type Name> (<CLID>)
export function extractCLID(cellName: string) {
const match = cellName.match(/\((CL[^)]+)\)/);
const match = /\((CL[^)]+)\)/.exec(cellName);
return match ? match[1] : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ function useDatasetsSelectedByExpression() {
};
try {
completeStep(createStepText(queryType, cellVariableNames, minExpressionLog, minCellPercentage));
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call */
const serviceResults = await new CellsService().getDatasets(queryParams);
const datasets = 'list' in serviceResults ? serviceResults.list : serviceResults;

Expand All @@ -136,7 +135,7 @@ function useDatasetsSelectedByExpression() {
return acc;
}, [] as WrappedCellsResultsDataset[]),
);
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call */

if ('list' in serviceResults) {
setResultCounts(serviceResults);
}
Expand All @@ -150,7 +149,7 @@ function useDatasetsSelectedByExpression() {
// but after the user submits their data, the component collapses,
// so the message is hidden, and the user just sees the please wait.
// Not sure what the best long term solution is, but this unblocks Nils.
// eslint-disable-next-line no-alert

// alert(e.message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const originDenylist = ['https://github.com/hubmapconsortium/portal-containers']
const nameDenylist = ['pipeline.cwl'];

export function getGithubRepoName(origin: string) {
const match = origin.match(/github.com\/([^/]+)\/([^/]+)(\/|$)/);
const match = /github.com\/([^/]+)\/([^/]+)(\/|$)/.exec(origin);
if (match) {
return match[2];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React from 'react';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { fireEvent, waitFor } from '@testing-library/react';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';

// eslint-disable-next-line
import { render, screen, appProviderEndpoints } from 'test-utils/functions';
import sampleProv, { sampleDescendantsProv } from './fixtures/sample_prov';
import donorProv from './fixtures/donor_prov';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function useVitessceConfig({ vitData, setVitessceState, markerGene }: Use
let vitessceURLConf;
try {
vitessceURLConf = fragment.length > 0 ? decodeURLParamsToConf(fragment) : null;
} catch (err) {
} catch {
// If URL cannot be parsed, display error and show Vitessce.
toastError('View configuration from URL was not able to be parsed.');
setVitessceDefaults(vitData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import VisualizationErrorBoundary from './VisualizationError';
import { VizContainerStyleContext } from './ContainerStylingContext';
import { VisualizationSuspenseFallback } from './VisualizationSuspenseFallback';

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
const Visualization = React.lazy(() => import('../Visualization'));

interface VisualizationWrapperProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function usePublicationDatasetsAggs({ descendantUUID, aggsField, associatedColle
const { searchHits: collectionDatasets } = useSearchHits(getCollectionDatasetsQuery(associatedCollectionUUID));

const collectionDatasetsUUIDs =
// eslint-disable-next-line no-underscore-dangle
collectionDatasets.length > 0 ? collectionDatasets[0]?._source?.datasets.map(({ uuid }) => uuid) : [];

const query = associatedCollectionUUID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-underscore-dangle */
import React, { useState } from 'react';
import Paper from '@mui/material/Paper';
import Table from '@mui/material/Table';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function TitleTextField({ handleChange, title }) {
label="Title"
fullWidth
variant="outlined"
// eslint-disable-next-line prettier/prettier
placeholder="Like “Spleen-Related Data” or “ATAC-seq Visualizations”"
inputProps={{ maxLength: maxTitleLength }}
onChange={handleChange}
Expand Down
2 changes: 1 addition & 1 deletion context/app/static/js/components/search/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function SearchBar() {
(e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();

setSearch(input.match(/^\s*HBM\S+\s*$/i) ? `"${input}"` : input);
setSearch(/^\s*HBM\S+\s*$/i.exec(input) ? `"${input}"` : input);

const category = 'Free Text Search';

Expand Down
2 changes: 1 addition & 1 deletion context/app/static/js/components/search/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function parseURLState(stateJSON: string) {
try {
const parsed = searchURLStateSchema.parse(JSON.parse(stateJSON));
return parsed;
} catch (e) {
} catch {
return {};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
// eslint-disable-next-line

import { render, screen } from 'test-utils/functions';

import SelectedFilter from '../SelectedFilter';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
// eslint-disable-next-line

import { render, screen } from 'test-utils/functions';

import SortingTableHead from '../SortingTableHead';
Expand Down
2 changes: 1 addition & 1 deletion context/app/static/js/components/searchPage/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable prettier/prettier */
// eslint-disable-next-line import/named
import { capitalizeString } from 'js/helpers/functions';
import { listFilter, rangeFilter, field, hierarchicalFilter, boolListFilter } from './utils';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
// eslint-disable-next-line

import { render, screen } from 'test-utils/functions';
import { SearchkitProvider, SearchkitManager } from 'searchkit';

Expand Down
6 changes: 3 additions & 3 deletions context/app/static/js/components/workspaces/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function useMatchingWorkspaceTemplates(workspace: MergedWorkspace | Record<strin
const matchingTemplates = workspaceFiles.reduce((acc, file) => {
// match the filename without extension given a file path.
const regex = /[\w-]+?(?=\.)/;
const fileNameMatch = getWorkspaceFileName(file).match(regex);
const fileNameMatch = regex.exec(getWorkspaceFileName(file));
const templateName = fileNameMatch ? fileNameMatch[0] : '';
if (templateName && templateName in templates) {
return { ...acc, [templateName]: templates[templateName] };
Expand Down Expand Up @@ -284,7 +284,7 @@ export function useCreateAndLaunchWorkspace() {

try {
workspace = await createWorkspace(body);
} catch (e) {
} catch {
toastErrorCreateWorkspace();
return;
}
Expand All @@ -298,7 +298,7 @@ export function useCreateAndLaunchWorkspace() {
templatePath,
resourceOptions,
});
} catch (e) {
} catch {
toastErrorLaunchWorkspace();
}
},
Expand Down
2 changes: 1 addition & 1 deletion context/app/static/js/helpers/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function shouldCapitalizeString(s: string, idx = 1) {
if (idx === 0) {
return true;
}
return NOT_CAPITALIZED_WORDS.indexOf(lowerCase) === -1;
return !NOT_CAPITALIZED_WORDS.includes(lowerCase);
}

export function capitalizeAndReplaceDashes(s: string) {
Expand Down
4 changes: 2 additions & 2 deletions context/app/static/js/helpers/swr/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function f({
let errorBody: Record<string, unknown> = { error: rawText };
try {
errorBody = JSON.parse(rawText) as Record<string, unknown>;
} catch (e) {
} catch {
// Ignore and use the raw text instead since error was not returned as json
}
const message = errorMessages[response.status] ?? `The request to ${url} failed.`;
Expand All @@ -48,7 +48,7 @@ async function f({
if (returnResponse) {
return response;
}
return response.json();
return response.json() as Promise<unknown>;
});
}

Expand Down
2 changes: 1 addition & 1 deletion context/app/static/js/hooks/useImmediateDescendantProv.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function getEntityData(hubmapID, elasticsearchEndpoint, groupsToken) {
return {};
}
const results = await response.json();
// eslint-disable-next-line no-underscore-dangle

return results.hits.hits[0]._source;
}

Expand Down
1 change: 1 addition & 0 deletions context/app/static/js/pages/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface WorkspacePageProps {
}

function LaunchStopButton(props: ButtonProps) {
// eslint-disable-next-line @typescript-eslint/no-base-to-string -- this is a valid use case
const variant = props?.children?.toString() === 'Stop Jobs' ? 'outlined' : 'contained';
return <Button {...props} variant={variant} />;
}
Expand Down
2 changes: 1 addition & 1 deletion context/app/static/js/pages/search/Search.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
// eslint-disable-next-line

import { render, screen } from 'test-utils/functions';

import Search from './Search';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function AccordionSteps({ steps, id }: AccordionStepsProps) {
return steps.map(({ heading, content, ref }, i) => (
<StepAccordion
id={`${id}-${i}`}
// eslint-disable-next-line @typescript-eslint/no-base-to-string
key={String(heading)}
index={i}
summaryHeading={heading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import TooltipButtonBase from './TooltipButtonBase';

export type TooltipButtonProps<E extends ElementType = IconButtonTypeMap['defaultComponent']> = {
tooltip: React.ReactNode;
placement?: 'top' | 'bottom' | 'left' | 'right';
} & IconButtonProps<E>;

function TooltipIconButton<E extends ElementType = IconButtonTypeMap['defaultComponent']>(
{ children, ...props }: TooltipButtonProps<E>,
ref: React.Ref<HTMLButtonElement>,
ref: React.ForwardedRef<HTMLButtonElement>,
) {
return (
<TooltipButtonBase {...props} ref={ref} isIconButton>
Expand All @@ -19,7 +20,8 @@ function TooltipIconButton<E extends ElementType = IconButtonTypeMap['defaultCom
);
}

const ForwardedTooltipIconButton = React.forwardRef(TooltipIconButton);
// @ts-expect-error Forwarded refs break button/link polymorphism, so we need to cast the forwarded ref to the correct type
const ForwardedTooltipIconButton = React.forwardRef(TooltipIconButton) as typeof TooltipIconButton;

const RectangularTooltipIconButton = styled(ForwardedTooltipIconButton)(() => ({
borderRadius: '0px',
Expand Down
Loading

0 comments on commit a333c5b

Please sign in to comment.