Skip to content

Commit

Permalink
chore: updated more linting plugins and fixed sonarjs errors (#4309)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaten committed Jan 3, 2025
1 parent cbf0c6e commit 9d3d7b5
Show file tree
Hide file tree
Showing 15 changed files with 3,238 additions and 635 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"prettier",
"plugin:prettier/recommended",
"next",
"plugin:sonarjs/recommended",
"plugin:sonarjs/recommended-legacy",
"plugin:eslint-comments/recommended"
],
"rules": {
Expand Down Expand Up @@ -57,7 +57,10 @@
"jsdoc/require-returns-description": "error",
"jsdoc/check-alignment": "error",
"jsdoc/check-param-names": "error",
"react-hooks/exhaustive-deps": "error"
"react-hooks/exhaustive-deps": "error",
"sonarjs/todo-tag": "warn",
"sonarjs/redundant-type-aliases": "warn",
"sonarjs/no-nested-conditional": "warn"
},
"overrides": [
{
Expand Down
4 changes: 2 additions & 2 deletions __tests__/project-matrix-mapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const LYMPH_NODE = "lymph node";
const MOCK_PROJECT_MATRIX_FILE_0 = {
name: "123.loom",
size: 254147853,
url: "http://path/to/file0?version=0&catalog=dcp2ebi",
url: "https://path/to/file0?version=0&catalog=dcp2ebi",
};
const MOCK_PROJECT_MATRIX_FILE_1 = {
name: "456.loom",
size: 254147854,
url: "http://path/to/file1?version=0&catalog=dcp2ebi",
url: "https://path/to/file1?version=0&catalog=dcp2ebi",
};
const CONTRIBUTED_ANALYSES = {
genusSpecies: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const FileLocationArchivePreview = ({
projectMatrixView,
}: FileLocationArchivePreviewProps): JSX.Element | null => {
const [open, setOpen] = useState<boolean>(false);
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO future loading state for archive preview dialog.
// eslint-disable-next-line @typescript-eslint/no-unused-vars, sonarjs/no-unused-vars, sonarjs/no-dead-store -- TODO future loading state for archive preview dialog.
const [loading, setLoading] = useState<boolean>(false);
return isArchivePreviewAvailable(projectMatrixView) ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export const baseProjectEdits: ProjectEdit[] = [
analysisPortals: [
{
...GENOME_BROWSER,
url: "http://genome.ucsc.edu/cgi-bin/hgTracks?db=mm10&tabulamurisBarChart=pack",
url: "https://genome.ucsc.edu/cgi-bin/hgTracks?db=mm10&tabulamurisBarChart=pack",
},
{
...UCSC_CELL_BROWSER,
Expand Down Expand Up @@ -672,7 +672,7 @@ export const baseProjectEdits: ProjectEdit[] = [
},
{
...SHINY,
url: "http://devapp.lungmap.net/app/shinycell-lungmap-single-cell-multiomic",
url: "https://devapp.lungmap.net/app/shinycell-lungmap-single-cell-multiomic",
},
{
...TOPPCELL,
Expand Down
10 changes: 8 additions & 2 deletions app/viewModelBuilders/azul/hca-dcp/common/viewModelBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
} from "@databiosphere/findable-ui/lib/components/Export/common/entities";
import { CurrentQuery } from "@databiosphere/findable-ui/lib/components/Export/components/ExportSummary/components/ExportCurrentQuery/exportCurrentQuery";
import { Summary } from "@databiosphere/findable-ui/lib/components/Export/components/ExportSummary/components/ExportSelectedDataSummary/exportSelectedDataSummary";
import { ANCHOR_TARGET } from "@databiosphere/findable-ui/lib/components/Links/common/entities";
import {
ANCHOR_TARGET,
REL_ATTRIBUTE,
} from "@databiosphere/findable-ui/lib/components/Links/common/entities";
import { getConfig } from "@databiosphere/findable-ui/lib/config/config";
import { ViewContext } from "@databiosphere/findable-ui/lib/config/entities";
import {
Expand Down Expand Up @@ -712,11 +715,14 @@ export const buildCookieBanner = (): React.ComponentProps<
"This website uses cookies for security and analytics purposes. By using this site, you agree to these uses.",
secondaryAction: C.ButtonOutline({
children: "Learn More",
/* eslint-disable sonarjs/link-with-target-blank -- const used for NOOPRNER NOREFERRER */
onClick: () =>
window.open(
"https://data.humancellatlas.org/privacy",
ANCHOR_TARGET.BLANK
ANCHOR_TARGET.BLANK,
REL_ATTRIBUTE.NO_OPENER_NO_REFERRER
),
/* eslint-enable sonarjs/link-with-target-blank -- check target blank links for the rest of the file */
}),
};
};
Expand Down
4 changes: 4 additions & 0 deletions e2e/anvil/anvil-backpages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
} from "../testFunctions";
import { ANVIL_TABS } from "./anvil-tabs";

//TODO: this should probably check a feature flag instead
//eslint-disable-next-line sonarjs/no-skipped-tests -- disabled since Export to Terra is disabled on AnVIL
test.skip("Smoke test `Export to Terra` button on the first available dataset", async ({
context,
page,
Expand All @@ -20,6 +22,8 @@ test.skip("Smoke test `Export to Terra` button on the first available dataset",
}
});

//TODO: this should probably check a feature flag instead
//eslint-disable-next-line sonarjs/no-skipped-tests -- disabled since Export to Terra is disabled on AnVIL
test.skip("Check access controls on the datasets backpages work for the first two tabs", async ({
page,
}) => {
Expand Down
10 changes: 2 additions & 8 deletions e2e/anvil/anvil-filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test("Check that all filters exist on the Files tab and are clickable", async ({
await testFilterPresence(page, ANVIL_TABS.FILES, ANVIL_FILTER_NAMES);
});

test("Check that the first filter on the Datasets tab creates at least one checkbox, and that checking up to the first five does not cause an error and does not cause there to be no entries in the table", async ({
test("Check that an arbitrary filter on the Datasets tab creates at least one checkbox, and that checking up to the first five does not cause an error and does not cause there to be no entries in the table", async ({
page,
}) => {
// Goto the datasets tab
Expand All @@ -77,13 +77,7 @@ test("Check that the first filter on the Datasets tab creates at least one check
// Select a filter
await page
.getByRole("button")
.getByText(
filterRegex(
ANVIL_FILTER_NAMES[
Math.floor(Math.random() * ANVIL_FILTER_NAMES.length)
]
)
)
.getByText(filterRegex(ANVIL_FILTER_NAMES[FILTER_INDEX_LIST[0]]))
.click();
// Expect all checkboxes to be unchecked initially and to work properly
await expect(page.getByRole("checkbox").first()).toBeVisible();
Expand Down
2 changes: 1 addition & 1 deletion e2e/anvil/anvil-tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const ANVIL_TABS: AnvilCMGTabCollection = {
exportActionButtonText: "Open Terra",
exportRequestButtonText: "Request Link",
exportTabName: "Export",
exportUrlRegExp: /\.*\/export-to-terra/,
exportUrlRegExp: /\/export-to-terra/,
newTabMessage:
"If you are a new user or returning user, click sign in to continue.",
requestLandingMessage:
Expand Down
53 changes: 28 additions & 25 deletions e2e/testFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
const TIMEOUT_EXPORT_REQUEST = 60000;
const TIMEOUT_DOWNLOAD = 10000;

// Filter length const for regexes
const MAX_FILTER_LENGTH = 256;

/**
* Get an array of all visible column header names
* @param page - a Playwright page object
Expand Down Expand Up @@ -365,7 +368,7 @@ export async function testPreSelectedColumns(
* @returns a regular expression matching "[filterName] ([n])"
*/
export const filterRegex = (filterName: string): RegExp =>
new RegExp(escapeRegExp(filterName) + "\\s+\\([0-9]+\\)\\s*");
new RegExp(escapeRegExp(filterName) + "\\s+\\(\\d+\\)\\s*");

/**
* Checks that each filter specified in filterNames is visible and can be
Expand Down Expand Up @@ -467,7 +470,7 @@ const getFirstNonEmptyFilterOptionInfo = async (
let i = 0;
while (filterToSelect === "" && i < MAX_FILTER_OPTIONS_TO_CHECK) {
// Filter options display as "[text]\n[number]" , sometimes with extra whitespace, so we want the string before the newline
const filterOptionRegex = /^(.*)\n+([0-9]+)\s*$/;
const filterOptionRegex = /^(.*)\n+(\d+)\s*$/;
filterOptionLocator = getNthFilterOptionLocator(page, i);
const filterNameMatch = (await filterOptionLocator.innerText())
.trim()
Expand Down Expand Up @@ -1004,7 +1007,7 @@ const hoverAndGetText = async (
if (
!columnDescription !== undefined &&
columnDescription?.pluralizedLabel !== undefined &&
RegExp("\\s*[0-9]+ " + columnDescription.pluralizedLabel + "\\s*").test(
RegExp("\\s*\\d+ " + columnDescription.pluralizedLabel + "\\s*").test(
cellText
)
) {
Expand Down Expand Up @@ -1186,7 +1189,7 @@ export async function testIndexExportSummary(
await expect(indexExportButtonLocator).toBeVisible();
for (const detail of tab.indexExportPage.detailsToCheck) {
// This Regexp gets a decimal number, some whitespace, then the name of the detail, matching how the detail box appears to Playwright.
const detailBoxRegexp = RegExp(`^([0-9]+\\.[0-9]+k)\\s*${detail}$`);
const detailBoxRegexp = RegExp(`^(\\d+\\.\\d+k)\\s*${detail}$`);
// This gets the detail's value. The .trim() is necessary since innertext adds extraneous whitespace on Webkit
const headerValueArray = (await page.getByText(detailBoxRegexp).innerText())
.trim()
Expand Down Expand Up @@ -1217,10 +1220,9 @@ export async function testIndexExportSummary(
return true;
}

const PAGE_COUNT_REGEX = /Page [0-9]+ of [0-9]+/;
const PAGE_COUNT_REGEX = /Page \d+ of \d+/;
const BACK_BUTTON_TEST_ID = "WestRoundedIcon";
const FORWARD_BUTTON_TEST_ID = "EastRoundedIcon";
const ERROR = "ERROR";
const MAX_PAGINATIONS = 200;

/**
Expand All @@ -1236,7 +1238,7 @@ export async function testFirstPagePagination(
await expect(getFirstRowNthColumnCellLocator(page, 0)).toBeVisible();
// Should start on first page
await expect(page.getByText(PAGE_COUNT_REGEX, { exact: true })).toHaveText(
/Page 1 of [0-9]+/
/Page 1 of \d+/
);
// Forward button should start enabled
await expect(
Expand Down Expand Up @@ -1270,42 +1272,43 @@ export async function filterAndTestLastPagePagination(
await expect(page.getByRole("checkbox").first()).toBeVisible();
const filterTexts = await page
.getByRole("button")
.filter({ hasText: /([0-9]+)[\n\s]*$/ })
.filter({ hasText: RegExp("(\\d{1," + MAX_FILTER_LENGTH + "})[\\s]*$") })
.allInnerTexts();
// Get the filter with the lowest associated count
const filterCounts = filterTexts
.map((filterText) =>
(
(filterText.match(/[^a-zA-Z0-9]+([0-9]+)[\n\s]*$/) ?? [
undefined,
"",
])[1] ?? ERROR
).trim()
const validFilterCounts = filterTexts
.map(
// Get filter counts
(filterOption) =>
filterOption
.split("\n")
.reverse()
.map((x) => Number(x))
.find((x) => !isNaN(x) && x !== 0) ?? -1
)
.map((numberText) => parseInt(numberText))
.filter(
/// Filter for counts that will produce a useful number of paginations
(n) =>
!isNaN(n) &&
n > (tab.maxPages ?? 0) * 3 &&
n < (tab.maxPages ?? 0) * MAX_PAGINATIONS
);
if (filterCounts.length == 0) {
if (validFilterCounts.length == 0) {
console.log(
"PAGINATION LAST PAGE: Test would involve too many paginations, so halting"
"PAGINATION LAST PAGE: Test would involve too many or too few paginations, so halting"
);
return false;
}
const minFilterValue = Math.min(...filterCounts);
const minFilterValue = Math.min(...validFilterCounts);
await page
.getByRole("button")
.filter({ hasText: RegExp(`${minFilterValue}[\\n\\s]*$`) })
.filter({ hasText: RegExp(`${minFilterValue}[\\s]*$`) })
.click();
await page.locator("body").click();
await expect(getFirstRowNthColumnCellLocator(page, 0)).toBeVisible();

// Should start on first page, and there should be multiple pages available
await expect(page.getByText(PAGE_COUNT_REGEX, { exact: true })).toHaveText(
/Page 1 of [0-9]+/
/Page 1 of \d+/
);
await expect(
page.getByText(PAGE_COUNT_REGEX, { exact: true })
Expand Down Expand Up @@ -1368,7 +1371,7 @@ export async function testPaginationContent(

// Should start on first page
await expect(page.getByText(PAGE_COUNT_REGEX, { exact: true })).toHaveText(
/Page 1 of [0-9]+/
/Page 1 of \d+/
);
const maxPages = 5;
const FirstTableEntries = [];
Expand All @@ -1384,7 +1387,7 @@ export async function testPaginationContent(
.click();
// Expect the page count to have incremented
await expect(page.getByText(PAGE_COUNT_REGEX, { exact: true })).toHaveText(
RegExp(`Page ${i} of [0-9]+`)
RegExp(`Page ${i} of \\d+`)
);
// Expect the back button to be enabled
await expect(
Expand Down Expand Up @@ -1417,7 +1420,7 @@ export async function testPaginationContent(
.click();
// Expect page number to be correct
await expect(page.getByText(PAGE_COUNT_REGEX, { exact: true })).toHaveText(
RegExp(`Page ${maxPages - i - 1} of [0-9]+`)
RegExp(`Page ${maxPages - i - 1} of \\d+`)
);
// Expect page entry to be consistent with forward pagination
await expect(firstElementTextLocator).toHaveText(OldFirstTableEntry);
Expand Down
Loading

0 comments on commit 9d3d7b5

Please sign in to comment.