MCPcopy
hub / github.com/prettier/prettier / makePlugin

Function makePlugin

tests/integration/__tests__/plugin-api-embed.js:10–68  ·  view source on GitHub ↗
(withOutdatedApi = false)

Source from the content-addressed store, hash-verified

8} = prettier;
9
10function makePlugin(withOutdatedApi = false) {
11 return {
12 parsers: {
13 // parsers leak across tests, so the name needs to be unique
14 [withOutdatedApi ? "baz-parser-outdated" : "baz-parser"]: {
15 parse: (text) => ({
16 type: "root",
17 lines: text
18 .trim()
19 .split("\n")
20 .map((line) => ({
21 type: line.startsWith("{") ? "json" : "plain",
22 text: line,
23 })),
24 }),
25 astFormat: "baz-ast",
26 },
27 },
28 printers: {
29 "baz-ast": {
30 print(path, options, print) {
31 const { type, text } = path.getValue();
32 switch (type) {
33 case "root":
34 return path.map(print, "lines");
35 case "json":
36 case "plain":
37 return [text, hardline];
38 }
39 },
40 embed: withOutdatedApi
41 ? (path, print, textToDoc) => {
42 const { type, text } = path.getValue();
43 if (type === "json") {
44 return [
45 textToDoc(text, {
46 parser: "json",
47 printWidth: Number.POSITIVE_INFINITY,
48 }),
49 hardline,
50 ];
51 }
52 }
53 : (path) => {
54 const { type, text } = path.getValue();
55 if (type === "json") {
56 return async (textToDoc) => [
57 await textToDoc(text, {
58 parser: "json",
59 printWidth: Number.POSITIVE_INFINITY,
60 }),
61 hardline,
62 ];
63 }
64 },
65 },
66 },
67 };

Callers 1

Calls 5

textToDocFunction · 0.85
splitMethod · 0.80
getValueMethod · 0.80
mapMethod · 0.45
trimMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…