Skip to content

Commit e598c3b

Browse files
authored
chore: migrate to ESLint v9 and Flat Config (#1753)
Upgraded eslint to v9 and replaced the legacy .eslintrc.js with the new eslint.config.js format. Applied minor fixes to 4 files (renaming unused catch variables to _e and one small refactor) to satisfy slightly stricter baseline rules from updated plugins. Mostly doing this due to our upgrade in TS to latest v5 version which the old versions of eslint ts plugins no longer support.
1 parent dece9a9 commit e598c3b

File tree

9 files changed

+783
-593
lines changed

9 files changed

+783
-593
lines changed

.eslintignore

Lines changed: 0 additions & 12 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

eslint.config.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
const { FlatCompat } = require("@eslint/eslintrc");
2+
const js = require("@eslint/js");
3+
const path = require("path");
4+
5+
const compat = new FlatCompat({
6+
baseDirectory: __dirname,
7+
recommendedConfig: js.configs.recommended,
8+
allConfig: js.configs.all
9+
});
10+
11+
module.exports = [
12+
{
13+
ignores: [
14+
"lib/",
15+
"dev/",
16+
"node_modules/",
17+
"coverage/",
18+
"docgen/",
19+
"v1/",
20+
"v2/",
21+
"logger/",
22+
"dist/",
23+
"spec/fixtures/",
24+
"scripts/**/*.js",
25+
"protos/",
26+
".prettierrc.js",
27+
"eslint.config.js",
28+
"scripts/bin-test/sources/esm-ext/index.mjs",
29+
],
30+
},
31+
...compat.extends(
32+
"eslint:recommended",
33+
"plugin:@typescript-eslint/recommended",
34+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
35+
"plugin:jsdoc/recommended",
36+
"google",
37+
"prettier"
38+
),
39+
{
40+
languageOptions: {
41+
parser: require("@typescript-eslint/parser"),
42+
parserOptions: {
43+
project: "tsconfig.json",
44+
tsconfigRootDir: __dirname,
45+
},
46+
ecmaVersion: 2022
47+
},
48+
plugins: {
49+
"prettier": require("eslint-plugin-prettier"),
50+
},
51+
rules: {
52+
"jsdoc/newline-after-description": "off",
53+
"jsdoc/require-jsdoc": ["warn", { publicOnly: true }],
54+
"jsdoc/check-tag-names": ["warn", { definedTags: ["alpha", "remarks", "typeParam", "packageDocumentation", "hidden"] }],
55+
"no-restricted-globals": ["error", "name", "length"],
56+
"prefer-arrow-callback": "error",
57+
"prettier/prettier": "off",
58+
"require-atomic-updates": "off", // This rule is so noisy and isn't useful: https://github.com/eslint/eslint/issues/11899
59+
"require-jsdoc": "off", // This rule is deprecated and superseded by jsdoc/require-jsdoc.
60+
"valid-jsdoc": "off", // This is deprecated but included in recommended configs.
61+
"no-prototype-builtins": "warn",
62+
"no-useless-escape": "warn",
63+
"prefer-promise-reject-errors": "warn",
64+
},
65+
},
66+
{
67+
files: ["**/*.ts"],
68+
rules: {
69+
"jsdoc/require-param-type": "off",
70+
"jsdoc/require-returns-type": "off",
71+
// Google style guide allows us to omit trivial parameters and returns
72+
"jsdoc/require-param": "off",
73+
"jsdoc/require-returns": "off",
74+
75+
"@typescript-eslint/no-invalid-this": "error",
76+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_" }], // Unused vars should not exist.
77+
"@typescript-eslint/no-misused-promises": "warn", // rule does not work with async handlers for express.
78+
"no-invalid-this": "off", // Turned off in favor of @typescript-eslint/no-invalid-this.
79+
"no-unused-vars": "off", // Off in favor of @typescript-eslint/no-unused-vars.
80+
eqeqeq: ["error", "always", { null: "ignore" }],
81+
camelcase: ["error", { properties: "never" }], // snake_case allowed in properties iif to satisfy an external contract / style
82+
83+
// Ideally, all these warning should be error - let's fix them in the future.
84+
"@typescript-eslint/no-unsafe-argument": "warn",
85+
"@typescript-eslint/no-unsafe-assignment": "warn",
86+
"@typescript-eslint/no-unsafe-call": "warn",
87+
"@typescript-eslint/no-unsafe-member-access": "warn",
88+
"@typescript-eslint/no-unsafe-return": "warn",
89+
"@typescript-eslint/restrict-template-expressions": "warn",
90+
"@typescript-eslint/no-explicit-any": "warn",
91+
"@typescript-eslint/no-redundant-type-constituents": "warn",
92+
"@typescript-eslint/no-base-to-string": "warn",
93+
"@typescript-eslint/no-duplicate-type-constituents": "warn",
94+
"@typescript-eslint/no-require-imports": "warn",
95+
"@typescript-eslint/no-empty-object-type": "warn",
96+
"@typescript-eslint/prefer-promise-reject-errors": "warn",
97+
},
98+
},
99+
{
100+
files: ["**/*.spec.ts", "**/*.spec.js", "spec/helper.ts", "scripts/bin-test/**/*.ts", "integration_test/**/*.ts"],
101+
languageOptions: {
102+
globals: {
103+
mocha: true,
104+
},
105+
},
106+
rules: {
107+
"@typescript-eslint/no-unused-expressions": "off",
108+
}
109+
},
110+
];

integration_test/functions/src/v1/pubsub-tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export const pubsubTests: any = functions
1313
let testId: string;
1414
try {
1515
testId = m.json.testId;
16-
} catch (e) {
17-
/* Ignored. Covered in another test case that `event.data.json` works. */
16+
} catch (_e) {
17+
// Ignored. Covered in another test case that `event.data.json` works.
1818
}
1919

2020
return new TestSuite<PubsubMessage>("pubsub onPublish")

0 commit comments

Comments
 (0)