-
Notifications
You must be signed in to change notification settings - Fork 2
/
eslint.config.mjs
165 lines (156 loc) · 5.28 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
// @ts-check
import eslintJs from '@eslint/js';
import eslintConfigPackageJson from 'eslint-plugin-package-json/configs/recommended';
import eslintConfigPrettier from 'eslint-config-prettier';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
import eslintPluginVitest from '@vitest/eslint-plugin';
import typescriptEslint from 'typescript-eslint';
const namedRecommendedEslintConfig = {
name: 'eslint/recommended',
...eslintJs.configs.recommended,
};
const typescriptEslintStrictAndStylisticConfigs = [
...typescriptEslint.configs.strictTypeChecked,
...typescriptEslint.configs.stylisticTypeChecked.filter(
({ name }) =>
name !== 'typescript-eslint/base' &&
name !== 'typescript-eslint/eslint-recommended',
),
];
const namedEslintConfigPrettier = {
name: 'config-prettier',
...eslintConfigPrettier,
};
export default typescriptEslint.config(
{
name: 'vue-ts-types/ignore-dist',
ignores: ['dist'],
},
eslintConfigPackageJson,
{
files: ['**/*.ts', '**/*.mjs'],
extends: [
namedRecommendedEslintConfig,
...typescriptEslintStrictAndStylisticConfigs,
eslintPluginUnicorn.configs['flat/recommended'],
namedEslintConfigPrettier,
],
},
{
name: 'vue-ts-types/main',
files: ['**/*.ts', '**/*.mjs'],
languageOptions: {
ecmaVersion: 'latest',
parserOptions: {
projectService: {
allowDefaultProject: ['eslint.config.mjs'],
defaultProject: './tsconfig.json',
},
},
},
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
rules: {
// Core ESLint rules
'accessor-pairs': 'error',
'camelcase': [
'error',
{
allow: ['Vue2_6', 'Vue2_7'],
},
],
'consistent-return': 'error',
'curly': ['error', 'all'],
'eqeqeq': 'error',
'grouped-accessor-pairs': ['error', 'getBeforeSet'],
'guard-for-in': 'error',
'no-bitwise': 'error',
'no-else-return': ['error', { allowElseIf: false }],
'no-lonely-if': 'error',
'no-loop-func': 'error',
'no-object-constructor': 'error',
'no-return-assign': 'error',
'no-shadow': 'off', // replaced by @typescript-eslint/no-shadow
'no-template-curly-in-string': 'error',
'no-unsafe-optional-chaining': [
'error',
{ disallowArithmeticOperators: true },
],
'object-shorthand': ['error', 'always', { avoidQuotes: true }],
'prefer-arrow-callback': 'error',
'prefer-template': 'error',
'radix': 'error',
// eslint-plugin-unicorn
'unicorn/filename-case': 'off',
'unicorn/no-null': 'off',
'unicorn/no-useless-undefined': 'off', // conflicts with consistent-return
'unicorn/prevent-abbreviations': [
'warn',
{
replacements: {
prop: false,
},
},
],
// @typescript-eslint/eslint-plugin
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/no-empty-object-type': [
'error',
{ allowInterfaces: 'with-single-extends' },
],
'@typescript-eslint/no-explicit-any': 'off', // needed for Vue types compatibility
'@typescript-eslint/no-extraneous-class': 'off',
'@typescript-eslint/no-unnecessary-parameter-property-assignment':
'error',
'@typescript-eslint/no-shadow': [
'warn',
{ ignoreOnInitialization: true },
],
'@typescript-eslint/prefer-enum-initializers': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'error',
},
},
{
name: 'vue-ts-types/eslint',
files: ['eslint.config.mjs'],
rules: {
// less strict rules for ESLint config while some ESLint plugins don't provide proper types
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
},
},
{
name: 'vue-ts-types/tests',
files: ['tests/**/*.spec.ts'],
plugins: {
vitest: eslintPluginVitest,
},
rules: {
...eslintPluginVitest.configs.recommended.rules,
...Object.fromEntries(
Object.keys(eslintPluginVitest.configs.all.rules).map((ruleName) => [
ruleName,
'error',
]),
),
'vitest/consistent-test-filename': 'off', // already covered by specific `include` path
'vitest/max-expects': 'off', // more expect statements are needed for some tests
'vitest/padding-around-all': 'off', // already covered by individual `padding` rules
'vitest/prefer-expect-assertions': 'off', // too verbose
'vitest/prefer-to-be-falsy': 'off', // `.toBe(false)` is more explicit
'vitest/prefer-to-be-truthy': 'off', // `.toBe(true)` is more explicit
// less strict other rules
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
},
},
);