Skip to content

Convert to eslint 9 #4056

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Convert to eslint 9 #4056

wants to merge 17 commits into from

Conversation

robertbrignull
Copy link
Contributor

@robertbrignull robertbrignull commented Jun 18, 2025

Upgrades eslint to version 9, as well as upgrading a few plugins.

I've tried to convert the old config as closely as I could, but I've removed a few plugins that weren't working well because they haven't received updates in a couple of years. It's also very possible I've misunderstood bits of the config!

I can now run npm run lint locally and hopefully it'll pass in CI too. I have fixed a few rules where it was simple or obvious to do, but for most rules I have disabled them as there were thousands of errors. After this is merged we'll want a secondary effort to try to re-enable rules as much as feasible.

I've tried to keep the list of commits as clear and understandable as possible, so hopefully you can review this commit-by-commit.

@robertbrignull robertbrignull requested review from a team and Copilot June 18, 2025 16:24
@robertbrignull robertbrignull requested a review from a team as a code owner June 18, 2025 16:24
Copilot

This comment was marked as outdated.

@robertbrignull robertbrignull force-pushed the robertbrignull/eslint-9 branch from 76dfe00 to d77537a Compare August 4, 2025 15:46
@Copilot Copilot AI review requested due to automatic review settings August 4, 2025 15:59
Copilot

This comment was marked as outdated.

@Copilot Copilot AI review requested due to automatic review settings August 4, 2025 16:13
@robertbrignull robertbrignull force-pushed the robertbrignull/eslint-9 branch from f568822 to 195c7e0 Compare August 4, 2025 16:13
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR upgrades ESLint from version 8 to version 9, along with updating several related plugins. The upgrade involves transitioning from the legacy .eslintrc.js configuration format to the new flat config format in eslint.config.mjs. Many lint rules have been temporarily disabled to address thousands of errors, with the plan to re-enable them incrementally in future work.

  • Replaces legacy ESLint configuration with flat config format
  • Updates ESLint plugins and removes outdated ones
  • Removes unnecessary non-null assertions and type casts throughout the codebase
  • Cleans up disabled ESLint comments that are no longer needed

Reviewed Changes

Copilot reviewed 39 out of 41 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
package.json Updates ESLint and plugin versions, removes outdated plugins
eslint.config.mjs New flat config replacing old .eslintrc.js with updated rule configurations
.eslintrc.js Removed legacy ESLint configuration file
.eslintignore Removed in favor of global ignores in flat config
Multiple source files Removes unnecessary non-null assertions and type casts flagged by new rules

@@ -73,6 +73,7 @@ async function readRequestFiles(
) {
request.response.body = await readFile(
join(scenarioDirPath, request.response.body.substring(5)),
"utf8",
);
Copy link
Preview

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The readFile function is being called with an explicit encoding parameter "utf8", but the function signature and context suggest this might be reading binary data. Consider verifying that UTF-8 encoding is appropriate for all file types being read here, or handle encoding based on file type.

Suggested change
);
const filePathToRead = join(scenarioDirPath, request.response.body.substring(5));
const fileBuffer = await readFile(filePathToRead);
// Convert to string only for text files
if (filePathToRead.endsWith(".txt") || filePathToRead.endsWith(".json")) {
request.response.body = fileBuffer.toString("utf8");
} else {
request.response.body = fileBuffer;
}

Copilot uses AI. Check for mistakes.

@@ -15,7 +15,7 @@ import { dbSchemeToLanguage } from "../common/query-language";
*/
export function getInitialQueryContents(language: string, dbscheme: string) {
if (!language) {
const dbschemeBase = basename(dbscheme) as keyof typeof dbSchemeToLanguage;
const dbschemeBase = basename(dbscheme);
language = dbSchemeToLanguage[dbschemeBase];
Copy link
Preview

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

Removing the type assertion as keyof typeof dbSchemeToLanguage could cause a runtime error if dbschemeBase is not a valid key in the dbSchemeToLanguage object. The indexing operation may return undefined, which could lead to unexpected behavior.

Suggested change
language = dbSchemeToLanguage[dbschemeBase];
if (dbschemeBase in dbSchemeToLanguage) {
language = dbSchemeToLanguage[dbschemeBase];
}

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could cause a runtime error

I think the code being removed is entirely compile-time, so I'm going to ignore this copilot suggestion about runtime errors.

@@ -17,7 +17,7 @@ class MockMemento<T> implements Memento {

public get<T>(key: string): T | undefined;
public get<T>(key: string, defaultValue: T): T;
public get(key: any, defaultValue?: any): T | T | undefined {
public get(key: any, defaultValue?: any): T | undefined {
return this.map.get(key) || defaultValue;
Copy link
Preview

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The return type should be T | undefined when no default value is provided, or T when a default value is provided. The current signature removes the overload distinction that was present in the original interface, potentially breaking type safety.

Suggested change
return this.map.get(key) || defaultValue;
public get<T>(key: string, defaultValue?: T): T | undefined {
if (this.map.has(key)) {
return this.map.get(key) as T;
}
if (defaultValue !== undefined) {
return defaultValue;
}
return undefined;

Copilot uses AI. Check for mistakes.

@robertbrignull robertbrignull force-pushed the robertbrignull/eslint-9 branch from 6089c83 to 320df4d Compare August 4, 2025 16:40
Copy link
Member

@koesie10 koesie10 left a comment

Choose a reason for hiding this comment

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

It makes sense to me to fix the other ESLint violations in follow-up PRs. These changes look good to me, my main concern is regarding the request handler where I don't think we should be reading the file as UTF-8.

@@ -73,6 +73,7 @@ async function readRequestFiles(
) {
request.response.body = await readFile(
join(scenarioDirPath, request.response.body.substring(5)),
"utf8",
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is equivalent/correct. All scenarios that have a file: response body have a ZIP file as their response and should not be decoded as UTF-8, but should be returned as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry. I thought this was textual data. I can revert this bit and find another way around the type issues.

disposable.reveal
(disposable as any).onDidExpandElement &&
(disposable as any).onDidCollapseElement &&
(disposable as any).reveal
) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this suggestion from Copilot makes sense, assuming the in checks are also true for an actual TreeViewer.

Co-authored-by: Koen Vlaswinkel <koesie10@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants