-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
115 lines (107 loc) · 2.75 KB
/
Copy pathindex.js
File metadata and controls
115 lines (107 loc) · 2.75 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
import eslintConfigPrettier from "eslint-config-prettier";
import globals from "globals";
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import tsParser from "@typescript-eslint/parser";
import vueParser from "vue-eslint-parser";
import pluginCypress from "eslint-plugin-cypress";
import pluginChaiFriendly from "eslint-plugin-chai-friendly";
import pluginVue from "eslint-plugin-vue";
import pluginJsdoc from "eslint-plugin-jsdoc";
/**
* Helper to dynamically convert error levels to warnings
* so that new rules do not break existing CI pipelines.
* @param {Array<object>|object} configs - ESLint configuration object(s)
* @returns {Array<object>} The modified configs with errors downgraded to warnings
*/
function mapConfigsToWarn(configs) {
if (!Array.isArray(configs)) {
configs = [configs];
}
return configs.map((config) => {
if (!config.rules) return config;
const newRules = {};
for (const [key, value] of Object.entries(config.rules)) {
if (Array.isArray(value)) {
if (value[0] === "error" || value[0] === 2) {
newRules[key] = ["warn", ...value.slice(1)];
} else {
newRules[key] = value;
}
} else if (value === "error" || value === 2) {
newRules[key] = "warn";
} else {
newRules[key] = value;
}
}
return { ...config, rules: newRules };
});
}
export const cypress = [
pluginCypress.configs.recommended,
{
plugins: { "chai-friendly": pluginChaiFriendly },
rules: {
"chai-friendly/no-unused-expressions": "error",
},
},
];
export const js = [
eslint.configs.recommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.browser,
},
},
},
];
export const typescript = [
...mapConfigsToWarn(tseslint.configs.recommended),
{
languageOptions: {
parserOptions: {
parser: tsParser,
},
},
rules: {
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
{
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"@typescript-eslint/no-unused-expressions": "off",
},
},
];
export const vue3 = [
...mapConfigsToWarn(pluginVue.configs["flat/recommended"]),
{
languageOptions: {
parser: vueParser,
parserOptions: {
parser: tsParser,
extraFileExtensions: [".vue"],
},
},
},
];
export const jsdocRules = [
...mapConfigsToWarn([
pluginJsdoc.configs["flat/recommended-typescript-flavor"],
]),
];
export const prettier = [eslintConfigPrettier];
export default [
...cypress,
...js,
...typescript,
...vue3,
...jsdocRules,
...prettier,
];