-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheslint.config.cjs
95 lines (89 loc) · 2.62 KB
/
eslint.config.cjs
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
const fs = require('fs');
const path = require('path');
const { includeIgnoreFile } = require('@eslint/compat');
const eslintJS = require('@eslint/js');
const stylistic = require('@stylistic/eslint-plugin');
const vue = require('eslint-plugin-vue');
const globals = require('globals');
const eslintTS = require('typescript-eslint');
const gitignoreFilePath = path.resolve(__dirname, '.gitignore');
// styling related rules, so code formatter is not needed
const styleConfig = {
jsx: false, semi: true, arrowParens: true, braceStyle: '1tbs',
};
const eslintStyleJS = stylistic.configs.customize({ ...styleConfig, ts: false });
const eslintStyleTS = stylistic.configs.customize(styleConfig);
const pluginsJS = { ...eslintStyleJS.plugins };
const pluginsTS = {
'@typescript-eslint': eslintTS.plugin,
...eslintStyleJS.plugins,
...eslintStyleTS.plugins,
};
const rulesJS = { ...eslintJS.configs.recommended.rules, ...eslintStyleJS.rules };
const rulesTS = {
...eslintJS.configs.recommended.rules,
...eslintStyleJS.rules,
...eslintTS.configs.recommended[1].rules,
...eslintTS.configs.recommended[2].rules,
...eslintStyleTS.rules,
'@stylistic/indent': ['error', 2, { ignoreComments: true }],
};
const eslintVue = vue.configs['flat/recommended'];
module.exports = [
{
// for config files
files: ['**/*.config.{ts|cjs}'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'commonjs',
globals: { ...globals.node },
},
plugins: pluginsJS,
rules: rulesJS,
},
{
// for typescript files
files: ['**/*.ts', '**/*.cts', '**/*.mts'],
ignores: ['**/*.config.*'],
languageOptions: {
ecmaVersion: 'latest',
parser: eslintTS.parser,
parserOptions: {
projectService: true,
},
sourceType: 'module',
},
plugins: pluginsTS,
rules: rulesTS,
},
// for vue files
{
files: ['*.vue', '**/*.vue'],
languageOptions: eslintVue[1].languageOptions,
plugins: eslintVue[1].plugins,
processor: eslintVue[1].processor,
rules: {
...eslintVue[1].rules,
...eslintVue[2].rules,
...eslintVue[3].rules,
...eslintVue[4].rules,
'vue/multi-word-component-names': 'warn',
},
},
{
// for typescript inside vue files
files: ['*.vue', '**/*.vue'],
languageOptions: {
parserOptions: {
ecmaVersion: 'latest',
extraFileExtensions: ['.vue'],
parser: eslintTS.parser,
projectService: true,
},
},
plugins: pluginsTS,
rules: rulesTS,
},
// ignore everything inside .gitignore
fs.existsSync(gitignoreFilePath) ? includeIgnoreFile(gitignoreFilePath) : {},
];