Skip to content

Commit 60c2eb7

Browse files
authored
refactor: small updates to eslint config (#618)
* refactor: cleanup eslint config - Use the base eslint config without the tseslint.configure helper function. * refactor: properly type jest config files * refactor: address linter error and warnings
1 parent 8308fb7 commit 60c2eb7

File tree

10 files changed

+880
-58
lines changed

10 files changed

+880
-58
lines changed

eslint.config.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,49 @@ import jestPlugin from 'eslint-plugin-jest';
55
import globals from 'globals';
66
import tseslint from 'typescript-eslint';
77

8-
export default tseslint.config(
8+
export default [
99
{
10+
name: 'base ignore',
1011
ignores: ['**/coverage/**', '**/dist/**', '**/node_modules/**'],
1112
},
13+
eslint.configs.recommended,
1214
{
13-
extends: [
14-
eslint.configs.recommended,
15-
...tseslint.configs.recommended,
16-
],
15+
name: 'javascript',
16+
files: ['**/*.js'],
17+
languageOptions: {
18+
globals: {
19+
...globals.jquery,
20+
...globals.browser,
21+
},
22+
},
23+
},
24+
...tseslint.configs.recommended,
25+
{
26+
name: 'typescript',
27+
files: ['**/*.ts'],
1728
languageOptions: {
1829
parser: tseslint.parser,
1930
parserOptions: {
2031
projectService: true,
2132
tsconfigRootDir: import.meta.dirname,
2233
},
2334
globals: {
24-
...globals.jquery,
25-
...globals.browser,
2635
...globals.node,
2736
...globals.jest,
2837
},
2938
},
3039
rules: {
31-
'@typescript-eslint/no-unused-vars': 'off',
32-
'@typescript-eslint/no-unused-expressions': 'off',
40+
'@typescript-eslint/no-unused-vars': 'warn',
41+
'@typescript-eslint/no-unused-expressions': 'warn',
3342
'@typescript-eslint/no-explicit-any': 'off',
34-
'@typescript-eslint/no-var-requires': 'warn',
3543
},
3644
},
3745
{
38-
// disable type-aware linting on JS files
39-
files: ['**/*.js'],
40-
...tseslint.configs.disableTypeChecked
41-
},
42-
{
43-
// enable jest rules on test files
46+
name: 'jest',
4447
files: ['**/*.test.{js,ts}'],
4548
...jestPlugin.configs['flat/recommended'],
4649
rules: {
4750
'@typescript-eslint/no-unsafe-argument': 'off',
4851
},
4952
},
50-
);
53+
];

jest.config.integration.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import config from './jest.config';
1+
import { Config } from '@jest/types';
2+
import baseConfig from './jest.config';
3+
4+
const integrationConfig: Config.InitialOptions = {
5+
...baseConfig,
6+
displayName: 'Integration Tests',
7+
testRegex: '\\.itest\\.(js|ts)$',
8+
silent: true,
9+
};
210

3-
config.testRegex = '\\.itest\\.(js|ts)$'; //Overriding testRegex option
411
console.log('RUNNING INTEGRATION TESTS');
5-
config.silent = true; //Overriding silent option
6-
export default config;
12+
export default integrationConfig;

jest.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2-
export default {
1+
import { Config } from '@jest/types';
2+
3+
const baseConfig: Config.InitialOptions = {
34
preset: 'ts-jest',
45
testEnvironment: 'jest-environment-node',
56
collectCoverage: true,
@@ -19,3 +20,5 @@ export default {
1920
},
2021
transform: {},
2122
};
23+
24+
export default baseConfig;

jest.config.unit.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import config from './jest.config';
2-
config.testRegex = '\\.test\\.(js|ts)$'; //Overriding testRegex option
3-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4-
// @ts-ignore
5-
(config.setupFilesAfterEnv = ['./src/tests/support/setupRedisMock.ts']),
6-
console.log('RUNNING UNIT TESTS');
7-
export default config;
1+
import { Config } from '@jest/types';
2+
import baseConfig from './jest.config';
3+
4+
const unitConfig: Config.InitialOptions = {
5+
...baseConfig,
6+
displayName: 'Unit Tests',
7+
testRegex: '\\.test\\.(js|ts)$',
8+
setupFilesAfterEnv: ['./src/tests/support/setupRedisMock.ts'],
9+
silent: false,
10+
};
11+
12+
console.log('RUNNING UNIT TESTS');
13+
export default unitConfig;

0 commit comments

Comments
 (0)