-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (62 loc) · 1.88 KB
/
index.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
// @ts-check
const merge = require("lodash.merge");
/**
* @typedef EslintConfigName
* @type {"base"|"browser-node"|"browser"|"config-authoring"|"config-files"|"jest"|"next"|"node"|"playwright-test"|"react"|"tailwindcss"|"tsup"|"typescript"}
*/
/**
* @param {EslintConfigName[]} configNames
* @param {import("eslint").Linter.Config} extraConfig
*/
const extendEslint = (configNames = [], extraConfig = {}) => {
/** @type {import("eslint").Linter.Config} */
const config = {};
/** @type {import("eslint").Linter.Config["extends"]} */
const newExtends = [];
configNames.forEach((name) => {
require.resolve(`./eslint/${name}`);
});
if (typeof extraConfig.extends === "string") {
newExtends.push(extraConfig.extends);
}
if (Array.isArray(extraConfig.extends)) {
newExtends.push(...extraConfig.extends);
}
config.extends = configNames.map((name) => {
return require.resolve(`./eslint/${name}`);
});
/** @type {import("eslint").Linter.Config["ignorePatterns"]} */
const newIgnorePatterns = [];
if (typeof extraConfig.ignorePatterns === "string") {
newIgnorePatterns.push(extraConfig.ignorePatterns);
}
if (Array.isArray(extraConfig.ignorePatterns)) {
newIgnorePatterns.push(...extraConfig.ignorePatterns);
}
config.ignorePatterns = newIgnorePatterns;
if (configNames.includes("typescript")) {
const { getTsconfigPath } = require("./eslint/utils/tsconfig");
config.parserOptions = {
project: getTsconfigPath(),
};
config.settings = {
"import/resolver": {
typescript: {
project: getTsconfigPath(),
},
},
};
}
return merge(extraConfig, config);
};
/**
* @param {import("prettier").Config} config
* @returns {import("prettier").Config}
*/
const extendPrettier = (config = {}) => {
return merge(require("./prettier"), config);
};
module.exports = {
extendEslint,
extendPrettier,
};