-
Notifications
You must be signed in to change notification settings - Fork 3
/
eslint.config.js
156 lines (150 loc) · 4.26 KB
/
eslint.config.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
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
149
150
151
152
153
154
155
156
import path from "node:path";
import { fileURLToPath } from "node:url";
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
import { includeIgnoreFile } from "@eslint/compat";
import js from "@eslint/js";
import next from '@next/eslint-plugin-next';
import jestLint from 'eslint-plugin-jest';
import * as mdx from 'eslint-plugin-mdx';
import reactPlugin from 'eslint-plugin-react';
import reactRecommended from 'eslint-plugin-react/configs/recommended.js';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import simpleImportSort from "eslint-plugin-simple-import-sort";
import tseslint from 'typescript-eslint';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const gitignorePath = path.resolve(__dirname, ".gitignore");
/** @type {import('eslint').Linter.FlatConfig} */
export const reactConfig = {
name: 'react etc',
languageOptions: {
sourceType: 'module',
ecmaVersion: 2020,
},
rules: {
...fixupConfigRules(reactRecommended),
...reactHooksPlugin.configs.recommended.rules,
...next.configs.recommended.rules,
},
plugins: {
'react-hooks': reactHooksPlugin,
'@next/next': next,
'react': fixupPluginRules(reactPlugin),
'simple-import-sort': simpleImportSort,
'jest': jestLint,
},
rules: {
'jest/prefer-importing-jest-globals': "error",
'react/forbid-elements': [
'error',
{
forbid: [
{ element: 'a', message: '<a> is dangerous. Please use the Link component instead.' },
{ element: 'video', message: 'native <video> does not respect reduced motion. Use Video in ts/react/video instead.' }
],
},
],
'no-restricted-imports': [
'error',
{ name: 'next/link', message: '<NextLink> is dangerous. Please use the <Link> component instead.' },
],
'react/prop-types': 'off',
'react/display-name': 'off',
'react/prefer-read-only-props': 'error',
'react/react-in-jsx-scope': 'off',
'react/self-closing-comp': 'error',
'react/jsx-sort-props': 'error',
'react/no-unescaped-entities': 'off',
'arrow-parens': ['error', 'as-needed'],
'arrow-spacing': ['error', { before: true, after: true }],
'prefer-const': ['error', { destructuring: 'all' }],
'no-else-return': ['error', { allowElseIf: false }],
'no-extra-bind': 'error',
'no-multi-spaces': 'error',
'array-bracket-newline': ['error', 'consistent'],
'no-unused-expressions': 'error',
'no-constant-binary-expression': 'error',
'no-sequences': 'error',
'array-element-newline': ['error', 'consistent'],
'block-spacing': ['error', 'always'],
'comma-spacing': 'error',
'computed-property-spacing': 'error',
'key-spacing': 'error',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'keyword-spacing': 'error',
'object-curly-newline': 'error',
'arrow-body-style': ['error', 'as-needed'],
'no-console': 'error',
},
settings: {
react: {
version: 'detect',
},
next: {
rootDir: ['project/zemn.me/'],
},
},
}
/** @type {import('eslint').Linter.FlatConfig[]} */
export default tseslint.config(
{
name: 'ts files & js files',
files: ['**/*.{ts,js}?(x)'],
languageOptions: {
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
project: ['tsconfig.json'],
},
},
extends: [
js.configs.recommended,
...tseslint.configs.recommended,
reactConfig
],
plugins: {
'@next/next': next,
},
rules: {
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-empty-interface': ['error', { allowSingleExtends: true }],
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unnecessary-condition': 'error',
},
},
{
name: 'markdown',
files: ['**/*.md?(x)'],
plugins: {
mdx: 'eslint-plugin-mdx',
},
languageOptions: {
extraFileExtensions: ['.md', '.mdx'],
},
settings: {
'mdx/code-blocks': true,
'mdx/language-mapper': {},
},
...mdx.flat,
},
{
name: 'gitignore',
extends: [
includeIgnoreFile(gitignorePath)
]
}
)