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

Start using eslint-plugin-deprecation to find deprecated code #3275

Merged
merged 8 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions extensions/ql-vscode/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const baseConfig = {
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:deprecation/recommended",
],
rules: {
"@typescript-eslint/await-thenable": "error",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as React from "react";
import { addons, types } from "@storybook/manager-api";
import { addons } from "@storybook/manager-api";
import { Addon_TypesEnum } from "@storybook/types";
import { ThemeSelector } from "./ThemeSelector";

const ADDON_ID = "vscode-theme-addon";

addons.register(ADDON_ID, () => {
addons.add(ADDON_ID, {
title: "VSCode Themes",
type: types.TOOL,
type: Addon_TypesEnum.TOOL,
match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)),
render: () => <ThemeSelector />,
});
Expand Down
16 changes: 16 additions & 0 deletions extensions/ql-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,7 @@
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-etc": "^2.0.2",
"eslint-plugin-github": "^4.4.1",
"eslint-plugin-import": "^2.29.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,22 @@ Example.args = {
};

faker.seed(42);
const uniqueStore = {};
const uniqueNumbers = [...Array(1000).keys()].sort(() => Math.random() - 0.5);

const manyScannedRepos = Array.from({ length: 1000 }, (_, i) => {
const mockedScannedRepo = createMockScannedRepo();
const randomInt = uniqueNumbers.pop();
const uniqueId =
randomInt === undefined ? Math.random() * 8000 + 1001 : randomInt;
Copy link
Contributor Author

@norascheuch norascheuch Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since array.pop() returns a number OR undefined I needed to add an alternative for the undefined case. This is a best effort for a random number bigger than 1000 without using a library to create it. This case should never happen since the uniqueNumbers array is never empty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of having code that's not intended to execute, and that branch isn't just throwing an error. I have a few potential solutions to make things a little cleaner:

Throw an error instead

I'd be happy if we threw an error if pop ever returns undefined. As you say it shouldn't ever happen, so if it does then the code needs to be updated rather than using a fallback strategy.

Iterate over uniqueNumbers

Instead of doing Array.from({ length: 1000 }, (_, i) => to initiate the loop, do uniqueNumbers.map(repoId => so that we remove the need to call pop.

Just use Math.random() and don't precompute a random list

The repo ids don't have to go from 0-999. They just need to be unique, and even then it's only the storybook so not too critical. If we use big enough numbers, e.g. Math.floor(Math.random() * 1000000000000) (AFAIK the max safe int in javascript is 9007199254740991), then the chance of getting duplicates in our 1000 repo ids becomes very low.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer the error, as you say it should never happen and if it does we should look at it!


return {
...mockedScannedRepo,
analysisStatus: VariantAnalysisRepoStatus.Succeeded,
resultCount: faker.number.int({ min: 0, max: 1000 }),
repository: {
...mockedScannedRepo.repository,
// We need to ensure the ID is unique for React keys
id: faker.helpers.unique(faker.number.int, [], {
store: uniqueStore,
}),
fullName: `octodemo/${faker.helpers.unique(faker.word.sample, [], {
store: uniqueStore,
})}`,
id: uniqueId,
fullName: `octodemo/${uniqueId}`,
},
};
});
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/view/compare/Compare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Message = styled.div`
padding: 1.5rem;
`;

export function Compare(_: Record<string, never>): JSX.Element {
export function Compare(_: Record<string, never>): React.JSX.Element {
const [queryInfo, setQueryInfo] =
useState<SetComparisonQueryInfoMessage | null>(null);
const [comparison, setComparison] = useState<SetComparisonsMessage | null>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const DataFlowPaths = ({
dataFlowPaths,
}: {
dataFlowPaths: DataFlowPathsDomainModel;
}): JSX.Element => {
}): React.JSX.Element => {
const [selectedCodeFlow, setSelectedCodeFlow] = useState(
dataFlowPaths.codeFlows[0],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type DataFlowPathsViewProps = {

export function DataFlowPathsView({
dataFlowPaths: initialDataFlowPaths,
}: DataFlowPathsViewProps): JSX.Element {
}: DataFlowPathsViewProps): React.JSX.Element {
const [dataFlowPaths, setDataFlowPaths] = useState<
DataFlowPathsDomainModel | undefined
>(initialDataFlowPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const MethodModeling = ({
method,
isModelingInProgress,
onChange,
}: MethodModelingProps): JSX.Element => {
}: MethodModelingProps): React.JSX.Element => {
return (
<Container>
<Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const MethodModelingInputs = ({
modelingStatus,
isModelingInProgress,
onChange,
}: MethodModelingInputsProps): JSX.Element => {
}: MethodModelingInputsProps): React.JSX.Element => {
const inputProps = {
language,
method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ type Props = {
initialViewState?: MethodModelingPanelViewState;
};

export function MethodModelingView({ initialViewState }: Props): JSX.Element {
export function MethodModelingView({
initialViewState,
}: Props): React.JSX.Element {
const [viewState, setViewState] = useState<
MethodModelingPanelViewState | undefined
>(initialViewState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const TypeMethodName = (method: Method) => {
);
};

export const MethodName = (method: Method): JSX.Element => {
export const MethodName = (method: Method): React.JSX.Element => {
return (
<Name>
{method.packageName && <>{method.packageName}.</>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function ModelEditor({
initialMethods = [],
initialModeledMethods = {},
initialHideModeledMethods = INITIAL_HIDE_MODELED_METHODS_VALUE,
}: Props): JSX.Element {
}: Props): React.JSX.Element {
const [viewState, setViewState] = useState<ModelEditorViewState | undefined>(
initialViewState,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const ModelInputDropdown = ({
modeledMethod,
modelingStatus,
onChange,
}: Props): JSX.Element => {
}: Props): React.JSX.Element => {
const options = useMemo(() => {
const modelsAsDataLanguage = getModelsAsDataLanguage(language);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const ModelOutputDropdown = ({
modeledMethod,
modelingStatus,
onChange,
}: Props): JSX.Element => {
}: Props): React.JSX.Element => {
const options = useMemo(() => {
const modelsAsDataLanguage = getModelsAsDataLanguage(language);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ModelTypeDropdown = ({
modeledMethod,
modelingStatus,
onChange,
}: Props): JSX.Element => {
}: Props): React.JSX.Element => {
const options = useMemo(() => {
const baseOptions: Array<{ value: ModeledMethodType; label: string }> = [
{ value: "none", label: "Unmodeled" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const ModelTypeTextbox = ({
typeInfo,
onChange,
...props
}: Props): JSX.Element => {
}: Props): React.JSX.Element => {
const [value, setValue] = useState<string | undefined>(
modeledMethod[typeInfo],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface Props {
showRawResults: () => void;
}

export function AlertTableNoResults(props: Props): JSX.Element {
export function AlertTableNoResults(props: Props): React.JSX.Element {
if (props.nonemptyRawResults) {
return (
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ interface Props {
numTruncatedResults: number;
}

export function AlertTableTruncatedMessage(props: Props): JSX.Element | null {
export function AlertTableTruncatedMessage(
props: Props,
): React.JSX.Element | null {
if (props.numTruncatedResults === 0) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Container = styled.span`
text-align: center;
`;

export function EmptyQueryResultsMessage(): JSX.Element {
export function EmptyQueryResultsMessage(): React.JSX.Element {
return (
<Root>
<Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Props {
handleCheckboxChanged: (event: React.ChangeEvent<HTMLInputElement>) => void;
}

export function ProblemsViewCheckbox(props: Props): JSX.Element | null {
export function ProblemsViewCheckbox(props: Props): React.JSX.Element | null {
const { selectedTable, problemsViewSelected, handleCheckboxChanged } = props;

if (selectedTable !== ALERTS_TABLE_NAME) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/view/results/RawTableValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function RawTableValue({
value,
databaseUri,
onSelected,
}: Props): JSX.Element {
}: Props): React.JSX.Element {
switch (value.type) {
case "boolean":
return <span>{value.value.toString()}</span>;
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/view/results/ResultCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getResultCount(resultSet: ResultSet): number {
}
}

export function ResultCount(props: Props): JSX.Element | null {
export function ResultCount(props: Props): React.JSX.Element | null {
if (!props.resultSet) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function ClickableLocation({
label,
databaseUri,
onClick: onClick,
}: Props): JSX.Element {
}: Props): React.JSX.Element {
const handleClick = useCallback(
(e: React.MouseEvent) => {
e.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function Location({
databaseUri,
title,
onClick,
}: Props): JSX.Element {
}: Props): React.JSX.Element {
const displayLabel = useMemo(() => convertNonPrintableChars(label), [label]);

if (loc === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function VariantAnalysis({
variantAnalysis: initialVariantAnalysis,
repoStates: initialRepoStates = [],
repoResults: initialRepoResults = [],
}: VariantAnalysisProps): JSX.Element {
}: VariantAnalysisProps): React.JSX.Element {
const [variantAnalysis, setVariantAnalysis] = useState<
VariantAnalysisDomainModel | undefined
>(initialVariantAnalysis);
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/view/webview-definition.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type WebviewDefinition = {
component: JSX.Element;
component: React.JSX.Element;
};
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("Releases API consumer", () => {

await expect(
consumer.getLatestRelease(new Range("5.*.*")),
).rejects.toThrowError();
).rejects.toThrow();
});

it("picked release passes additional compatibility test if an additional compatibility test is specified", async () => {
Expand All @@ -140,7 +140,7 @@ describe("Releases API consumer", () => {
(asset) => asset.name === "otherExampleAsset.txt",
),
),
).rejects.toThrowError();
).rejects.toThrow();
});

it("picked release is the most recent prerelease when includePrereleases is set", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe(VariantAnalysisResultsManager.name, () => {
async function* generateInParts() {
const partLength = fileContents.length / 5;
for (let i = 0; i < 5; i++) {
yield fileContents.slice(i * partLength, (i + 1) * partLength);
yield fileContents.subarray(i * partLength, (i + 1) * partLength);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ describe("local databases", () => {
Uri.parse("file:/sourceArchive-uri/"),
);
(db as any).contents.sourceArchiveUri = undefined;
expect(() => db.resolveSourceFile("abc")).toThrowError(
"Scheme is missing",
);
expect(() => db.resolveSourceFile("abc")).toThrow("Scheme is missing");
});

it("should fail to resolve when not a file uri", () => {
Expand All @@ -308,7 +306,7 @@ describe("local databases", () => {
Uri.parse("file:/sourceArchive-uri/"),
);
(db as any).contents.sourceArchiveUri = undefined;
expect(() => db.resolveSourceFile("http://abc")).toThrowError(
expect(() => db.resolveSourceFile("http://abc")).toThrow(
"Invalid uri scheme",
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe("listDatabases", () => {
it("throws an error", async () => {
await expect(
listDatabases(owner, repo, credentials, config),
).rejects.toThrowError("Not found");
).rejects.toThrow("Not found");
});
});

Expand All @@ -150,7 +150,7 @@ describe("listDatabases", () => {
it("throws an error", async () => {
await expect(
listDatabases(owner, repo, credentials, config),
).rejects.toThrowError("Internal server error");
).rejects.toThrow("Internal server error");
});
});
});
Expand Down Expand Up @@ -199,7 +199,7 @@ describe("listDatabases", () => {
it("throws an error", async () => {
await expect(
listDatabases(owner, repo, credentials, config),
).rejects.toThrowError("Internal server error");
).rejects.toThrow("Internal server error");
expect(mockListCodeqlDatabases).not.toHaveBeenCalled();
});
});
Expand Down Expand Up @@ -270,7 +270,7 @@ describe("listDatabases", () => {
it("throws an error", async () => {
await expect(
listDatabases(owner, repo, credentials, config),
).rejects.toThrowError("Not found");
).rejects.toThrow("Not found");
});
});

Expand All @@ -297,7 +297,7 @@ describe("listDatabases", () => {
it("throws an error", async () => {
await expect(
listDatabases(owner, repo, credentials, config),
).rejects.toThrowError("Internal server error");
).rejects.toThrow("Internal server error");
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe("resolveQueries", () => {
"tags contain": ["ide-contextual-queries/print-ast"],
},
),
).rejects.toThrowError(
).rejects.toThrow(
'No my query queries (kind "graph", tagged "ide-contextual-queries/print-ast") could be found in the current library path (tried searching the following packs: my-qlpack). Try upgrading the CodeQL libraries. If that doesn\'t work, then my query queries are not yet available for this language.',
);
});
Expand Down
Loading