Skip to content

Commit 55b7f9e

Browse files
committed
chore: update ESLint and Jest configuration
1 parent 1a6059b commit 55b7f9e

File tree

4 files changed

+587
-465
lines changed

4 files changed

+587
-465
lines changed

eslint.config.js

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import globals from 'globals';
22
import eslint from '@eslint/js';
33
import tseslint from 'typescript-eslint';
4-
import eslintConfigPrettier from 'eslint-config-prettier';
4+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
55
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
66

77
export default tseslint.config(
88
eslint.configs.recommended,
99
tseslint.configs.strictTypeChecked,
1010
tseslint.configs.stylisticTypeChecked,
1111
eslintPluginUnicorn.configs['flat/recommended'],
12-
eslintConfigPrettier,
12+
eslintPluginPrettierRecommended,
1313
{
1414
languageOptions: {
1515
globals: globals.node,
@@ -19,8 +19,100 @@ export default tseslint.config(
1919
},
2020
},
2121
},
22+
{
23+
files: ['src/**/*.ts', 'tests/**/*.ts'],
24+
rules: {
25+
'no-console': 'warn',
26+
'no-debugger': 'warn',
27+
'no-empty-pattern': 'warn',
28+
'no-empty': 'warn',
29+
'no-param-reassign': 'warn',
30+
'no-unreachable': 'warn',
31+
'no-var': 'warn',
32+
'no-warning-comments': 'warn',
33+
'prefer-const': 'warn',
34+
eqeqeq: 'warn',
35+
36+
'prettier/prettier': 'warn',
37+
38+
'unicorn/prevent-abbreviations': 'off',
39+
'unicorn/prefer-optional-catch-binding': 'warn',
40+
'unicorn/no-empty-file': 'warn',
41+
'unicorn/prefer-set-has': 'warn',
42+
/**
43+
* There are situations where you might prefer to use `null` because
44+
* `undefined` doesn't fit. For example, when merging one object into another
45+
* with lodash's merge function, it completely ignores properties with
46+
* `undefined` values and you may want to keep those properties.
47+
*/
48+
'unicorn/no-null': 'off',
49+
50+
'@typescript-eslint/no-magic-numbers': 'warn',
51+
'@typescript-eslint/no-unused-vars': 'warn',
52+
'@typescript-eslint/no-unsafe-assignment': 'warn',
53+
'@typescript-eslint/no-floating-promises': ['warn', { ignoreIIFE: true }],
54+
'@typescript-eslint/no-empty-function': 'warn',
55+
'@typescript-eslint/explicit-function-return-type': [
56+
'warn',
57+
{
58+
allowExpressions: false,
59+
allowTypedFunctionExpressions: true,
60+
allowHigherOrderFunctions: false,
61+
allowDirectConstAssertionInArrowFunctions: true,
62+
allowConciseArrowFunctionExpressionsStartingWithVoid: false,
63+
allowFunctionsWithoutTypeParameters: false,
64+
allowedNames: [],
65+
allowIIFEs: false,
66+
},
67+
],
68+
'@typescript-eslint/explicit-module-boundary-types': 'warn',
69+
'@typescript-eslint/typedef': [
70+
'warn',
71+
{
72+
arrayDestructuring: true,
73+
objectDestructuring: true,
74+
arrowParameter: true,
75+
memberVariableDeclaration: true,
76+
parameter: true,
77+
propertyDeclaration: true,
78+
variableDeclaration: true,
79+
variableDeclarationIgnoreFunction: true,
80+
},
81+
],
82+
'@typescript-eslint/strict-boolean-expressions': 'warn',
83+
'@typescript-eslint/no-unsafe-call': 'warn',
84+
'@typescript-eslint/no-unsafe-member-access': 'warn',
85+
'@typescript-eslint/no-for-in-array': 'warn',
86+
'@typescript-eslint/consistent-type-exports': 'warn',
87+
'@typescript-eslint/consistent-type-imports': 'warn',
88+
'@typescript-eslint/no-shadow': 'warn',
89+
'@typescript-eslint/require-await': 'warn',
90+
'@typescript-eslint/no-explicit-any': 'warn',
91+
'@typescript-eslint/no-unsafe-return': 'warn',
92+
/**
93+
* It's better to explicitly define the type. The implementation may change in the future,
94+
* and you can forget to add the type if it's not there. Also, you may need to create a variable
95+
* that could have several types and in this case it's better to explicitly define what are those types.
96+
*/
97+
'@typescript-eslint/no-inferrable-types': 'off',
98+
// /**
99+
// * The nullish coalescing operator only coalesces when the checked value is null or
100+
// * undefined, but what if you want to coalesce on any falsy value like an empty string?
101+
// * In that case you would need "||". This requires {"strictNullChecks": true}
102+
// */
103+
// '@typescript-eslint/prefer-nullish-coalescing': 'off',
104+
},
105+
},
22106
{
23107
files: ['**/*.js'],
108+
// TS rules are applied by default so we have to disable the
109+
// type-checking rules for JS files.
24110
extends: [tseslint.configs.disableTypeChecked],
25111
},
112+
// {
113+
// files: ['tests/**/*.ts'],
114+
// env: {
115+
// jest: true,
116+
// },
117+
// },
26118
);

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export default {
1010
transform: {
1111
'^.+.ts$': ['ts-jest', {}],
1212
},
13+
clearMocks: true,
1314
};

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
},
1414
"scripts": {
1515
"check-types": "yarn tsc --noEmit --pretty",
16-
"lint": "eslint ./src",
17-
"lint:fix": "eslint ./src --fix",
16+
"lint": "eslint '{src,tests}/**/*.ts'",
17+
"lint:fix": "eslint '{src,tests}/**/*.ts' --fix",
1818
"dev": "tsx watch src/server.ts",
1919
"test": "jest",
2020
"test:watch": "jest --watch",
@@ -34,16 +34,14 @@
3434
"@types/node": "^22.10.10",
3535
"eslint": "^9.18.0",
3636
"eslint-config-prettier": "^10.0.1",
37+
"eslint-plugin-prettier": "^5.2.3",
3738
"eslint-plugin-unicorn": "^56.0.1",
3839
"globals": "^15.14.0",
3940
"jest": "^29.7.0",
40-
"prettier": "^3.4.2",
41+
"prettier": "3.4.2",
4142
"ts-jest": "^29.2.5",
4243
"tsx": "^4.19.2",
4344
"typescript": "^5.7.3",
4445
"typescript-eslint": "^8.21.0"
45-
},
46-
"engines": {
47-
"node": ">=22"
4846
}
4947
}

0 commit comments

Comments
 (0)