-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
145 lines (144 loc) · 3.63 KB
/
eslint.config.js
File metadata and controls
145 lines (144 loc) · 3.63 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
import js from '@eslint/js'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import { defineConfig, globalIgnores } from 'eslint/config'
import globals from 'globals'
import tseslint from 'typescript-eslint'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser
}
},
{
files: ['**/*.{ts,tsx,js,jsx,vue}'],
rules: {
/**
* 不可使用 namespace
* v: type interface
* x: namespace
*/
'@typescript-eslint/no-namespace': 'warn',
/**
* 不可繼承 any unknown
* v: <T>
* x: <T extends any>
*/
'@typescript-eslint/no-unnecessary-type-constraint': 'off',
/**
* 類型定義不要為空
* v: interface Type {...}
* x: interface Type {}
*/
'@typescript-eslint/no-empty-object-type': 'off',
/**
* 要求使用完整的函數定義
* v: () => {}
* x: Function
*/
'@typescript-eslint/no-unsafe-function-type': 'off',
/**
* 要求使用完整的Object定義
* v: {...}
* x: Object
*/
'@typescript-eslint/no-wrapper-object-types': 'warn',
/**
* 定義未使用
*/
'@typescript-eslint/no-unused-vars': 'warn',
/**
* 不檢查 any
* v: num: number = 123
* x: num: any = 123
*/
'@typescript-eslint/no-explicit-any': 'off',
/**
* 建議使用 cont
*/
'prefer-const': ['warn'],
/**
* 要求使用 === 和 !==
* v: a === b,
* x: a == b
*/
eqeqeq: ['warn', 'always'],
/**
* 不要分號
* v: test
* x: test;
*/
semi: ['warn', 'never'],
/**
* 使用單引號
* v: a = 'test'
* x: a = "test"
*/
quotes: ['warn', 'single'],
/**
* 逗號 前面不空格 後面要空格
* v: [1, 2, 3]
* x: [1,2,3]
*/
'comma-spacing': ['warn', { before: false, after: true }],
/**
* object 冒號 前面不空格 後面號空格
* v: { a: 123 }
* x: { a :123 }
*/
'key-spacing': ['warn', { beforeColon: false, afterColon: true }],
/**
* 操作符前後需要加空格: + - * / =
* v: 1 + 1
* x: 1+1
*/
'space-infix-ops': 'warn',
/**
* ojbect, array 最後一格不要加上逗號
* v: { a: 123, b: 456 }, [1, 2, 3]
* x: { a: 123, b: 456,}, [1, 2, 3,]
*/
'comma-dangle': ['warn', 'never'],
/**
* 行末禁止加空格
*/
'no-trailing-spaces': 'warn',
/**
* 前頭函數 前後空格
* v: () => {}
* x: ()=> {}, ()=>{}, () =>{}
*/
'arrow-spacing': ['warn', { before: true, after: true }],
/**
* 函數前面加空格
* v: function() {}
* x: function () {}
*/
'space-before-function-paren': ['off', 'never'],
/**
* 只有一個參數是否要括號
* v: (x) => x
* x: x => x
*/
'arrow-parens': ['off', 'as-needed'],
/**
* 註解加空白
* v: // ...註解
* x: //...註解
*
* v: ///
*/
'spaced-comment': ['warn', 'always', { block: { balanced: true } }],
'spaced-comment': ['error', 'always', { markers: ['/'] }]
}
}
])