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+ ] ) ;
0 commit comments