forked from VOICEVOX/voicevox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.mjs
255 lines (235 loc) · 7.11 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// @ts-check
import js from "@eslint/js";
import globals from "globals";
import * as importPlugin from "eslint-plugin-import";
import storybookPlugin from "eslint-plugin-storybook";
import vueParser from "vue-eslint-parser";
import vuePlugin from "eslint-plugin-vue";
import vuePrettierConfig from "@vue/eslint-config-prettier";
import {
defineConfigWithVueTs,
vueTsConfigs,
} from "@vue/eslint-config-typescript";
import { configs as tsConfigs, parser as tsParser } from "typescript-eslint";
import voicevoxPlugin from "./eslint-plugin/index.mjs";
const __dirname = import.meta.dirname;
/**
* @typedef {import("@typescript-eslint/utils/ts-eslint").FlatConfig.Config} Config
* @typedef {import("@typescript-eslint/utils/ts-eslint").FlatConfig.ConfigArray} ConfigArray
* @typedef {import("@typescript-eslint/utils/ts-eslint").FlatConfig.ParserOptions} ParserOptions
* @typedef {import("@typescript-eslint/utils/ts-eslint").FlatConfig.Rules} Rules
*/
/**
* プラグイン読込ラッパー関数
* nameが設定されていないプラグイン用
* @overload
* @param {string} name ESLint Config Inspectorで表示される名前
* @param {Config} config
* @returns {ConfigArray}
*/
/**
* プラグイン読込ラッパー関数
* nameが設定されている or Arrayを渡すプラグイン用
* @overload
* @param {Config | ConfigArray} configs
* @returns {ConfigArray}
*/
/**
* @param {string | Config | ConfigArray} nameOrConfigs
* @param {Config} config
* @returns {ConfigArray}
*/
const pluginConfig = (nameOrConfigs, config) => {
if (typeof nameOrConfigs === "string") {
return /** @type {ConfigArray} */ ([{ name: nameOrConfigs, ...config }]);
} else if (Array.isArray(nameOrConfigs)) {
return /** @type {ConfigArray} */ (nameOrConfigs);
} else {
return /** @type {ConfigArray} */ ([nameOrConfigs]);
}
};
/** @type {ParserOptions} */
const vueParserOptions = {
ecmaVersion: 2020,
parser: tsParser,
extraFileExtensions: [".vue"],
};
/** @type {ParserOptions} */
const typeCheckedParserOptions = {
project: ["./tsconfig.json"],
tsconfigRootDir: __dirname,
};
/** @type {Rules} */
const typeCheckedRules = {
// Storeでよくasyncなしの関数を定義するので無効化
// TODO: いずれは有効化する
"@typescript-eslint/require-await": "off",
// 比較関数無しでのsortは文字列での比較になり、ミスが起こりやすいため有効化
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/no-misused-promises": [
"error",
{
// (...) => voidに(...) => Promise<void>を渡すのは許可
// ただし特に強い意志でこれを許可しているわけではないので、
// もし問題が発生した場合は有効化する
// ref: https://canary.discord.com/channels/879570910208733277/893889888208977960/1267467454876225536
checksVoidReturn: false,
},
],
};
export default defineConfigWithVueTs(
{
name: "voicevox/defaults/plugins",
plugins: {
import: importPlugin,
},
},
{
name: "voicevox/defaults/linterOptions",
linterOptions: {
// TODO: いずれは有効化する
reportUnusedDisableDirectives: false,
},
},
{
name: "voicevox/defaults/languageOptions",
languageOptions: {
parser: vueParser,
parserOptions: {
...vueParserOptions,
},
globals: {
...globals.node,
},
},
},
{
name: "voicevox/defaults/ignores",
ignores: ["dist/**/*", "dist_*/**/*", "node_modules/**/*"],
},
...pluginConfig(vuePlugin.configs["flat/recommended"]),
...pluginConfig("eslint:recommended", js.configs.recommended),
...pluginConfig("@vue/prettier", vuePrettierConfig),
...pluginConfig(vueTsConfigs.recommended.toConfigArray()),
...pluginConfig(voicevoxPlugin.configs.all),
...pluginConfig(storybookPlugin.configs["flat/recommended"]),
{
name: "voicevox/type-checked/typescript",
files: ["**/*.ts", "**/*.mts"],
extends: [...tsConfigs.recommendedTypeChecked],
languageOptions: {
parser: tsParser,
parserOptions: {
...typeCheckedParserOptions,
},
},
rules: {
...typeCheckedRules,
},
},
{
name: "voicevox/type-checked/vue",
files: ["**/*.vue"],
extends: [...tsConfigs.recommendedTypeChecked],
languageOptions: {
parser: vueParser,
parserOptions: {
...vueParserOptions,
...typeCheckedParserOptions,
},
},
rules: {
...typeCheckedRules,
// typescript-eslintにVueの型がanyとして認識されるので無効化
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-redundant-type-constituents": "off",
},
},
{
name: "voicevox/defaults/files",
files: ["**/*.{js,mjs,ts,mts,vue}"],
},
{
name: "voicevox/defaults/rules",
rules: {
"@typescript-eslint/no-unused-vars": [
process.env.NODE_ENV !== "production" ? "warn" : "error", // 開発時のみwarn
{
ignoreRestSiblings: true,
},
],
"import/order": "error",
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-constant-condition": ["error", { checkLoops: false }], // while(true) などを許可
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
"prettier/prettier": [
"error",
{
endOfLine: "auto",
},
],
"vue/attribute-hyphenation": ["error", "never"],
"vue/block-order": [
"error",
{
order: ["template", "script", "style"],
},
],
"vue/component-name-in-template-casing": [
"error",
"PascalCase",
{
registeredComponentsOnly: false,
ignores: [],
},
],
"vue/multi-word-component-names": [
"error",
{
ignores: ["Container", "Presentation"],
},
],
"vue/v-bind-style": [
"error",
"shorthand",
{ sameNameShorthand: "always" },
],
"vue/v-on-event-hyphenation": ["error", "never", { autofix: true }],
},
},
{
name: "voicevox/some-allow-console",
files: [
"src/backend/electron/**/*.ts",
"tests/**/*.ts",
"build/*.{js,mts}",
],
rules: {
"no-console": "off",
},
},
// Electronのメインプロセス以外でelectronのimportを禁止する
{
name: "voicevox/restricted-electron-imports-outside-main-process",
ignores: ["src/backend/electron/**/*.ts"],
files: ["src/**/*.{ts,vue}"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["electron"],
message:
"このファイル内でelectronはimportできません。許可されているファイル内へ移すか、ESLintの設定を見直してください",
},
],
},
],
},
},
);