-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.mjs
138 lines (134 loc) · 3.25 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { FlatCompat } from '@eslint/eslintrc';
import eslintJs from '@eslint/js';
const nextJsReservedFiles = [
'default',
'error',
'forbidden',
'instrumentation',
'layout',
'loading',
'mdx-components',
'middleware',
'not-found',
'page',
'route',
'template',
'unauthorized',
];
const compat = new FlatCompat({
baseDirectory: import.meta.dirname,
recommendedConfig: eslintJs.configs.recommended,
});
/**
* @type {import('eslint').Linter.Config}
*/
const eslintConfig = [
...compat.config({
extends: [
'eslint:recommended',
'prettier',
'next/core-web-vitals',
'next/typescript',
],
}),
{
name: 'Javascript rules',
rules: {
'no-console': ['warn'],
'no-debugger': ['error'],
semi: ['error', 'always'],
quotes: ['error', 'single', { avoidEscape: true }],
'no-tabs': ['error', { allowIndentationTabs: false }],
indent: ['error', 2],
'max-len': ['error', 80],
'jsx-quotes': ['error', 'prefer-double'],
'linebreak-style': ['error', 'unix'],
eqeqeq: ['error', 'always'],
'no-undef': 'error',
'prefer-const': [
'error',
{ destructuring: 'all', ignoreReadBeforeAssign: false },
],
},
},
{
name: 'Import rules',
rules: {
'import/first': ['error'],
'import/newline-after-import': ['error', { count: 1 }],
'import/no-absolute-path': ['error'],
'import/no-duplicates': ['error', { 'prefer-inline': true }],
'import/no-cycle': ['error'],
'import/no-self-import': ['error'],
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'unknown',
'parent',
'sibling',
'index',
'object',
'type',
],
'newlines-between': 'always',
named: true,
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
},
},
{
name: 'Source code export rules',
files: ['src/**/*.{js,jsx,ts,tsx}'],
// only allow named export in source code
rules: {
'import/no-default-export': ['error'],
},
},
{
name: 'NextJS reserved files export rules',
files: [
...nextJsReservedFiles.map((keyword) => {
return `src/app/**/${keyword}.{js,jsx,ts,tsx}`;
}),
],
// only allow default export in reserved files
rules: {
'import/no-default-export': ['off'],
'import/prefer-default-export': ['error'],
},
},
{
name: 'Typescript rules',
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{ args: 'all', argsIgnorePattern: '_' },
],
'@typescript-eslint/no-empty-interface': [
'error',
{ allowSingleExtends: true },
],
},
},
{
name: 'React rules',
rules: {
'react/jsx-boolean-value': ['error', 'never'],
'react/self-closing-comp': ['error', { component: true, html: true }],
'react/jsx-curly-spacing': ['error', 'never', { allowMultiline: true }],
'react/function-component-definition': [
'error',
{ namedComponents: 'function-declaration' },
],
},
},
];
export default eslintConfig;