Skip to content

Commit 15f435f

Browse files
authored
Upgrade to ESLint 9 (#2481)
2 parents 37ff807 + 96e90eb commit 15f435f

File tree

44 files changed

+954
-492
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+954
-492
lines changed

.changeset/chilly-windows-like.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-graphile-export": patch
3+
---
4+
5+
🚨 Now uses a flat config for compatibility with ESLint v9.

.github/workflows/lint.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ jobs:
2424
cache: "yarn"
2525

2626
- run: yarn --immutable
27-
- name: Compile eslint-plugin-graphile-export
28-
run: yarn workspaces foreach --parallel --topological --recursive --from eslint-plugin-graphile-export run prepack
27+
28+
- name: "Build"
29+
run: yarn build
30+
31+
- name: "Prepack"
32+
run: yarn workspaces foreach --parallel --topological --all run prepack
2933

3034
- name: "Lint Code"
3135
run: yarn eslint .

.lintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ node_modules/
77
/postgraphile/postgraphile/assets/
88
/postgraphile/postgraphile/src/assets/
99
/postgraphile/postgraphile/exported-schema.js
10+
/postgraphile/postgraphile/exported-schema.mjs
1011
/postgraphile/postgraphile/exported-schema.webpacked.js
1112
/grafast/ruru/bundle/ruru.min.js
1213
/grafast/ruru/bundle/ruru.min.js.LICENSE.txt

.eslintrc.js renamed to eslint.config.mjs

Lines changed: 129 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,76 @@
1-
module.exports = {
2-
parser: "@babel/eslint-parser",
3-
parserOptions: {
1+
// @ts-check
2+
import babelParser from "@babel/eslint-parser";
3+
import js from "@eslint/js";
4+
import tsParser from "@typescript-eslint/parser";
5+
import { defineConfig, globalIgnores } from "eslint/config";
6+
import prettier from "eslint-config-prettier";
7+
import graphileExport from "eslint-plugin-graphile-export";
8+
import graphql from "eslint-plugin-graphql";
9+
import importPlugin from "eslint-plugin-import";
10+
import jest from "eslint-plugin-jest";
11+
import react from "eslint-plugin-react";
12+
import reactHooks from "eslint-plugin-react-hooks";
13+
import simpleImportSort from "eslint-plugin-simple-import-sort";
14+
import tsdoc from "eslint-plugin-tsdoc";
15+
import fs from "fs";
16+
import globals from "globals";
17+
import path from "path";
18+
import tseslint from "typescript-eslint";
19+
20+
const __dirname = import.meta.dirname;
21+
22+
const globalIgnoresFromFile = fs
23+
.readFileSync(path.resolve(__dirname, ".lintignore"), "utf8")
24+
.split("\n")
25+
.map((line) => line.trim())
26+
.filter((line) => line && !line.startsWith("#"))
27+
.map((line) => {
28+
let text = line;
29+
text = text.startsWith("/") ? text.substring(1) : `**/${text}`;
30+
text = text.endsWith("/") ? text + "**" : text;
31+
return text;
32+
});
33+
34+
/** @type {import('@eslint/config-helpers').ConfigWithExtends} */
35+
const config = {
36+
linterOptions: {
37+
reportUnusedDisableDirectives: false,
38+
},
39+
languageOptions: {
40+
parser: babelParser,
441
sourceType: "module",
5-
ecmaFeatures: {
6-
jsx: true,
42+
43+
parserOptions: {
44+
ecmaFeatures: {
45+
jsx: true,
46+
},
47+
},
48+
49+
globals: {
50+
jasmine: false,
51+
...globals.jest,
52+
...globals.node,
753
},
854
},
9-
globals: {
10-
jasmine: false,
11-
},
12-
env: {
13-
jest: true,
14-
node: true,
15-
es6: true,
16-
},
55+
1756
settings: {
1857
react: {
1958
version: "detect",
2059
},
60+
"import/resolver": {
61+
node: true,
62+
typescript: true,
63+
},
64+
},
65+
66+
plugins: {
67+
jest,
68+
graphql,
69+
tsdoc,
70+
"simple-import-sort": simpleImportSort,
71+
react,
72+
"react-hooks": reactHooks,
2173
},
22-
extends: [
23-
"eslint:recommended",
24-
"plugin:@typescript-eslint/eslint-recommended",
25-
"plugin:@typescript-eslint/recommended",
26-
//'plugin:@typescript-eslint/recommended-requiring-type-checking',
27-
"plugin:import/errors",
28-
"plugin:import/typescript",
29-
"plugin:graphile-export/recommended",
30-
"prettier",
31-
],
32-
plugins: [
33-
"jest",
34-
"graphql",
35-
"tsdoc",
36-
"simple-import-sort",
37-
"import",
38-
"graphile-export",
39-
"react-hooks",
40-
],
4174

4275
rules: {
4376
"@typescript-eslint/ban-ts-comment": "off",
@@ -49,7 +82,8 @@ module.exports = {
4982
"@typescript-eslint/no-namespace": "off",
5083
"@typescript-eslint/no-use-before-define": "off",
5184
"@typescript-eslint/no-var-requires": "off",
52-
"@typescript-eslint/consistent-type-imports": "error",
85+
// This needs full type-checking now (apparently?)
86+
"@typescript-eslint/consistent-type-imports": "off",
5387
"no-confusing-arrow": 0,
5488
"no-else-return": 0,
5589
"no-underscore-dangle": 0,
@@ -58,6 +92,10 @@ module.exports = {
5892
"jest/no-focused-tests": 2,
5993
"jest/no-identical-title": 2,
6094
"tsdoc/syntax": 2,
95+
"@typescript-eslint/no-empty-object-type": [
96+
"error",
97+
{ allowInterfaces: "always" },
98+
],
6199

62100
// Rules that we should enable:
63101
"@typescript-eslint/no-inferrable-types": "warn",
@@ -71,6 +109,7 @@ module.exports = {
71109
{
72110
argsIgnorePattern: "^_",
73111
varsIgnorePattern: "^_",
112+
caughtErrors: "none",
74113
args: "after-used",
75114
ignoreRestSiblings: true,
76115
},
@@ -85,7 +124,12 @@ module.exports = {
85124
"sort-imports": "off",
86125
"import/order": "off",
87126

88-
"import/extensions": ["error", "ignorePackages"],
127+
"import/extensions": [
128+
"error",
129+
"ignorePackages",
130+
// TODO: fix this properly, rather than turning off 'ts'/'tsx'
131+
{ ts: "never", tsx: "never" },
132+
],
89133
"import/no-deprecated": "warn",
90134

91135
// Apply has been more optimised than spread, use whatever feels right.
@@ -95,6 +139,15 @@ module.exports = {
95139
"no-duplicate-imports": "off",
96140
"import/no-duplicates": "error",
97141
},
142+
};
143+
144+
/**
145+
* This object only exists to make our new eslint.config.js look more like the
146+
* old .eslintrc.js
147+
*
148+
* @type {{overrides: ReadonlyArray<import('@eslint/config-helpers').ConfigWithExtends>}}
149+
*/
150+
const oldConfig = {
98151
overrides: [
99152
// Rules for core plugins
100153
{
@@ -154,8 +207,12 @@ module.exports = {
154207

155208
// Rules for TypeScript only
156209
{
157-
files: ["*.ts", "*.tsx"],
158-
parser: "@typescript-eslint/parser",
210+
files: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.mtsx"],
211+
212+
languageOptions: {
213+
parser: tsParser,
214+
},
215+
159216
rules: {
160217
"no-dupe-class-members": "off",
161218
"no-undef": "off",
@@ -166,21 +223,26 @@ module.exports = {
166223

167224
// Rules for JavaScript only
168225
{
169-
files: ["*.js", "*.jsx", "*.mjs", "*.cjs"],
226+
files: ["**/*.js", "**/*.jsx", "**/*.mjs", "**/*.cjs"],
170227
rules: {
171228
"tsdoc/syntax": "off",
172229
"import/extensions": "off",
230+
"@typescript-eslint/no-require-imports": "off",
173231
},
174232
},
175233

176234
// Stricter rules for source code
177235
{
178236
files: ["*/*/src/**/*.ts", "*/*/src/**/*.tsx"],
179-
parser: "@typescript-eslint/parser",
180-
parserOptions: {
181-
project: true,
237+
languageOptions: {
238+
parser: tsParser,
239+
parserOptions: {
240+
project: true,
241+
},
242+
},
243+
rules: {
244+
"@typescript-eslint/consistent-type-imports": "error",
182245
},
183-
rules: {},
184246
},
185247

186248
// Rules for tests only
@@ -190,6 +252,7 @@ module.exports = {
190252
// Disable these to enable faster test writing
191253
"prefer-const": "off",
192254
"@typescript-eslint/no-explicit-any": "off",
255+
"@typescript-eslint/no-unused-expressions": "off",
193256
"@typescript-eslint/no-unused-vars": "off",
194257
"@typescript-eslint/explicit-function-return-type": "off",
195258

@@ -205,8 +268,9 @@ module.exports = {
205268
"grafast/ruru/src/**/*.tsx",
206269
"**/website/src/**",
207270
],
208-
extends: ["plugin:react/recommended"],
209271
rules: {
272+
...react.configs.recommended.rules,
273+
...reactHooks.configs.recommended.rules,
210274
"react-hooks/rules-of-hooks": "error",
211275
"react-hooks/exhaustive-deps": [
212276
"warn",
@@ -243,13 +307,14 @@ module.exports = {
243307
files: ["**/website/**"],
244308
rules: {
245309
"import/no-unresolved": "off",
310+
"simple-import-sort/imports": "off",
246311
},
247312
},
248313

249314
// Don't use Node.js builtins
250315
{
251316
files: ["grafast/grafast/src/**", "utils/graphile-config/src/**"],
252-
excludedFiles: ["utils/graphile-config/src/loadConfig.ts"],
317+
ignores: ["utils/graphile-config/src/loadConfig.ts"],
253318
rules: {
254319
"@typescript-eslint/no-restricted-imports": [
255320
"error",
@@ -297,3 +362,24 @@ module.exports = {
297362
},
298363
],
299364
};
365+
366+
export default defineConfig([
367+
//"eslint:recommended",
368+
js.configs.recommended,
369+
// "plugin:@typescript-eslint/eslint-recommended",
370+
//"plugin:@typescript-eslint/recommended",
371+
tseslint.configs.recommended,
372+
//'plugin:@typescript-eslint/recommended-requiring-type-checking',
373+
// ...tseslint.configs.recommendedTypeChecked, // requires parserOptions.project
374+
// "plugin:import/errors",
375+
importPlugin.flatConfigs.errors,
376+
// "plugin:import/typescript",
377+
{ rules: importPlugin.flatConfigs.typescript.rules },
378+
// "plugin:graphile-export/recommended",
379+
graphileExport.configs.recommended,
380+
//"prettier",
381+
prettier, // not a plugin, just a config object
382+
config,
383+
...oldConfig.overrides,
384+
globalIgnores(globalIgnoresFromFile),
385+
]);

grafast/dataplan-pg/scripts/runExampleSchema.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { resolvePreset } from "graphile-config";
1010
import { isAsyncIterable } from "iterall";
1111
import JSON5 from "json5";
1212

13+
// eslint-disable-next-line import/no-unresolved
1314
import { schema } from "./exampleSchemaExport.mjs";
1415

1516
const databaseName = "graphilecrystaltest";
@@ -87,7 +88,7 @@ async function runTestQuery(basePath) {
8788
await promise;
8889
const sortPayloads = (payload1, payload2) => {
8990
const ONE_AFTER_TWO = 1;
90-
const ONE_BEFORE_TWO = -1;
91+
// const ONE_BEFORE_TWO = -1;
9192
if (!payload1.path) {
9293
return 0;
9394
}

grafast/dataplan-pg/src/adaptors/pg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function newNodePostgresPgClient(
145145
text: `rollback to savepoint tx${txLevel === 0 ? "" : txLevel}`,
146146
});
147147
}
148-
} catch (e2) {
148+
} catch (_e2) {
149149
console.error(`Error occurred whilst rolling back: ${e}`);
150150
}
151151
throw e;
@@ -710,7 +710,7 @@ export class PgSubscriber<
710710
await client.query(`UNLISTEN ${client.escapeIdentifier(topic)}`);
711711
this.subscribedTopics.delete(topic);
712712
}
713-
} catch (e) {
713+
} catch (_e) {
714714
// ignore
715715
}
716716
client.release();

grafast/dataplan-pg/src/datasource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ function validateRelations(registry: PgRegistry<any, any, any, any>): void {
13881388
}
13891389
}
13901390

1391-
// eslint-disable-next-line @typescript-eslint/ban-types
1391+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
13921392
export function makeRegistryBuilder(): PgRegistryBuilder<{}, {}, {}, {}> {
13931393
const registryConfig: PgRegistryConfig<any, any, any> = {
13941394
pgExecutors: Object.create(null),

grafast/dataplan-pg/src/examples/exampleSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ export function makeExampleSchema(
17101710
>;
17111711

17121712
const {
1713-
pgCodecs: { union__entity: unionEntityCodec },
1713+
pgCodecs: { union__entity: _unionEntityCodec },
17141714
pgResources: {
17151715
messages: messageResource,
17161716
users: userResource,
@@ -2860,7 +2860,7 @@ export function makeExampleSchema(
28602860

28612861
const entityUnion = EXPORTABLE(
28622862
(lambda) =>
2863-
<TCodec extends typeof unionEntityCodec>(
2863+
<TCodec extends typeof _unionEntityCodec>(
28642864
$item:
28652865
| PgSelectSingleStep<PgResource<any, TCodec, any, any, any>>
28662866
| PgClassExpressionStep<TCodec, PgResource<any, any, any, any, any>>,

grafast/dataplan-pg/src/executor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ ${duration}
456456
const pendingResult = defer<any[]>(); // CRITICAL: this MUST resolve later
457457
results[resultIndex] = pendingResult;
458458
scopedCache.set(identifiersJSON, pendingResult);
459-
remaining.push(identifiersJSON) - 1;
459+
remaining.push(identifiersJSON);
460460
remainingDeferreds.push(pendingResult);
461461
}
462462
}

grafast/dataplan-pg/src/inspect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export let inspect: {
1212
};
1313

1414
try {
15+
// eslint-disable-next-line @typescript-eslint/no-require-imports
1516
inspect = require("util").inspect;
1617
if (typeof inspect !== "function") {
1718
throw new Error("Failed to load inspect");

0 commit comments

Comments
 (0)