generated from shuding/nextra-docs-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.code.mjs
144 lines (143 loc) · 5.39 KB
/
eslint.config.code.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
139
140
141
142
143
144
import * as mdx from 'eslint-plugin-mdx';
import pluginPrettier from 'eslint-plugin-prettier';
import configPrettierRecommended from 'eslint-plugin-prettier/recommended';
import eslint from '@eslint/js';
import eslintTS from 'typescript-eslint';
import tsParser from '@typescript-eslint/parser';
import pluginImport from 'eslint-plugin-import';
import pluginTypescript from '@typescript-eslint/eslint-plugin';
import configReactRecommended from 'eslint-plugin-react/configs/recommended.js';
import configReactJSXRuntime from 'eslint-plugin-react/configs/jsx-runtime.js';
import pluginReactHooks from 'eslint-plugin-react-hooks';
import {fixupPluginRules} from '@eslint/compat';
export default [
eslint.configs.recommended,
...eslintTS.configs.recommended,
configReactRecommended,
configReactJSXRuntime,
configPrettierRecommended,
{
files: ['**/*.{js,ts,tsx,cjs,mjs}'],
ignores: ['**/*.mdx'],
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaFeatures: {modules: true},
ecmaVersion: 'latest',
project: './tsconfig.json',
},
},
settings: {
react: {
version: 'detect',
},
},
plugins: {
import: pluginImport,
prettier: pluginPrettier,
'@typescript-eslint': pluginTypescript,
'react-hooks': fixupPluginRules(pluginReactHooks),
},
rules: {
...pluginReactHooks.configs.recommended.rules,
/**
* Allow empty arrow functions `() => {}`, while keeping other empty functions restricted
* @see https://eslint.org/docs/latest/rules/no-empty-function#allow-arrowfunctions
*/
'@typescript-eslint/no-empty-function': ['error', {allow: ['arrowFunctions']}],
'@typescript-eslint/ban-ts-comment': 1,
'no-const-assign': 'error',
/** Restrict imports from devDependencies since they are not included in library build. peerDependencies are ok */
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
peerDependencies: true,
},
],
/**
* Enforce import order with empty lines between import group
* @see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md
*/
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index']],
pathGroups: [
{
pattern: '@/**',
group: 'internal',
},
],
'newlines-between': 'always',
},
],
/**
* Disallow combined module and type imports like this `import React, {FC} from 'react'`.
* Eslint will try to split into type and module imports instead
* @see https://typescript-eslint.io/rules/consistent-type-imports/
*/
'@typescript-eslint/consistent-type-imports': 'error',
'import/no-cycle': 'error',
'prettier/prettier': [
'error',
{
semi: true,
singleQuote: true,
jsxSingleQuote: false,
trailingComma: 'es5',
bracketSpacing: false,
jsxBracketSameLine: true,
arrowParens: 'avoid',
},
],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
/**
* Allow unused variables with names stating with '_'
* @see https://eslint.org/docs/latest/rules/no-unused-vars
* @see https://typescript-eslint.io/rules/no-unused-vars/
*/
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
args: 'after-used',
},
],
},
},
{
plugins: {
prettier: pluginPrettier,
},
...mdx.flat,
// optional, if you want to lint code blocks at the same
processor: mdx.createRemarkProcessor({
lintCodeBlocks: true,
// optional, if you want to disable language mapper, set it to `false`
// if you want to override the default language mapper inside, you can provide your own
languageMapper: {},
}),
rules: {
...mdx.flatCodeBlocks.rules,
'prettier/prettier': [
'error',
{
semi: true,
singleQuote: true,
jsxSingleQuote: false,
trailingComma: 'es5',
bracketSpacing: false,
jsxBracketSameLine: true,
arrowParens: 'avoid',
},
],
},
},
];