-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.mjs
114 lines (103 loc) · 3.46 KB
/
eslint.config.mjs
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { fixupPluginRules } from '@eslint/compat';
import { default as eslint } from '@eslint/js';
import tsParser from '@typescript-eslint/parser';
import prettierConfig from 'eslint-config-prettier';
import pluginChaiFriendly from 'eslint-plugin-chai-friendly';
import pluginCypress from 'eslint-plugin-cypress/flat';
import _import from 'eslint-plugin-import';
import pluginMocha from 'eslint-plugin-mocha';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import vitest from 'eslint-plugin-vitest';
import globals from 'globals';
import tseslint from 'typescript-eslint';
export default tseslint.config(
{
ignores: ['**/src/template/**', '**/dist/**', '**/build/**', '**/node_modules/**'],
},
prettierConfig,
eslint.configs.recommended,
pluginCypress.configs.recommended,
pluginCypress.configs.globals,
pluginMocha.configs.flat.recommended,
...tseslint.configs.recommended,
{
files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx', '**/*.mjs'],
plugins: {
'@typescript-eslint': tseslint.plugin,
react,
vitest,
cypress: pluginCypress,
'chai-friendly': pluginChaiFriendly,
// TODO: Replace (and remove compatability packages in package.json) when flat config is supported in these plugins
'react-hooks': fixupPluginRules(reactHooks),
import: fixupPluginRules(_import),
},
languageOptions: {
globals: {
...vitest.environments.env.globals,
...globals.browser,
...globals.node,
fetchMock: true,
FormioUtils: true,
},
parser: tsParser,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
rules: {
...vitest.configs.recommended.rules,
...reactHooks.configs.recommended.rules,
// Errors
'mocha/no-exclusive-tests': 'error', // Should not ignore tests
'no-unused-labels': 'error', // Should not have any unused labels
'import/no-duplicates': 'error', // Should not import the same module twice (should be handled automatically by prettier-plugin-organize-imports)
// Ignores unused variables starting with _ or $
'@typescript-eslint/no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
argsIgnorePattern: '^[_$].*',
varsIgnorePattern: '^[_$].*',
caughtErrorsIgnorePattern: '^[_$].*',
},
],
// There was an error with a missing key that crashed the app
'react/jsx-key': [
'error',
{
checkFragmentShorthand: true,
},
],
// Should not import from shared components or domain
'import/no-internal-modules': [
'error',
{
forbid: ['@navikt/skjemadigitalisering-shared-@(components|domain)/**'],
},
],
// Warnings
'@typescript-eslint/ban-ts-comment': 'warn', // No @ts-ignore or @ts-nocheck comments
// Disabled
'mocha/no-mocha-arrows': 'off', // We don't use "this" context in tests so we can use arrow functions
'vitest/expect-expect': 'off', // Cypress tests don't necessarily use expect
'@typescript-eslint/no-explicit-any': 'off', // Explicit any's
},
},
{
files: ['**/mocks/**'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-require-imports': 'off',
},
},
{
files: ['**/cypress/e2e/**'],
rules: {
'@typescript-eslint/no-unused-expressions': 'off',
},
},
);