Skip to content

Commit a77f189

Browse files
authored
Migrate to ESLint flat config (#2145)
* Migrate to ESLint flat config * Merge configuration files * Comment out unreachable disabled code * Fix parameters
1 parent 07b06f4 commit a77f189

File tree

17 files changed

+246
-171
lines changed

17 files changed

+246
-171
lines changed

.eslintignore

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

.eslintrc.json

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

eslint.config.js

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
2+
import preferArrow from "eslint-plugin-prefer-arrow";
3+
import unicorn from "eslint-plugin-unicorn";
4+
import globals from "globals";
5+
import tsParser from "@typescript-eslint/parser";
6+
import path from "node:path";
7+
import {fileURLToPath} from "node:url";
8+
import js from "@eslint/js";
9+
import {FlatCompat} from "@eslint/eslintrc";
10+
11+
const __filename = fileURLToPath(import.meta.url);
12+
const __dirname = path.dirname(__filename);
13+
const compat = new FlatCompat({
14+
baseDirectory: __dirname,
15+
recommendedConfig: js.configs.recommended,
16+
allConfig: js.configs.all,
17+
});
18+
const staticCompat = new FlatCompat({
19+
baseDirectory: __dirname + "/static",
20+
recommendedConfig: js.configs.recommended,
21+
allConfig: js.configs.all,
22+
});
23+
24+
export default [
25+
{
26+
ignores: [
27+
"**/coverage/",
28+
"**/generated/",
29+
"**/browser-compat-data/",
30+
"**/es-scraper/",
31+
"**/static/",
32+
],
33+
},
34+
...compat.extends(
35+
"eslint:recommended",
36+
"plugin:@typescript-eslint/strict",
37+
"plugin:@typescript-eslint/stylistic",
38+
"plugin:jsdoc/recommended-typescript",
39+
),
40+
...staticCompat.extends("eslint:recommended", "plugin:jsdoc/recommended"),
41+
{
42+
files: ["**/*.ts", "**/eslint.config.js"],
43+
plugins: {
44+
"@typescript-eslint": typescriptEslint,
45+
"prefer-arrow": preferArrow,
46+
// jsdoc,
47+
unicorn,
48+
},
49+
50+
languageOptions: {
51+
globals: {
52+
...globals.mocha,
53+
...globals.node,
54+
},
55+
56+
parser: tsParser,
57+
ecmaVersion: 2022,
58+
sourceType: "module",
59+
},
60+
61+
rules: {
62+
curly: ["error", "all"],
63+
"max-len": "off",
64+
indent: "off",
65+
"jsdoc/check-param-names": "error",
66+
"jsdoc/require-description": "warn",
67+
68+
"jsdoc/require-jsdoc": [
69+
"warn",
70+
{
71+
require: {
72+
ArrowFunctionExpression: true,
73+
ClassDeclaration: true,
74+
ClassExpression: true,
75+
FunctionDeclaration: true,
76+
FunctionExpression: true,
77+
MethodDefinition: true,
78+
},
79+
},
80+
],
81+
82+
"jsdoc/require-param-type": "off",
83+
"jsdoc/require-returns": "error",
84+
"jsdoc/require-returns-type": "off",
85+
"jsdoc/no-undefined-types": "error",
86+
"jsdoc/require-yields": "error",
87+
"no-else-return": "error",
88+
"no-unused-vars": "off",
89+
"prefer-arrow/prefer-arrow-functions": "error",
90+
quotes: "off",
91+
"quote-props": ["error", "as-needed"],
92+
"require-jsdoc": "off",
93+
"space-before-function-paren": "off",
94+
"unicorn/prefer-node-protocol": "error",
95+
96+
"@typescript-eslint/no-unused-vars": [
97+
"error",
98+
{
99+
caughtErrors: "none",
100+
},
101+
],
102+
103+
"@typescript-eslint/no-explicit-any": "off",
104+
"@typescript-eslint/no-empty-function": "off",
105+
},
106+
},
107+
{
108+
files: ["**/static/**"],
109+
languageOptions: {
110+
ecmaVersion: 3,
111+
sourceType: "script",
112+
globals: {
113+
...globals.browser,
114+
JSON: "readonly",
115+
Promise: "readonly",
116+
},
117+
},
118+
119+
rules: {
120+
"comma-dangle": ["error", "never"],
121+
curly: ["error", "all"],
122+
"guard-for-in": "off",
123+
indent: "off",
124+
"max-len": "off",
125+
"no-invalid-this": "off",
126+
127+
"no-unused-vars": [
128+
"error",
129+
{
130+
caughtErrors: "none",
131+
},
132+
],
133+
134+
"no-var": "off",
135+
"prefer-arrow/prefer-arrow-functions": "off",
136+
quotes: "off",
137+
"require-jsdoc": "off",
138+
"space-before-function-paren": "off",
139+
"jsdoc/check-param-names": "error",
140+
"jsdoc/require-description": "warn",
141+
142+
"jsdoc/require-jsdoc": [
143+
"warn",
144+
{
145+
require: {
146+
ArrowFunctionExpression: true,
147+
ClassDeclaration: true,
148+
ClassExpression: true,
149+
FunctionDeclaration: true,
150+
FunctionExpression: true,
151+
MethodDefinition: true,
152+
},
153+
},
154+
],
155+
156+
"jsdoc/require-param-type": "error",
157+
"jsdoc/require-returns": "error",
158+
"jsdoc/require-returns-type": "off",
159+
"jsdoc/no-undefined-types": "error",
160+
"jsdoc/require-yields": "error",
161+
},
162+
},
163+
{
164+
files: ["**/static/unittest/**.js"],
165+
languageOptions: {
166+
ecmaVersion: 2022,
167+
globals: {
168+
...globals.browser,
169+
...globals.mocha,
170+
},
171+
},
172+
},
173+
{
174+
files: [
175+
"**/static/resources/custom-tests/api/AudioWorkletNode/WhiteNoiseProcessor.js",
176+
],
177+
languageOptions: {
178+
ecmaVersion: 6,
179+
},
180+
},
181+
];

lib/exporter.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ describe("GitHub export", () => {
8585
const octokit = new Octokit();
8686

8787
describe("happy path", () => {
88-
// eslint-disable-next-line guard-for-in
8988
for (const i in REPORTS) {
9089
// XXX Mocking GitHub is currently broken since
9190
// @octokit/plugin-rest-endpoint-methods 8.0.0...

lib/exporter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const getReportMeta = (report: Report): ReportMeta => {
2828
const json = stringify(report) as string;
2929
const buffer = Buffer.from(json);
3030

31-
/* eslint-disable-next-line max-len */
3231
// like https://github.com/web-platform-tests/wpt.fyi/blob/26805a0122ea01076ac22c0a96313c1cf5cc30d6/results-processor/wptreport.py#L79
3332
const digest = crypto
3433
.createHash("sha1")

package-lock.json

Lines changed: 28 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
},
1717
"scripts": {
1818
"prepare": "tsx prepare.ts",
19-
"format": "ESLINT_USE_FLAT_CONFIG=false eslint . && prettier -c \"**/*.ts\" \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.scss\" \"**/*.yaml\" --color && ejslint views/*",
20-
"format:fix": "ESLINT_USE_FLAT_CONFIG=false eslint --fix . && prettier --write \"**/*.ts\" \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.scss\" \"**/*.yaml\"",
19+
"format": "eslint . && prettier -c \"**/*.ts\" \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.scss\" \"**/*.yaml\" --color && ejslint views/*",
20+
"format:fix": "eslint --fix . && prettier --write \"**/*.ts\" \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/*.scss\" \"**/*.yaml\"",
2121
"fix": "npm run format:fix",
2222
"clean": "rm -rf .nyc_output coverage generated tests.json",
2323
"build": "npm run build:compile && npm run build:tests && npm run build:resources",
@@ -82,6 +82,8 @@
8282
"@browser-logos/firefox": "3.0.10",
8383
"@browser-logos/opera": "1.1.11",
8484
"@browser-logos/safari": "2.1.0",
85+
"@eslint/eslintrc": "^3.2.0",
86+
"@eslint/js": "^9.20.0",
8587
"@listr2/prompt-adapter-enquirer": "^2.0.12",
8688
"@swc/cli": "^0.6.0",
8789
"@swc/helpers": "^0.5.15",
@@ -119,6 +121,7 @@
119121
"eslint-plugin-unicorn": "^56.0.1",
120122
"fdir": "6.4.3",
121123
"foreman": "^3.0.1",
124+
"globals": "^15.15.0",
122125
"json3": "3.3.3",
123126
"jsonc-parser": "^3.3.1",
124127
"listr2": "8.2.5",

0 commit comments

Comments
 (0)