Skip to content

Commit

Permalink
Upgrade ESLint to v9 (#29451)
Browse files Browse the repository at this point in the history
Just upgrade convex for now, plan to hit the rest later.

Upgrade ESLint to v9

GitOrigin-RevId: 953103ffa088a685b19e2ef74a714ce381e571de
  • Loading branch information
thomasballinger authored and Convex, Inc. committed Sep 3, 2024
1 parent 466237e commit e0f304e
Show file tree
Hide file tree
Showing 42 changed files with 222 additions and 207 deletions.
86 changes: 0 additions & 86 deletions .eslintrc.cjs

This file was deleted.

176 changes: 176 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// @ts-check

import tseslint from "typescript-eslint";
import reactHooksPlugin from "eslint-plugin-react-hooks";
import reactPlugin from "eslint-plugin-react";
import vitest from "eslint-plugin-vitest";
import { fixupPluginRules } from "@eslint/compat";
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
import eslintConfigPrettier from "eslint-config-prettier";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
{
ignores: [
"**/node_modules",
"**/dist",
"tmpDist*",
"**/tmpPackage*",
"**/custom-vitest-environment.ts",
// TODO use a separate config for files that doesn't use TypeScript
"**/*.js",
"vitest.config.js",
"scripts",
".prettierrc.js",
"eslint.config.mjs",
"jest.config.mjs",
],
},
...compat.plugins("require-extensions"),
...compat.extends("plugin:require-extensions/recommended"),
js.configs.recommended,
{
files: ["**/*.js", "**/*.jsx", "**/*ts", "**/*.tsx"],
plugins: {
"@typescript-eslint": tseslint.plugin,
react: reactPlugin,
"react-hooks": fixupPluginRules(reactHooksPlugin),
vitest,
},

languageOptions: {
globals: {
...globals.amd,
...globals.browser,
...globals.node,
},

parser: tseslint.parser,
ecmaVersion: 2022,
sourceType: "module",

parserOptions: {
project: ["./tsconfig.json"],
tsconfigRootDir: ".",
},
},

rules: {
...reactHooksPlugin.configs.recommended.rules,
"no-debugger": "error",
// any is terrible but we use it a lot (even in our public code).
"@typescript-eslint/no-explicit-any": "off",
// asserting that values aren't null is risky but useful.
"@typescript-eslint/no-non-null-assertion": "off",
// Warn against interpolating objects
"@typescript-eslint/restrict-template-expressions": "error",

"no-redeclare": "off", // breaks for overloads
"@typescript-eslint/no-redeclare": "error",

"no-undef": "off",

// allow (_arg: number) => {}
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],

"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",

// If you add rules here, make sure to add it to subdir eslintrc files as well!
"no-restricted-syntax": [
"error",
{
// From https://github.com/typescript-eslint/typescript-eslint/issues/1391#issuecomment-1124154589
// Prefer `private` ts keyword to `#private` private methods
selector:
":matches(PropertyDefinition, MethodDefinition) > PrivateIdentifier.key",
message: "Use `private` instead",
},
],

// Makes it harder to accidentally fire off a promise without waiting for it.
"@typescript-eslint/no-floating-promises": "error",

// Since `const x = <number>foo;` syntax is ambiguous with JSX syntax some tools don't support it.
// In particular we need this for depcheck https://github.com/depcheck/depcheck/issues/585
"@typescript-eslint/consistent-type-assertions": [
"error",
{
assertionStyle: "as",
},
],

eqeqeq: ["error", "always"],

// vitest (manually enabled until we can upgrade eslint)
"vitest/no-focused-tests": [
"error",
{
fixable: false,
},
],
},
},
{
name: "CLI-specific",
files: ["src/cli/**/*.ts", "src/bundler/**/*.ts"],
ignores: ["**/*.test.ts"],
rules: {
"no-restricted-imports": [
"warn",
{
patterns: [
{
group: ["fs", "node:fs"],
message:
"Use a `Filesystem` implementation like `nodeFs` instead of Node's 'fs' package directly.",
},
{
group: ["fs/promises", "node:fs/promises"],
message:
"Use a `Filesystem` implementation like `nodeFs` instead of Node's 'fs/promises' package directly. Additionally, use synchronous filesystem IO within our CLI.",
},
],
},
],
"no-restricted-syntax": [
"error",
{
selector:
":matches(PropertyDefinition, MethodDefinition) > PrivateIdentifier.key",
message: "Use `private` instead",
},
{
selector: "ThrowStatement",
message:
"Don't use `throw` if this is a developer-facing error message and this code could be called by `npx convex dev`. Instead use `ctx.crash`.",
},
// TODO: fix to allow process.exit(0) but not process.exit(1)
// {
// message: "Use flushAndExit from convex/src/cli/utils.ts instead of process.exit so that Sentry gets flushed.",
// selector: "CallExpression[callee.object.name='process'][callee.property.name='exit'][callee.value=1]"
// }
],
"no-throw-literal": ["error"],
},
},
eslintConfigPrettier,
];
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@
"build": "python3 scripts/build.py 2>&1",
"bundle-server": "node scripts/bundle-server.mjs",
"clean": "shx rm -rf dist tmpDist*",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"lint": "eslint .",
"format": "prettier -w . && eslint --fix .",
"format-check": "prettier -c . && eslint . --ext .js,.jsx,.ts,.tsx",
"format-check": "prettier -c . && eslint .",
"prepare": "npm run build",
"prepack": "node scripts/prepack.mjs",
"postpack": "node scripts/postpack.mjs",
Expand All @@ -164,7 +164,8 @@
"dependencies": {
"esbuild": "0.23.0",
"jwt-decode": "^3.1.2",
"prettier": "3.2.5"
"prettier": "3.2.5",
"globals": "~15.9.0"
},
"peerDependencies": {
"@auth0/auth0-react": "^2.0.1",
Expand Down Expand Up @@ -196,12 +197,16 @@
"@babel/types": "7.24.0",
"@clerk/clerk-react": "4.18.0",
"@commander-js/extra-typings": "^11.1.0",
"@eslint/compat": "~1.1.1",
"@eslint/eslintrc": "~3.1.0",
"@eslint/js": "~9.9.1",
"@sentry/node": "^7.23.0",
"@sentry/tracing": "^7.23.0",
"@swc/core": "1.3.107",
"@testing-library/react": "~14.0.0",
"@types/adm-zip": "^0.5.5",
"@types/deep-equal": "1.0.1",
"@types/detect-port": "~1.3.5",
"@types/http-proxy": "~1.17.9",
"@types/inquirer": "^8.2.0",
"@types/jwt-encode": "~1.0.0",
Expand All @@ -210,8 +215,6 @@
"@types/react-dom": "^18.0.0",
"@types/semver": "^7.3.13",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"adm-zip": "^0.5.10",
"bufferutil": "^4.0.7",
"chalk": "4",
Expand All @@ -226,7 +229,7 @@
"envfile": "6.18.0",
"esbuild": "0.23.0",
"esbuild-plugin-external-global": "~1.0.1",
"eslint": "^8.29.0",
"eslint": "9",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
Expand All @@ -251,12 +254,12 @@
"tsx": "~4.15.6",
"typedoc": "^0.24.6",
"typescript": "~5.0.3",
"typescript-eslint": "~8.4.0",
"utf-8-validate": "^5.0.10",
"vitest": "~1.6.0",
"wait-for-expect": "~3.0.2",
"ws": "8.18.0",
"zod": "^3.21.4",
"@types/detect-port": "~1.3.5"
"zod": "^3.21.4"
},
"engines": {
"npm": ">=7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/browser/sync/authentication_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export class AuthenticationManager {
private decodeToken(token: string) {
try {
return jwtDecode(token);
} catch (e) {
} catch {
return null;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/browser/sync/web_socket_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ export class WebSocketManager {
}
default: {
// Enforce that the switch-case is exhaustive.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _: never = this.socket;
}
}
Expand Down Expand Up @@ -367,7 +366,6 @@ export class WebSocketManager {
}
default: {
// Enforce that the switch-case is exhaustive.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _: never = this.socket;
return Promise.resolve();
}
Expand Down
1 change: 0 additions & 1 deletion src/bundler/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ async function flushAndExit(exitCode: number, err?: any) {
Sentry.captureException(err);
}
await Sentry.close();
// eslint-disable-next-line no-restricted-syntax
return process.exit(exitCode);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bundler/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export async function findExactVersionAndDependencies(
try {
const packageJsonString = ctx.fs.readUtf8File(modulePackageJsonPath);
modulePackageJson = JSON.parse(packageJsonString);
} catch (error: any) {
} catch {
return await ctx.crash({
exitCode: 1,
errorType: "invalid filesystem data",
Expand Down
1 change: 0 additions & 1 deletion src/bundler/fs.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-restricted-syntax */
import { test, expect } from "vitest";
import fs from "fs";
import os from "os";
Expand Down
1 change: 1 addition & 0 deletions src/bundler/fs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Disable our restriction on `throw` because these aren't developer-facing
// error messages.
/* eslint-disable no-restricted-imports */
/* eslint-disable no-restricted-syntax */
import chalk from "chalk";
import stdFs, { Dirent, Mode, ReadStream, Stats } from "fs";
Expand Down
2 changes: 1 addition & 1 deletion src/bundler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async function doEsbuild(
externalModuleNames: external.externalModuleNames,
bundledModuleNames: external.bundledModuleNames,
};
} catch (err) {
} catch {
return await ctx.crash({
exitCode: 1,
errorType: "invalid filesystem data",
Expand Down
Loading

0 comments on commit e0f304e

Please sign in to comment.