Fix linting errors resulting from upgrading @typescript-eslint/eslint-plugin to version 8

This commit is contained in:
Robert
2024-08-08 16:17:43 +00:00
parent c90f8056e4
commit b501a04074
30 changed files with 92 additions and 86 deletions

View File

@@ -3,5 +3,14 @@ node_modules/
out/
build/
# Ignore js files
.eslintrc.js
jest.config.js
test/vscode-tests/activated-extension/jest-runner-vscode.config.js
test/vscode-tests/cli-integration/jest-runner-vscode.config.js
test/vscode-tests/jest-runner-vscode.config.base.js
test/vscode-tests/minimal-workspace/jest-runner-vscode.config.js
test/vscode-tests/no-workspace/jest-runner-vscode.config.js
# Include the Storybook config
!.storybook

View File

@@ -45,7 +45,7 @@ const baseConfig = {
"@typescript-eslint/no-invalid-this": "off",
"@typescript-eslint/no-shadow": "off",
"prefer-const": ["warn", { destructuring: "all" }],
"@typescript-eslint/no-throw-literal": "error",
"@typescript-eslint/only-throw-error": "error",
"@typescript-eslint/consistent-type-imports": "error",
"import/consistent-type-specifier-style": ["error", "prefer-top-level"],
curly: ["error", "all"],
@@ -133,18 +133,7 @@ module.exports = {
...baseConfig.rules,
// We want to allow mocking of functions in modules, so we need to allow namespace imports.
"import/no-namespace": "off",
"@typescript-eslint/ban-types": [
"error",
{
// For a full list of the default banned types, see:
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md
extendDefaults: true,
types: {
// Don't complain about the `Function` type in test files. (Default is `true`.)
Function: false,
},
},
],
"@typescript-eslint/no-unsafe-function-type": "off",
},
},
{

View File

@@ -1,5 +1,5 @@
import { src, dest } from "gulp";
// eslint-disable-next-line @typescript-eslint/no-var-requires,import/no-commonjs
// eslint-disable-next-line @typescript-eslint/no-require-imports,import/no-commonjs
const replace = require("gulp-replace");
/** Inject the application insights key into the telemetry file */

View File

@@ -943,7 +943,7 @@ export class CodeQLCliServer implements Disposable {
if (line.startsWith("Enter value for --github-auth-stdin")) {
try {
return await this.app.credentials.getAccessToken();
} catch (e) {
} catch {
// If the user cancels the authentication prompt, we still need to give a value to the CLI.
// By giving a potentially invalid value, the user will just get a 401/403 when they try to access a
// private package and the access token is invalid.

View File

@@ -36,7 +36,7 @@ export async function findLanguage(
void extLogger.log(
"Query language is unsupported. Select language manually.",
);
} catch (e) {
} catch {
void extLogger.log(
"Could not autodetect query language. Select language manually.",
);

View File

@@ -78,7 +78,7 @@ function getNwoOrOwnerFromGitHubUrl(
}
const nwo = `${paths[0]}/${paths[1]}`;
return paths[1] ? nwo : undefined;
} catch (e) {
} catch {
// Ignore the error here, since we catch failures at a higher level.
return;
}

View File

@@ -1,14 +1,14 @@
export type DeepReadonly<T> =
T extends Array<infer R>
? DeepReadonlyArray<R>
: // eslint-disable-next-line @typescript-eslint/ban-types
: // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
T extends Function
? T
: T extends object
? DeepReadonlyObject<T>
: T;
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}
type DeepReadonlyArray<T> = ReadonlyArray<DeepReadonly<T>>;
type DeepReadonlyObject<T> = {
readonly [P in keyof T]: DeepReadonly<T[P]>;

View File

@@ -298,7 +298,7 @@ export class DbConfigStore extends DisposableObject {
let newConfig: DbConfig | undefined = undefined;
try {
newConfig = await readJSON(this.configPath);
} catch (e) {
} catch {
this.configErrors = [
{
kind: DbConfigValidationErrorKind.InvalidJson,
@@ -332,7 +332,7 @@ export class DbConfigStore extends DisposableObject {
let newConfig: DbConfig | undefined = undefined;
try {
newConfig = readJSONSync(this.configPath);
} catch (e) {
} catch {
this.configErrors = [
{
kind: DbConfigValidationErrorKind.InvalidJson,

View File

@@ -454,7 +454,7 @@ export class DatabaseFetcher {
let uri;
try {
uri = Uri.parse(databaseUrl, true);
} catch (e) {
} catch {
throw new Error(`Invalid url: ${databaseUrl}`);
}
@@ -612,7 +612,7 @@ export class DatabaseFetcher {
const obj = JSON.parse(text);
msg =
obj.error || obj.message || obj.reason || JSON.stringify(obj, null, 2);
} catch (e) {
} catch {
msg = text;
}
throw new Error(`${errorMessage}.\n\nReason: ${msg}`);

View File

@@ -231,7 +231,7 @@ export class DatabaseManager extends DisposableObject {
let originStat;
try {
originStat = await stat(originDbYml);
} catch (e) {
} catch {
// if there is an error here, assume that the origin database
// is no longer available. Safely ignore and do not try to re-import.
return false;
@@ -240,7 +240,7 @@ export class DatabaseManager extends DisposableObject {
try {
const importedStat = await stat(importedDbYml);
return originStat.mtimeMs > importedStat.mtimeMs;
} catch (e) {
} catch {
// If either of the files does not exist, we assume the origin is newer.
// This shouldn't happen unless the user manually deleted one of the files.
return true;

View File

@@ -96,7 +96,7 @@ export type Response = DebugProtocol.Response & { type: "response" };
export type InitializeResponse = DebugProtocol.InitializeResponse &
Response & { command: "initialize" };
export interface QuickEvalResponse extends Response {}
export type QuickEvalResponse = Response;
export type AnyResponse = InitializeResponse | QuickEvalResponse;

View File

@@ -31,7 +31,7 @@ export function fileRangeFromURI(
return new Location(db.resolveSourceFile(uri.uri), range);
}
return undefined;
} catch (e) {
} catch {
return undefined;
}
}

View File

@@ -28,7 +28,7 @@ export async function resolveContextualQlPacksForDatabase(
): Promise<QlPacksForLanguage> {
try {
return await qlpackOfDatabase(cli, databaseItem);
} catch (e) {
} catch {
// If we can't find the qlpacks for the database, use the defaults instead
}

View File

@@ -12,7 +12,7 @@ import { languages, IndentAction } from "vscode";
* See https://github.com/microsoft/vscode/blob/master/src/vs/editor/test/common/modes/supports/javascriptOnEnterRules.ts
*/
export function install() {
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const langConfig = require("../../language-configuration.json");
// setLanguageConfiguration requires a regexp for the wordpattern, not a string
langConfig.wordPattern = new RegExp(langConfig.wordPattern);

View File

@@ -133,7 +133,7 @@ async function findGitFolder(
const stat = await workspace.fs.stat(gitFolder);
// Check whether it's a directory
return (stat.type & FileType.Directory) !== 0;
} catch (e) {
} catch {
return false;
}
}),

View File

@@ -845,7 +845,7 @@ export class QueryHistoryManager extends DisposableObject {
evalLogData,
);
this.evalLogViewer.updateRoots(await evalLogTreeBuilder.getRoots());
} catch (e) {
} catch {
throw new Error(
`Could not read evaluator log summary JSON file to generate viewer data at ${item.jsonEvalLogSummaryLocation}.`,
);

View File

@@ -61,7 +61,7 @@ export class TestRunner extends DisposableObject {
})) {
await eventHandler(event);
}
} catch (e) {
} catch {
// CodeQL testing can throw exception even in normal scenarios. For example, if the test run
// produces no output (which is normal), the testing command would throw an exception on
// unexpected EOF during json parsing. So nothing needs to be done here - all the relevant

View File

@@ -607,7 +607,7 @@ export async function logEndSummary(
const endSummaryContent = await readFile(endSummary, "utf-8");
void logger.log(" --- Evaluator Log Summary --- ");
void logger.log(endSummaryContent);
} catch (e) {
} catch {
void showAndLogWarningMessage(
extLogger,
`Could not read structured evaluator log end of summary file at ${endSummary}.`,

View File

@@ -26,7 +26,7 @@ export async function readRepoStates(
const repoStates = mapRepoStatesToDomainModel(repoStatesData);
return repoStates;
} catch (e) {
} catch {
// Ignore this error, we simply might not have downloaded anything yet
return undefined;
}

View File

@@ -562,7 +562,7 @@ export class VariantAnalysisManager
});
const doc = await workspace.openTextDocument(uri);
await Window.showTextDocument(doc, { preview: false });
} catch (error) {
} catch {
void showAndLogWarningMessage(
this.app.logger,
"Could not open variant analysis query text. Failed to open text document.",
@@ -586,7 +586,7 @@ export class VariantAnalysisManager
variantAnalysis.query.filePath,
);
await Window.showTextDocument(textDocument, ViewColumn.One);
} catch (error) {
} catch {
void showAndLogWarningMessage(
this.app.logger,
`Could not open file: ${variantAnalysis.query.filePath}`,

View File

@@ -64,7 +64,18 @@ type Props = {
export const SuggestBoxItem = forwardRef<
HTMLDivElement,
Props & HTMLProps<HTMLDivElement>
>(({ children, active, icon, labelText, details, ...props }, ref) => {
>(
(
{
children,
active,
icon,
labelText,
details,
...props
}: Props & HTMLProps<HTMLDivElement>,
ref,
) => {
const id = useId();
return (
<Container
@@ -82,5 +93,6 @@ export const SuggestBoxItem = forwardRef<
</LabelContainer>
</Container>
);
});
},
);
SuggestBoxItem.displayName = "SuggestBoxItem";

View File

@@ -116,7 +116,7 @@ export const MethodRow = (props: MethodRowProps) => {
};
const ModelableMethodRow = forwardRef<HTMLElement | undefined, MethodRowProps>(
(props, ref) => {
(props: MethodRowProps, ref) => {
const {
method,
modeledMethods: modeledMethodsProp,
@@ -412,7 +412,7 @@ ModelableMethodRow.displayName = "ModelableMethodRow";
const UnmodelableMethodRow = forwardRef<
HTMLElement | undefined,
MethodRowProps
>((props, ref) => {
>((props: MethodRowProps, ref) => {
const { method, viewState, revealedMethodSignature } = props;
const jumpToMethod = useCallback(

View File

@@ -124,9 +124,11 @@ export function ResultTables(props: ResultTablesProps) {
(evt: MessageEvent): void => {
// sanitize origin
const origin = evt.origin.replace(/\n|\r/g, "");
evt.origin === window.origin
? handleMessage(evt.data as IntoResultsViewMsg)
: console.error(`Invalid event origin ${origin}`);
if (evt.origin === window.origin) {
handleMessage(evt.data as IntoResultsViewMsg);
} else {
console.error(`Invalid event origin ${origin}`);
}
},
[handleMessage],
);

View File

@@ -193,9 +193,11 @@ export function ResultsApp() {
(evt: MessageEvent) => {
// sanitize origin
const origin = evt.origin.replace(/\n|\r/g, "");
evt.origin === window.origin
? handleMessage(evt.data as IntoResultsViewMsg)
: console.error(`Invalid event origin ${origin}`);
if (evt.origin === window.origin) {
handleMessage(evt.data as IntoResultsViewMsg);
} else {
console.error(`Invalid event origin ${origin}`);
}
},
[handleMessage],
);

View File

@@ -50,7 +50,7 @@ describe("OutputChannelLogger tests", function () {
tempFolders.storagePath.removeCallback();
});
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const mockOutputChannel = require("vscode").mockOutputChannel;
it("should log to the output channel", async () => {

View File

@@ -15,15 +15,11 @@ describe("CommandManager", () => {
});
it("can register typed commands", async () => {
const commands = {
"codeQL.openVariantAnalysisLogs": async (variantAnalysisId: number) => {
return variantAnalysisId * 10;
},
};
const commandManager = new CommandManager<typeof commands>(
jest.fn(),
jest.fn(),
);
const commandManager = new CommandManager<{
"codeQL.openVariantAnalysisLogs": (
variantAnalysisId: number,
) => Promise<number>;
}>(jest.fn(), jest.fn());
// @ts-expect-error wrong command name should give a type error
commandManager.register("abc", jest.fn());
@@ -81,15 +77,11 @@ describe("CommandManager", () => {
});
it("can execute typed commands", async () => {
const commands = {
"codeQL.openVariantAnalysisLogs": async (variantAnalysisId: number) => {
return variantAnalysisId * 10;
},
};
const commandManager = new CommandManager<typeof commands>(
jest.fn(),
jest.fn(),
);
const commandManager = new CommandManager<{
"codeQL.openVariantAnalysisLogs": (
variantAnalysisId: number,
) => Promise<number>;
}>(jest.fn(), jest.fn());
// @ts-expect-error wrong command name should give a type error
await commandManager.execute("abc", 4);

View File

@@ -278,7 +278,7 @@ describeWithCodeQL()("Queries", () => {
function safeDel(file: string) {
try {
unlinkSync(file);
} catch (e) {
} catch {
// ignore
}
}

View File

@@ -140,7 +140,7 @@ describe("runModelEditorQueries", () => {
const result = await runModelEditorQueries(Mode.Framework, options);
expect(result).not.toBeUndefined;
expect(result).not.toBeUndefined();
expect(options.cliServer.resolveQlpacks).toHaveBeenCalledTimes(1);
expect(options.cliServer.resolveQlpacks).toHaveBeenCalledWith([], true);

View File

@@ -200,7 +200,7 @@ describe("runSuggestionsQuery", () => {
const result = await runSuggestionsQuery(Mode.Framework, options);
expect(result).not.toBeUndefined;
expect(result).not.toBeUndefined();
expect(options.cliServer.resolveQlpacks).toHaveBeenCalledTimes(1);
expect(options.cliServer.resolveQlpacks).toHaveBeenCalledWith([], true);

View File

@@ -408,7 +408,7 @@ describe("query-results", () => {
function safeDel(file: string) {
try {
unlinkSync(file);
} catch (e) {
} catch {
// ignore
}
}