-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend-typescript.js
97 lines (89 loc) · 3 KB
/
frontend-typescript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import node from 'eslint-plugin-node';
import testingLibrary from 'eslint-plugin-testing-library';
import {fixupPluginRules} from '@eslint/compat';
import tsParser from '@typescript-eslint/parser';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import js from '@eslint/js';
import {FlatCompat} from '@eslint/eslintrc';
import tsEslint from 'typescript-eslint';
import overrides from './common/overrides.js';
import youDontNeedLodash from './rules/you-dont-need-lodash.js';
import typescriptRules from './rules/typescript.js';
import consistentTypeImports from './rules/consistent-type-imports.js';
import frontendConfig from './frontend.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
});
const testingLibraryReact = {
rules: compat.extends('plugin:testing-library/react')[0].rules,
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
};
export default [
...compat.extends('plugin:you-dont-need-lodash-underscore/compatible'),
...tsEslint.configs.recommended,
...frontendConfig,
testingLibraryReact,
{
plugins: {
'@typescript-eslint': tsEslint.plugin,
node,
'testing-library': fixupPluginRules(testingLibrary),
},
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
rules: {
// Often test name starts with component name which are always capitalized
'jest/lowercase-name': 'off',
'react/prop-types': 'off',
'react/display-name': 'warn',
'testing-library/await-async-queries': 'error',
'testing-library/no-await-sync-queries': 'error',
// 'testing-library/no-wait-for-empty-callback': 'error',
// It's enabled in overrides
'testing-library/no-debugging-utils': 'off',
'testing-library/consistent-data-testid': [
2,
{
testIdPattern: '^(([a-z])+(-)*)+$',
},
],
...consistentTypeImports,
// it fail to compile TS on react static class properties (displayName | defaultProps | etc..)
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/consistent-type-assertions': 'warn',
// Don`t need for typescript files
'@typescript-eslint/no-empty-function': 'off',
...typescriptRules,
'@typescript-eslint/no-unused-vars': ['error', {ignoreRestSiblings: true}],
...youDontNeedLodash,
},
},
overrides.allowRequireInConfigs,
overrides.noExplicitsInTests,
overrides.noCastWithJestMock,
overrides.noTSRulesWithJSON,
{
files: ['**/*.test.{ts,tsx,js}', '**/mocks.ts', '**/mock.js'],
rules: {
camelcase: 'off',
'sonarjs/no-duplicate-string': 'off',
'testing-library/no-debugging-utils': 'error',
},
},
{
files: ['**/*.styled.{ts,tsx}'],
rules: {
'sonarjs/no-nested-template-literals': 'off',
},
},
];