-
Notifications
You must be signed in to change notification settings - Fork 577
Expand file tree
/
Copy patheslint.config.mjs
More file actions
148 lines (136 loc) · 4.97 KB
/
eslint.config.mjs
File metadata and controls
148 lines (136 loc) · 4.97 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import eslintComments from '@eslint-community/eslint-plugin-eslint-comments';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import sortKeysFix from 'eslint-plugin-sort-keys-fix';
import testingLibrary from 'eslint-plugin-testing-library';
import globals from 'globals';
import { dirname } from 'path';
import tseslint from 'typescript-eslint';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
});
export default tseslint.config(
// Global ignores
{
ignores: ['dist/**', 'lib/**', '.next/**', '.next-dev/**', 'node_modules/**'],
},
// Next.js config via compat (still legacy format in v15)
...compat.extends('next/core-web-vitals'),
// Base configs (after compat so tseslint parser takes precedence)
...tseslint.configs.recommended,
// Main config
{
linterOptions: {
reportUnusedDisableDirectives: 'warn',
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
},
plugins: {
'simple-import-sort': simpleImportSort,
'sort-keys-fix': sortKeysFix,
'@eslint-community/eslint-comments': eslintComments,
},
rules: {
semi: ['error', 'always'],
'@typescript-eslint/no-explicit-any': 'off',
'object-curly-spacing': ['error', 'always'],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-empty-object-type': ['error', { allowInterfaces: 'with-single-extends' }],
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true,
},
],
'no-unused-vars': 'off',
'simple-import-sort/imports': 'error',
'no-restricted-globals': ['error', 'RegExp'],
'no-restricted-syntax': [
'error',
{
selector: 'Literal[regex]',
message:
'RegExps are not recommended. If you sure regexp is needed - please use eslint-disable-next no-restricted-syntax -- %comment% to explain why',
},
{
selector: 'RegExpLiteral',
message:
'RegExps are not recommended. If you sure regexp is needed - please use eslint-disable-next no-restricted-syntax -- %comment% to explain why',
},
],
'sort-keys-fix/sort-keys-fix': 'error',
'@eslint-community/eslint-comments/no-unlimited-disable': 'error',
'no-console': 'error',
},
},
// Allow require() in CommonJS and script files
{
files: ['**/*.cjs', '**/*.js'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
// Testing library config for test files
{
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
...testingLibrary.configs['flat/react'],
},
// Allow unlimited disable in mock files
{
files: ['**/mocks/**/*.[jt]s?(x)'],
rules: {
'@eslint-community/eslint-comments/no-unlimited-disable': 'off',
},
},
// Allow console in logger, scripts, standalone files, pnpmfile
{
files: ['app/shared/lib/logger.ts', 'scripts/**', '**/*.mjs', '**/*.cjs'],
rules: {
'no-console': 'off',
},
},
// Relax sort-keys in config/tooling files (not linted by next lint before)
{
files: ['*.config.*', '**/*.mjs', '**/*.cjs', '.storybook/**', 'scripts/**', '.prettierrc.cjs'],
rules: {
'sort-keys-fix/sort-keys-fix': 'off',
},
},
// Restrict @sentry/nextjs imports in app code
{
files: ['app/**/*.[jt]s?(x)'],
ignores: ['app/shared/lib/sentry/**', 'app/shared/lib/logger.ts'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: '@sentry/nextjs',
message:
"Import from '@/app/shared/lib/sentry' instead. For logging, use the Logger from '@/app/shared/lib/logger'.",
},
],
},
],
},
},
);