Skip to content

Commit b210d83

Browse files
Use named Props interfaces instead of defining types inline
1 parent eaf8d68 commit b210d83

5 files changed

Lines changed: 42 additions & 35 deletions

File tree

extensions/ql-vscode/src/view/results/locations/ClickableLocation.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { useCallback } from "react";
33
import { ResolvableLocationValue } from "../../../common/bqrs-cli-types";
44
import { jumpToLocation } from "../result-table-utils";
55

6+
interface Props {
7+
loc: ResolvableLocationValue;
8+
label: string;
9+
databaseUri: string;
10+
title?: string;
11+
jumpToLocationCallback?: () => void;
12+
}
13+
614
/**
715
* A clickable location link.
816
*/
@@ -12,13 +20,7 @@ export function ClickableLocation({
1220
databaseUri,
1321
title,
1422
jumpToLocationCallback,
15-
}: {
16-
loc: ResolvableLocationValue;
17-
label: string;
18-
databaseUri: string;
19-
title?: string;
20-
jumpToLocationCallback?: () => void;
21-
}): JSX.Element {
23+
}: Props): JSX.Element {
2224
const jumpToLocationHandler = useCallback(
2325
(e: React.MouseEvent) => {
2426
jumpToLocation(loc, databaseUri);

extensions/ql-vscode/src/view/results/locations/Location.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import { convertNonPrintableChars } from "../../../common/text-utils";
1010
import { NonClickableLocation } from "./NonClickableLocation";
1111
import { ClickableLocation } from "./ClickableLocation";
1212

13+
interface Props {
14+
loc?: UrlValue;
15+
label?: string;
16+
databaseUri?: string;
17+
title?: string;
18+
jumpToLocationCallback?: () => void;
19+
}
20+
1321
/**
1422
* A location link. Will be clickable if a location URL and database URI are provided.
1523
*/
@@ -19,13 +27,7 @@ export function Location({
1927
databaseUri,
2028
title,
2129
jumpToLocationCallback,
22-
}: {
23-
loc?: UrlValue;
24-
label?: string;
25-
databaseUri?: string;
26-
title?: string;
27-
jumpToLocationCallback?: () => void;
28-
}): JSX.Element {
30+
}: Props): JSX.Element {
2931
const resolvableLoc = useMemo(() => tryGetResolvableLocation(loc), [loc]);
3032
const displayLabel = useMemo(() => convertNonPrintableChars(label!), [label]);
3133
if (loc === undefined) {
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import * as React from "react";
22

3+
interface Props {
4+
msg?: string;
5+
locationHint?: string;
6+
}
7+
38
/**
49
* A non-clickable location for when there isn't a valid link.
510
* Designed to fit in with the other types of location components.
611
*/
7-
export function NonClickableLocation({
8-
msg,
9-
locationHint,
10-
}: {
11-
msg?: string;
12-
locationHint?: string;
13-
}) {
12+
export function NonClickableLocation({ msg, locationHint }: Props) {
1413
if (msg === undefined) return null;
1514
return <span title={locationHint}>{msg}</span>;
1615
}

extensions/ql-vscode/src/view/results/locations/SarifLocation.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import { basename } from "path";
66
import { useMemo } from "react";
77
import { Location } from "./Location";
88

9+
interface Props {
10+
text?: string;
11+
loc?: Sarif.Location;
12+
sourceLocationPrefix: string;
13+
databaseUri: string;
14+
jumpToLocationCallback: () => void;
15+
}
16+
917
/**
1018
* A clickable SARIF location link.
1119
*
@@ -18,13 +26,7 @@ export function SarifLocation({
1826
sourceLocationPrefix,
1927
databaseUri,
2028
jumpToLocationCallback,
21-
}: {
22-
text?: string;
23-
loc?: Sarif.Location;
24-
sourceLocationPrefix: string;
25-
databaseUri: string;
26-
jumpToLocationCallback: () => void;
27-
}) {
29+
}: Props) {
2830
const parsedLoc = useMemo(
2931
() => loc && parseSarifLocation(loc, sourceLocationPrefix),
3032
[loc, sourceLocationPrefix],

extensions/ql-vscode/src/view/results/locations/SarifMessageWithLocations.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import * as Sarif from "sarif";
33
import { parseSarifPlainTextMessage } from "../../../common/sarif-utils";
44
import { SarifLocation } from "./SarifLocation";
55

6+
interface Props {
7+
msg: string;
8+
relatedLocations: Sarif.Location[];
9+
sourceLocationPrefix: string;
10+
databaseUri: string;
11+
jumpToLocationCallback: () => void;
12+
}
13+
614
/**
715
* Parses a SARIF message and populates clickable locations.
816
*/
@@ -12,13 +20,7 @@ export function SarifMessageWithLocations({
1220
sourceLocationPrefix,
1321
databaseUri,
1422
jumpToLocationCallback,
15-
}: {
16-
msg: string;
17-
relatedLocations: Sarif.Location[];
18-
sourceLocationPrefix: string;
19-
databaseUri: string;
20-
jumpToLocationCallback: () => void;
21-
}) {
23+
}: Props) {
2224
const relatedLocationsById: Map<number, Sarif.Location> = new Map();
2325
for (const loc of relatedLocations) {
2426
if (loc.id !== undefined) {

0 commit comments

Comments
 (0)