This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
75 lines (62 loc) · 1.79 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
73
74
75
module.exports = editorConfigToPrettier;
function removeUnset(editorConfig) {
const result = {};
const keys = Object.keys(editorConfig);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (editorConfig[key] === "unset") {
continue;
}
result[key] = editorConfig[key];
}
return result;
}
function editorConfigToPrettier(editorConfig) {
if (!editorConfig) {
return null;
}
editorConfig = removeUnset(editorConfig);
if (Object.keys(editorConfig).length === 0) {
return null;
}
const result = {};
if (editorConfig.indent_style) {
result.useTabs = editorConfig.indent_style === "tab";
}
if (editorConfig.indent_size === "tab") {
result.useTabs = true;
}
if (result.useTabs && editorConfig.tab_width) {
result.tabWidth = editorConfig.tab_width;
} else if (
editorConfig.indent_style === "space" &&
editorConfig.indent_size &&
editorConfig.indent_size !== "tab"
) {
result.tabWidth = editorConfig.indent_size;
} else if (editorConfig.tab_width !== undefined) {
result.tabWidth = editorConfig.tab_width;
}
if (editorConfig.max_line_length) {
if (editorConfig.max_line_length === "off") {
result.printWidth = Number.POSITIVE_INFINITY;
} else {
result.printWidth = editorConfig.max_line_length;
}
}
if (editorConfig.quote_type === "single") {
result.singleQuote = true;
} else if (editorConfig.quote_type === "double") {
result.singleQuote = false;
}
if (["cr", "crlf", "lf"].indexOf(editorConfig.end_of_line) !== -1) {
result.endOfLine = editorConfig.end_of_line;
}
if (
editorConfig.insert_final_newline === false ||
editorConfig.insert_final_newline === true
) {
result.insertFinalNewline = editorConfig.insert_final_newline;
}
return result;
}