1- import { defineConfig , globalIgnores } from 'eslint/config' ;
2- import typescriptEslint from '@typescript-eslint/eslint-plugin' ;
3- import jest from 'eslint-plugin-jest' ;
4- import prettier from 'eslint-plugin-prettier' ;
51import globals from 'globals' ;
6- import tsParser from '@typescript-eslint/parser' ;
2+
3+ import typescriptPlugin from '@typescript-eslint/eslint-plugin' ;
4+
75import path from 'node:path' ;
86import { fileURLToPath } from 'node:url' ;
7+
98import js from '@eslint/js' ;
109import { FlatCompat } from '@eslint/eslintrc' ;
1110
@@ -17,51 +16,71 @@ const compat = new FlatCompat({
1716 allConfig : js . configs . all ,
1817} ) ;
1918
20- export default defineConfig ( [
21- globalIgnores ( [
22- 'coverage/**/*' ,
23- 'dist/**/*' ,
24- 'scripts/**/*' ,
25- '**/*.sh' ,
26- 'coverage/**/*' ,
27- 'dist/**/*' ,
28- 'scripts/**/*' ,
29- '**/*.sh' ,
30- '**/rollup.config.js' ,
31- '**/populate-readme.cjs' ,
32- 'eslint.config.mjs' ,
33- ] ) ,
19+ export default [
3420 {
35- extends : compat . extends (
36- 'eslint:recommended' ,
37- 'plugin:@typescript-eslint/eslint-recommended' ,
38- 'plugin:@typescript-eslint/recommended' ,
39- 'plugin:jest/recommended' ,
40- 'plugin:prettier/recommended' ,
41- ) ,
42-
43- plugins : {
44- '@typescript-eslint' : typescriptEslint ,
45- jest,
46- prettier,
47- } ,
48-
21+ ignores : [
22+ 'coverage/**/*' ,
23+ 'dist/**/*' ,
24+ 'scripts/**/*' ,
25+ '**/*.sh' ,
26+ '**/*.js' ,
27+ 'eslint.config.mjs' ,
28+ ] ,
29+ } ,
30+ ...compat . extends (
31+ 'eslint:recommended' ,
32+ 'plugin:@typescript-eslint/eslint-recommended' ,
33+ 'plugin:@typescript-eslint/recommended' ,
34+ 'plugin:jest/recommended' ,
35+ 'prettier' ,
36+ ) ,
37+ {
38+ plugins : { '@typescript-eslint' : typescriptPlugin } ,
4939 languageOptions : {
50- globals : {
51- ...globals . node ,
52- } ,
53-
54- parser : tsParser ,
55- ecmaVersion : 5 ,
56- sourceType : 'commonjs' ,
57-
58- parserOptions : {
59- project : './tsconfig.json' ,
60- tsconfigRootDir : './' ,
61- } ,
40+ globals : { ...globals . node , ...globals . jest } ,
41+ parserOptions : { project : 'tsconfig.json' , tsConfigRootDir : './' } ,
6242 } ,
63-
6443 rules : {
44+ /******************************************************************
45+ * Async / Promises
46+ ******************************************************************/
47+
48+ // Don't allow a function to be async if there's no await
49+ 'require-await' : 'error' ,
50+
51+ // Don't allow returning await statements
52+ 'no-return-await' : 'error' ,
53+
54+ // Prevent unreachable code
55+ 'no-unreachable' : 'error' ,
56+
57+ // Don't allow awaiting calls that are not thenable
58+ // (such as example promises)
59+ '@typescript-eslint/await-thenable' : 'error' ,
60+
61+ //
62+ '@typescript-eslint/no-floating-promises' : 'error' ,
63+
64+ // Prevent promises from being used ad illogical locations
65+ // such as in if statements, as this is usually forgetting an await
66+ '@typescript-eslint/no-misused-promises' : 'error' ,
67+
68+ /******************************************************************
69+ * Classes
70+ ******************************************************************/
71+
72+ // Always declare accessibility of class members (public, private, ...)
73+ '@typescript-eslint/explicit-member-accessibility' : 'error' ,
74+
75+ // Don't allow unused methods/attributes in classes
76+ // that are not public
77+ 'no-unused-private-class-members' : 'error' ,
78+
79+ /******************************************************************
80+ * Misc
81+ ******************************************************************/
82+
83+ // Always require a return type on methods
6584 '@typescript-eslint/explicit-function-return-type' : [
6685 'error' ,
6786 {
@@ -70,37 +89,77 @@ export default defineConfig([
7089 } ,
7190 ] ,
7291
73- '@typescript-eslint/no-floating-promises' : [ 'error' ] ,
74- '@typescript-eslint/no-shadow' : [ 'error' ] ,
75- '@typescript-eslint/explicit-member-accessibility' : [ 'error' ] ,
76- 'no-console' : [ 'error' ] ,
77- 'no-return-await' : [ 'error' ] ,
92+ // Don't allow for..in loops (should generally be for..of)
93+ '@typescript-eslint/no-for-in-array' : 'error' ,
94+
95+ // Warn when working with deprecated code
96+ '@typescript-eslint/no-deprecated' : 'error' ,
97+
98+ // Don't require explicit argument typings but warn if they
99+ // have not been provided
100+ '@typescript-eslint/explicit-module-boundary-types' : 'warn' ,
78101
79- 'padding-line-between-statements' : [
102+ // Don't allow the use of `any`
103+ '@typescript-eslint/no-explicit-any' : 'off' ,
104+
105+ // Ensure all cases are handled in a switch
106+ '@typescript-eslint/switch-exhaustiveness-check' : [
80107 'error' ,
81- {
82- blankLine : 'always' ,
83- prev : '*' ,
84- next : 'function' ,
85- } ,
108+ { considerDefaultExhaustiveForUnions : true } ,
86109 ] ,
87110
88- 'prettier/prettier' : [
111+ // Don't allow shadowing of variables (i.e. redeclaring a
112+ // variable with the same name)
113+ '@typescript-eslint/no-shadow' : 'error' ,
114+
115+ // Only allow toString to be called on values where
116+ // it makes sense
117+ '@typescript-eslint/no-base-to-string' : 'error' ,
118+
119+ // Require variable initialization
120+ // Only use the typescript-eslint version
121+ 'init-declarations' : 'off' ,
122+ '@typescript-eslint/init-declarations' : 'error' ,
123+
124+ // Don't allow unused variables unless they start with _
125+ // Only use the typescript-eslint version
126+ 'no-unused-vars' : 'off' ,
127+ '@typescript-eslint/no-unused-vars' : [
89128 'error' ,
90- { } ,
91- {
92- usePrettierrc : true ,
93- } ,
129+ { args : 'all' , argsIgnorePattern : '^_' , varsIgnorePattern : '^_' } ,
94130 ] ,
95131
96- 'require-await' : [ 'error' ] ,
132+ // Don't allow unused expressions unless they start with _
133+ // Only use typescript-eslint version
134+ 'no-unused-expressions' : 'off' ,
135+ '@typescript-eslint/no-unused-expressions' : 'error' ,
136+
137+ // Don't allow ts-comments
138+ '@typescript-eslint/ban-ts-comment' : 'error' ,
139+
140+ // Warn on deprecations
141+ '@typescript-eslint/no-deprecated' : 'warn' ,
97142 } ,
98143 } ,
99144 {
100- files : [ 'test/**/*.js' ] ,
145+ files : [ 'test/**' ] ,
146+ rules : {
147+ // Allow non-null assertions in test files
148+ '@typescript-eslint/no-non-null-assertion' : 'off' ,
101149
150+ // Don't require intialization in test files
151+ 'init-declarations' : 'off' ,
152+ '@typescript-eslint/init-declarations' : 'off' ,
153+ } ,
154+ } ,
155+ {
156+ files : [ 'mock-server/**' ] ,
102157 rules : {
103- '@typescript-eslint/explicit-function-return-type' : 'off' ,
158+ // Allow non-boolan statements
159+ '@typescript-eslint/strict-boolean-expressions' : 'off' ,
160+
161+ // Allow returning promises where no promises are expected
162+ '@typescript-eslint/no-misused-promises' : 'off' ,
104163 } ,
105164 } ,
106- ] ) ;
165+ ] ;
0 commit comments