-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.js
93 lines (86 loc) · 2.12 KB
/
config.js
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
// @ts-check
const linterCommandsMap = {
eslint: 'eslint --color',
stylelint: 'stylelint --color',
markdown: 'dprint check --log-level=warn',
htmllint: 'htmlhint',
jsonymllint: 'spectral lint --ignore-unknown-format',
dockerfile: 'dockerfilelint',
prettier: 'prettier -c',
biome: 'biome check --diagnostic-level=warn'
};
/**
* @param {Array<keyof typeof linterCommandsMap>} lintNames
*/
const applyLinterCommands = (lintNames = []) =>
lintNames
.map(
(/** @type {keyof typeof linterCommandsMap} */ lint) =>
linterCommandsMap[lint]
)
.filter((command) => command);
const languagesSupport = [
'ts',
'js',
'tsx',
'jsx',
'json',
'yml',
'css',
'scss',
'sass',
'less',
'md',
'dockerfile'
];
// eslint-disable-next-line complexity
module.exports = (languages = languagesSupport) => {
const config = {};
for (const language of languages) {
let regex = '*.';
let commands;
switch (language) {
case 'js':
case 'ts':
case 'jsx':
case 'tsx':
regex += language;
commands = applyLinterCommands(['eslint', 'biome']);
break;
case 'json':
regex += language;
commands = applyLinterCommands(['biome']);
break;
case 'yaml':
case 'yml':
regex += language;
commands = applyLinterCommands(['jsonymllint']);
break;
case 'html':
throw new Error('Due of security issues, we currently disabled it');
// regex += language;
// commands = applyLinterCommands(['htmllint', 'prettier']);
// break;
case 'css':
case 'scss':
case 'sass':
case 'less':
regex += language;
commands = applyLinterCommands(['stylelint', 'prettier']);
break;
case 'md':
regex += language;
commands = applyLinterCommands(['markdown']);
break;
case 'dockerfile':
regex = 'Dockerfile';
commands = applyLinterCommands(['dockerfile']);
break;
default:
return;
}
// @ts-expect-error It has a dynamic entry
config[regex] = commands;
}
return config;
};