-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
plugins.ts
143 lines (138 loc) · 3.58 KB
/
plugins.ts
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import * as prettier from "../../../../src/index.js";
import { expectType } from "ts-expect";
interface PluginAST {
kind: "line";
value: string;
}
const plugin: prettier.Plugin<PluginAST> = {
languages: [
{
name: "Shell",
parsers: ["sh"],
interpreters: ["bash", "zsh"],
},
],
parsers: {
lines: {
parse(text, options) {
return { kind: "line", value: "This is a line" };
},
astFormat: "lines",
locStart: (node) => {
expectType<PluginAST>(node);
return 0;
},
locEnd: (node) => {
expectType<PluginAST>(node);
return 0;
},
},
},
printers: {
lines: {
print(path, options, print) {
expectType<prettier.AstPath<PluginAST>>(path);
expectType<(path: prettier.AstPath<PluginAST>) => prettier.Doc>(print);
const node = path.getValue();
expectType<PluginAST>(node);
return node.value;
},
printComment(commentPath, options) {
const comment = commentPath.getValue();
return comment.value;
},
},
},
options: {
testBoolOption: {
type: "boolean",
category: "Test",
default: true,
description: "Move open brace for code blocks onto new line.",
oppositeDescription:
"Don't move open brace for code blocks onto new line.",
},
testBoolArrOption: {
type: "boolean",
array: true,
category: "Test",
default: [{ value: [true, false, true] }],
deprecated: true,
description: "Move open brace for code blocks onto new line.",
},
testIntOption: {
type: "int",
category: "Global",
default: 15,
range: {
start: 5,
end: 100,
step: 5,
},
deprecated: "Deprecated can be a string describing deprecation status.",
description: "This is a number.",
},
testIntArrOption: {
type: "int",
category: "Test",
default: [{ value: [3, 8, 12] }],
array: true,
description: "This is a number.",
},
testStringOption: {
type: "string",
category: "Test",
default: "default",
description: "This is a string.",
},
testStringArrOption: {
type: "string",
category: "Test",
default: [{ value: ["one", "two", "three"] }],
array: true,
description: "This is a string.",
},
testChoiceOption: {
type: "choice",
default: "one",
choices: [
{ value: "one", description: "The number one" },
{ value: "two", description: "The number two" },
{ value: "three", description: "The number three" },
],
category: "Test",
description: "Choose one of three.",
},
testChoiceComplexOption: {
type: "choice",
default: [{ since: "1.0.7", value: "banana" }, { value: "apple" }],
choices: [
{ value: "apple", description: "A fruit." },
{ value: "orange", since: "1.0.6", description: "A different fruit." },
{
value: "banana",
since: "1.0.5",
description: "Added in 1.0.5, made default in 1.0.7.",
},
],
category: "Test",
description: "Choose one of three.",
},
testPathOption: {
type: "path",
category: "Test",
default: "./path.js",
},
testPathArrOption: {
type: "path",
category: "Test",
array: true,
default: [{ value: ["./pathA.js", "./pathB.js"] }],
},
testNoDefaultOption: {
type: "path",
category: "Test",
},
},
};
prettier.format("a line!", { parser: "lines", plugins: [plugin] });