Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Down to 181 lint warnings. #4816

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions static/js/apps/visualization/stat_var_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function StatVarSelector(props: StatVarSelectorPropType): JSX.Element {
{selectedStatVars.length >= (visTypeConfig.numSv || 1) && (
<div
className="primary-button continue-button"
onClick={() => setStatVars(selectedStatVars)}
onClick={(): void => setStatVars(selectedStatVars)}
>
Display
</div>
Expand All @@ -135,7 +135,7 @@ export function StatVarSelector(props: StatVarSelectorPropType): JSX.Element {
id="statvar-modal"
>
<ModalHeader
toggle={() => {
toggle={(): void => {
removeSv(extraSv.dcid);
setExtraSv(null);
}}
Expand All @@ -158,7 +158,7 @@ export function StatVarSelector(props: StatVarSelectorPropType): JSX.Element {
type="radio"
name="statvar"
defaultChecked={idx === modalSelection}
onClick={() => setModalSelection(idx)}
onClick={(): void => setModalSelection(idx)}
/>
{sv.info.title || sv.dcid}
</Label>
Expand All @@ -171,7 +171,7 @@ export function StatVarSelector(props: StatVarSelectorPropType): JSX.Element {
<ModalFooter>
<Button
color="primary"
onClick={() => {
onClick={(): void => {
const newStatVars = _.cloneDeep(selectedStatVars).filter(
(sv) => sv.dcid !== extraSv.dcid
);
Expand Down
8 changes: 4 additions & 4 deletions static/js/chart/draw_line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ export function drawLineChart(
`line ${LEGEND_HIGHLIGHT_CLASS} ${legendKeyFn(dataGroup.label)}`
)
.attr("d", line)
.attr("part", (d) =>
.attr("part", () =>
["series", `series-variable-${dataGroup.label}`].join(" ")
)
.style("fill", "none")
Expand All @@ -513,7 +513,7 @@ export function drawLineChart(
)
.attr("cx", (d) => xScale(d.time))
.attr("cy", (d) => yScale(d.value))
.attr("part", (d) =>
.attr("part", () =>
["series-point", `series-point-variable-${dataGroup.label}`].join(" ")
)
.attr("r", (d) => (d.value === null ? 0 : 3))
Expand Down Expand Up @@ -549,7 +549,7 @@ export function drawLineChart(
top: 0,
};
const dataGroupsDict = { [DATAGROUP_UNKNOWN_PLACE]: dataGroups };
const highlightColorFn = (_: string, dataGroup: DataGroup) => {
const highlightColorFn = (_: string, dataGroup: DataGroup): string => {
return colorFn(dataGroup.label);
};

Expand Down Expand Up @@ -813,7 +813,7 @@ export function drawGroupLineChart(
right: width - legendWidth + LEGEND.marginLeft,
top: 0,
};
const highlightColorFn = (place: string, dataGroup: DataGroup) => {
const highlightColorFn = (place: string, dataGroup: DataGroup): string => {
return plotParams.lines[place + dataGroup.label].color;
};
addHighlightOnHover(
Expand Down
27 changes: 20 additions & 7 deletions static/js/components/nl_search_bar/auto_complete_input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const LOCATION_SEARCH = "location_search";

export interface AutoCompleteResult {
dcid: string;
match_type: string;
matched_query: string;
matchType: string;
matchedQuery: string;
name: string;
}

Expand All @@ -68,6 +68,17 @@ interface AutoCompleteInputPropType {
barType: string;
}

function convertJSONToAutoCompleteResults(
json: object[]
): AutoCompleteResult[] {
return json.map((json) => ({
dcid: json["dcid"],
matchType: json["match_type"],
matchedQuery: json["matched_query"],
name: json["name"],
}));
}

export function AutoCompleteInput(
props: AutoCompleteInputPropType
): ReactElement {
Expand Down Expand Up @@ -206,7 +217,9 @@ export function AutoCompleteInput(
.then((response) => {
if (!controller.current.signal.aborted) {
setResults({
placeResults: response["data"]["predictions"],
placeResults: convertJSONToAutoCompleteResults(
response["data"]["predictions"]
),
svResults: [],
});
}
Expand Down Expand Up @@ -259,7 +272,7 @@ export function AutoCompleteInput(
query: string,
result: AutoCompleteResult
): string {
return stripPatternFromQuery(query, result.matched_query) + result.name;
return stripPatternFromQuery(query, result.matchedQuery) + result.name;
}

function processArrowKey(selectedIndex: number): void {
Expand All @@ -281,10 +294,10 @@ export function AutoCompleteInput(
});

if (
result["match_type"] == LOCATION_SEARCH &&
stripPatternFromQuery(baseInput, result.matched_query).trim() === ""
result.matchType == LOCATION_SEARCH &&
stripPatternFromQuery(baseInput, result.matchedQuery).trim() === ""
) {
// If this is a location result, and the matched_query matches the base input
// If this is a location result, and the matchedQuery matches the base input
// then that means there are no other parts of the query, so it's a place only
// redirection.
if (result.dcid) {
Expand Down
10 changes: 5 additions & 5 deletions static/js/components/nl_search_bar/auto_complete_suggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export function AutoCompleteSuggestions(
): ReactElement {
const [triggered, setTriggered] = useState(false);

function getIcon(query: string, matched_query: string): string {
if (query.trim() == matched_query.trim()) {
function getIcon(query: string, matchedQuery: string): string {
if (query.trim() == matchedQuery.trim()) {
return "location_on";
}
return "search";
Expand Down Expand Up @@ -72,16 +72,16 @@ export function AutoCompleteSuggestions(
<div
className="search-input-result"
key={"search-input-result-" + result.dcid}
onClick={() => props.onClick(result, idx)}
onClick={(): void => props.onClick(result, idx)}
>
<span className="material-icons-outlined search-result-icon">
{getIcon(props.baseInput, result.matched_query)}
{getIcon(props.baseInput, result.matchedQuery)}
</span>
<div className="query-result">
<span>
{stripPatternFromQuery(
props.baseInput,
result.matched_query
result.matchedQuery
)}
<span className="query-suggestion">{result.name}</span>
</span>
Expand Down
15 changes: 11 additions & 4 deletions static/js/components/tiles/bar_tile.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ declare global {
}

beforeAll(() => {
SVGElement.prototype.getComputedTextLength = () => 100;
SVGElement.prototype.getBBox = () => ({ x: 1, y: 1, width: 1, height: 1 });
SVGElement.prototype.getComputedTextLength = (): number => 100;
SVGElement.prototype.getBBox = (): {
x: number;
y: number;
width: number;
height: number;
} => ({ x: 1, y: 1, width: 1, height: 1 });
});

function mockAxios(): void {
mockedAxios.post.mockImplementation((url, options) => {
mockedAxios.post.mockImplementation((url, _) => {
if (url === "/api/place/name") {
return Promise.resolve({
data: {
Expand All @@ -74,8 +79,9 @@ function mockAxios(): void {
return Promise.resolve({});
});

mockedAxios.get.mockImplementation((url, options) => {
mockedAxios.get.mockImplementation((url, _) => {
if (url === "/api/observations/point/within") {
/* eslint-disable camelcase */
return Promise.resolve({
data: {
data: {
Expand Down Expand Up @@ -111,6 +117,7 @@ function mockAxios(): void {
},
},
});
/* eslint-enable camelcase */
} else if (url === "/api/node/propvals/out") {
return Promise.resolve({
data: { sector_property: [] },
Expand Down
6 changes: 3 additions & 3 deletions static/js/components/tiles/disaster_event_map_tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export function fetchChartData(
"polygonGeoJsonProp",
props.apiRoot
);
const childGeoJsonPromiseFn = () =>
const childGeoJsonPromiseFn = (): Promise<GeoJsonData> =>
fetchGeoJsonData(
props.place,
props.enclosedPlaceType,
Expand All @@ -426,7 +426,7 @@ export function fetchChartData(
break;
}
}
const placeGeoJsonPromiseFn = () =>
const placeGeoJsonPromiseFn = (): Promise<GeoJsonData> =>
fetchNodeGeoJson([props.place.dcid], placeGeoJsonProp, props.apiRoot);
const placeGeoJsonPromise = fetchData
? fetchData(
Expand All @@ -439,7 +439,7 @@ export function fetchChartData(
? Promise.resolve(props.parentPlaces)
: null;
if (!parentPlacesPromise) {
const parentPlacesPromiseFn = () =>
const parentPlacesPromiseFn = (): Promise<Array<NamedTypedPlace>> =>
getParentPlacesPromise(props.place.dcid, props.apiRoot);
parentPlacesPromise = fetchData
? fetchData(`parents-${props.place.dcid}`, parentPlacesPromiseFn)
Expand Down
4 changes: 2 additions & 2 deletions static/js/components/tiles/gauge_tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function GaugeTile(props: GaugeTilePropType): JSX.Element {
}
// fetch data
if (!gaugeData || !_.isEqual(gaugeData.props, props)) {
(async () => {
(async (): Promise<void> => {
const data = await fetchData(props);
setGaugeData(data);
})();
Expand Down Expand Up @@ -171,7 +171,7 @@ const fetchData = async (props: GaugeTilePropType) => {
props.apiRoot
);

const { unit, scaling } = getStatFormat(props.statVarSpec, statResp);
const scaling = getStatFormat(props.statVarSpec, statResp).scaling;
const sources = new Set<string>();
const statData = statResp.data[props.statVarSpec.statVar][props.place.dcid];
if (statResp.facets[statData.facet]) {
Expand Down
6 changes: 4 additions & 2 deletions static/js/components/tiles/highlight_tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function HighlightTile(props: HighlightTilePropType): JSX.Element {
);

useEffect(() => {
(async () => {
(async (): Promise<void> => {
try {
const data = await fetchData(props);
setHighlightData(data);
Expand Down Expand Up @@ -151,7 +151,9 @@ export function getDescription(
return description;
}

export const fetchData = async (props: HighlightTilePropType) => {
export const fetchData = async (
props: HighlightTilePropType
): Promise<HighlightData> => {
// Now assume highlight only talks about one stat var.
const statPromise = getPoint(
props.apiRoot,
Expand Down
8 changes: 5 additions & 3 deletions static/js/components/tiles/line_tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function LineTile(props: LineTilePropType): JSX.Element {
return;
}
if (!chartData || !_.isEqual(chartData.props, props)) {
(async () => {
(async (): Promise<void> => {
try {
setIsLoading(true);
const data = await fetchData(props);
Expand Down Expand Up @@ -231,7 +231,7 @@ function getDataCsvCallback(props: LineTilePropType): () => Promise<string> {
* @param props LineTile props
* @returns Array of place dcids
*/
function getPlaceDcids(props: LineTilePropType) {
function getPlaceDcids(props: LineTilePropType): string[] {
return props.comparisonPlaces && props.comparisonPlaces.length > 0
? props.comparisonPlaces
: [props.place.dcid];
Expand All @@ -246,7 +246,9 @@ export function getReplacementStrings(
};
}

export const fetchData = async (props: LineTilePropType) => {
export const fetchData = async (
props: LineTilePropType
): Promise<LineChartData> => {
const facetToVariable = { [EMPTY_FACET_ID_KEY]: [] };
for (const spec of props.statVarSpec) {
const facetId = spec.facetId || EMPTY_FACET_ID_KEY;
Expand Down
4 changes: 2 additions & 2 deletions static/js/components/tiles/loading_header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export function LoadingHeader(props: {
isLoading: boolean;
title?: string;
}): JSX.Element {
const { isLoading, title, ...headerProps } = props;
const { isLoading, title } = props;
return (
<h4 {...{ part: "header" }}>
{props.isLoading ? (
{isLoading ? (
<>
<Spinner color="secondary" size="sm" className="mr-1" />
{title ? title : "Loading..."}
Expand Down
6 changes: 3 additions & 3 deletions static/js/components/tiles/map_tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function MapTile(props: MapTilePropType): JSX.Element {
!_.isEqual(mapChartData.props, props) ||
!_.isEqual(mapChartData.dateOverride, dateOverride)
) {
(async () => {
(async (): Promise<void> => {
try {
setIsLoading(true);
const data = await fetchData(props, dateOverride);
Expand Down Expand Up @@ -283,7 +283,7 @@ export function MapTile(props: MapTilePropType): JSX.Element {
}, [props, mapChartData, svgContainer, legendContainer, mapContainer]);
useDrawOnResize(drawFn, svgContainer.current);
useEffect(() => {
const eventHandler = (e: CustomEvent<ChartEventDetail>) => {
const eventHandler = (e: CustomEvent<ChartEventDetail>): void => {
if (e.detail.property === "date") {
setDateOverride(e.detail.value);
}
Expand Down Expand Up @@ -315,7 +315,7 @@ export function MapTile(props: MapTilePropType): JSX.Element {
}
className={`${props.className} map-chart`}
allowEmbed={true}
getDataCsv={async () => {
getDataCsv={async (): Promise<string> => {
const layers = getDataSpec(props);
const rows: DataRow[] = [];
for (const layer of layers) {
Expand Down
2 changes: 1 addition & 1 deletion static/js/components/tiles/ranking_tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function RankingTile(props: RankingTilePropType): JSX.Element {
if (props.lazyLoad && !shouldLoad) {
return;
}
(async () => {
(async (): Promise<void> => {
try {
setIsLoading(true);
const rankingData = await fetchData(props);
Expand Down
6 changes: 4 additions & 2 deletions static/js/components/tiles/scatter_tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function ScatterTile(props: ScatterTilePropType): JSX.Element {
// only re-fetch if the props that affect data fetch are not equal
return;
}
(async () => {
(async (): Promise<void> => {
try {
setIsLoading(true);
const data = await fetchData(props);
Expand Down Expand Up @@ -294,7 +294,9 @@ function getPopulationPromise(
}
}

export const fetchData = async (props: ScatterTilePropType) => {
export const fetchData = async (
props: ScatterTilePropType
): Promise<ScatterChartData> => {
if (props.statVarSpec.length < 2) {
// TODO: add error message
return;
Expand Down
7 changes: 5 additions & 2 deletions static/js/components/tiles/use_draw_on_resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ import { useEffect } from "react";
// Number of ms to debounce re-draws when chart is resized
export const RESIZE_DEBOUNCE_INTERVAL_MS = 10;

export function useDrawOnResize(drawFn: () => void, chartContainer: Element) {
export function useDrawOnResize(
drawFn: () => void,
chartContainer: Element
): void {
useEffect(() => {
if (!chartContainer) {
return;
}
const debouncedHandler = _.debounce(drawFn, RESIZE_DEBOUNCE_INTERVAL_MS);
const resizeObserver = new ResizeObserver(debouncedHandler);
resizeObserver.observe(chartContainer);
return () => {
return (): void => {
resizeObserver.unobserve(chartContainer);
debouncedHandler.cancel();
};
Expand Down
2 changes: 1 addition & 1 deletion static/js/homepage/carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function Carousel(props: CarouselPropType): JSX.Element {
})}
</div>
<div
onClick={() => setIdxStart((idxStart + 1) % props.items.length)}
onClick={(): void => setIdxStart((idxStart + 1) % props.items.length)}
className="navigation-button"
>
<span className="material-icons-outlined">navigate_next</span>
Expand Down
Loading
Loading