Skip to content

Commit 572305f

Browse files
authored
chore: upgrade to ESLint v9 (#573)
* chore: upgrade to eslint v9 * fix tests * fix crash * istanbul * stop testing under Node 16 * temporarily revert peer dep * Revert "temporarily revert peer dep" This reverts commit e86c55e.
1 parent 8c2cccb commit 572305f

32 files changed

+736
-990
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ jobs:
1616
strategy:
1717
matrix:
1818
os: [ ubuntu, windows ]
19-
node-version: [16.x, 18.x, 20.x]
19+
# TODO: We still support Node 16 but can't run ESLint v9 tests with it anymore.
20+
node-version: [18.x, 20.x]
2021

2122
steps:
2223
- uses: actions/checkout@v4

eslint-remote-tester.config.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

3-
const fs = require("node:fs");
4-
const { basename, extname } = require("node:path");
3+
const eslintPluginQunitRecommended = require("./lib/configs/recommended");
54

65
/** @type {import('eslint-remote-tester').Config} */
76
module.exports = {
@@ -33,25 +32,7 @@ module.exports = {
3332
cache: false,
3433

3534
/** ESLint configuration */
36-
eslintrc: {
37-
plugins: ["qunit"],
38-
39-
// Enable all of our rules.
40-
rules: Object.fromEntries(
41-
fs
42-
.readdirSync(`${__dirname}/lib/rules`)
43-
.map(
44-
(filename) =>
45-
`qunit/${basename(filename, extname(filename))}`,
46-
)
47-
.map((ruleName) => [ruleName, "error"]),
48-
),
49-
50-
overrides: [
51-
{
52-
files: ["*.ts", "*.mts", "*.cts"],
53-
parser: "@typescript-eslint/parser",
54-
},
55-
],
35+
eslintConfig: {
36+
...eslintPluginQunitRecommended,
5637
},
5738
};

eslint.config.js

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
"use strict";
22

33
const js = require("@eslint/js");
4-
const { FlatCompat } = require("@eslint/eslintrc");
4+
const eslintPluginEslintComments = require("@eslint-community/eslint-plugin-eslint-comments/configs");
55
const eslintPluginEslintPluginAll = require("eslint-plugin-eslint-plugin/configs/all");
66
const eslintPluginMarkdown = require("eslint-plugin-markdown");
7+
const eslintPluginMocha = require("eslint-plugin-mocha");
8+
const eslintPluginN = require("eslint-plugin-n");
9+
const eslintPluginPrettierRecommended = require("eslint-plugin-prettier/recommended");
10+
const eslintPluginUnicorn = require("eslint-plugin-unicorn");
711
const globals = require("globals");
812

9-
const compat = new FlatCompat({
10-
baseDirectory: __dirname,
11-
recommendedConfig: js.configs.recommended,
12-
});
13-
1413
module.exports = [
15-
...compat.extends(
16-
"plugin:eslint-comments/recommended",
17-
"plugin:node/recommended",
18-
"plugin:prettier/recommended",
19-
"plugin:unicorn/recommended",
20-
),
14+
js.configs.recommended,
2115

16+
eslintPluginEslintComments.recommended,
2217
eslintPluginEslintPluginAll,
18+
eslintPluginN.configs["flat/recommended"],
19+
eslintPluginPrettierRecommended,
20+
eslintPluginUnicorn.configs["flat/recommended"],
2321

24-
// Apply mocha config only to tests.
25-
...compat
26-
.extends("plugin:mocha/recommended")
27-
.map((config) => ({ ...config, files: ["tests/**/*.js"] })),
22+
{
23+
...eslintPluginMocha.configs.flat.recommended,
24+
files: ["tests/**/*.js"],
25+
},
2826

2927
{
3028
languageOptions: {
@@ -136,14 +134,6 @@ module.exports = [
136134
"spaced-comment": ["error", "always", { exceptions: ["-"] }],
137135
strict: ["error", "global"],
138136
"use-isnan": "error",
139-
"valid-jsdoc": [
140-
"error",
141-
{
142-
prefer: {
143-
return: "returns",
144-
},
145-
},
146-
],
147137
"valid-typeof": "error",
148138
yoda: ["error", "never"],
149139

@@ -172,8 +162,8 @@ module.exports = [
172162
],
173163
"eslint-plugin/require-meta-schema-description": "off", // TODO: enable this.
174164

175-
// eslint-plugin-node
176-
"node/no-missing-require": [
165+
// eslint-plugin-n
166+
"n/no-missing-require": [
177167
"error",
178168
{
179169
allowModules: ["@typescript-eslint/parser"],
@@ -207,11 +197,6 @@ module.exports = [
207197
{
208198
// Markdown code samples.
209199
files: ["**/*.md/*.js", "**/*.md/*.javascript"],
210-
languageOptions: {
211-
parserOptions: {
212-
sourceType: "module",
213-
},
214-
},
215200
rules: {
216201
eqeqeq: "off",
217202
"guard-for-in": "off",

lib/rules/no-compare-relation-boolean.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ module.exports = {
8282
messageId: "redundantComparison",
8383
fix(fixer) {
8484
const sourceCode = context.getSourceCode();
85+
/* istanbul ignore next */
86+
if (callExprNode.type !== "CallExpression") {
87+
return null;
88+
}
89+
/* istanbul ignore next */
90+
if (callExprNode.callee.type !== "MemberExpression") {
91+
return null;
92+
}
93+
/* istanbul ignore next */
94+
if (callExprNode.callee.object.type !== "Identifier") {
95+
return null;
96+
}
97+
/* istanbul ignore next */
98+
if (
99+
callExprNode.callee.property.type !== "Identifier"
100+
) {
101+
return null;
102+
}
85103
const assertionVariableName =
86104
callExprNode.callee.object.name;
87105

lib/rules/no-setup-teardown.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ module.exports = {
3535
};
3636

3737
function checkModuleHook(propertyNode) {
38-
if (replacements.hasOwnProperty(propertyNode.key.name)) {
38+
if (
39+
Object.prototype.hasOwnProperty.call(
40+
replacements,
41+
propertyNode.key.name,
42+
)
43+
) {
3944
context.report({
4045
node: propertyNode,
4146
messageId: "noSetupTeardown",

0 commit comments

Comments
 (0)