prettier 1.5.4 → 2.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +338 -276
  3. data/CONTRIBUTING.md +8 -11
  4. data/LICENSE +1 -1
  5. data/README.md +31 -14
  6. data/dist/haml/embed.js +53 -0
  7. data/dist/haml/parser.js +31 -0
  8. data/{src → dist}/haml/parser.rb +8 -1
  9. data/dist/haml/printer.js +336 -0
  10. data/dist/parser/getInfo.js +17 -0
  11. data/{src → dist}/parser/netcat.js +1 -0
  12. data/dist/parser/parseSync.js +128 -0
  13. data/dist/parser/server.rb +140 -0
  14. data/dist/plugin.js +143 -0
  15. data/dist/prettier.js +15 -0
  16. data/dist/rbs/parser.js +34 -0
  17. data/{src → dist}/rbs/parser.rb +7 -1
  18. data/dist/rbs/printer.js +517 -0
  19. data/dist/ruby/embed.js +110 -0
  20. data/dist/ruby/nodes/alias.js +59 -0
  21. data/{src → dist}/ruby/nodes/aref.js +26 -35
  22. data/dist/ruby/nodes/args.js +165 -0
  23. data/dist/ruby/nodes/arrays.js +126 -0
  24. data/dist/ruby/nodes/assign.js +41 -0
  25. data/dist/ruby/nodes/blocks.js +68 -0
  26. data/dist/ruby/nodes/calls.js +220 -0
  27. data/dist/ruby/nodes/case.js +50 -0
  28. data/dist/ruby/nodes/class.js +54 -0
  29. data/dist/ruby/nodes/commands.js +124 -0
  30. data/dist/ruby/nodes/conditionals.js +242 -0
  31. data/dist/ruby/nodes/constants.js +38 -0
  32. data/dist/ruby/nodes/flow.js +66 -0
  33. data/dist/ruby/nodes/hashes.js +130 -0
  34. data/dist/ruby/nodes/heredocs.js +30 -0
  35. data/dist/ruby/nodes/hooks.js +35 -0
  36. data/dist/ruby/nodes/ints.js +27 -0
  37. data/dist/ruby/nodes/lambdas.js +69 -0
  38. data/dist/ruby/nodes/loops.js +73 -0
  39. data/dist/ruby/nodes/massign.js +73 -0
  40. data/dist/ruby/nodes/methods.js +70 -0
  41. data/dist/ruby/nodes/operators.js +70 -0
  42. data/dist/ruby/nodes/params.js +89 -0
  43. data/dist/ruby/nodes/patterns.js +109 -0
  44. data/dist/ruby/nodes/regexp.js +45 -0
  45. data/dist/ruby/nodes/rescue.js +82 -0
  46. data/dist/ruby/nodes/return.js +75 -0
  47. data/dist/ruby/nodes/statements.js +111 -0
  48. data/dist/ruby/nodes/strings.js +218 -0
  49. data/dist/ruby/nodes/super.js +30 -0
  50. data/dist/ruby/nodes/undef.js +26 -0
  51. data/dist/ruby/nodes.js +151 -0
  52. data/dist/ruby/parser.js +34 -0
  53. data/{src → dist}/ruby/parser.rb +1276 -290
  54. data/dist/ruby/printer.js +125 -0
  55. data/dist/ruby/toProc.js +93 -0
  56. data/dist/types/haml.js +4 -0
  57. data/dist/types/plugin.js +3 -0
  58. data/dist/types/rbs.js +4 -0
  59. data/dist/types/ruby.js +4 -0
  60. data/dist/types/utils.js +2 -0
  61. data/dist/types.js +30 -0
  62. data/dist/utils/containsAssignment.js +15 -0
  63. data/dist/utils/getTrailingComma.js +6 -0
  64. data/dist/utils/hasAncestor.js +15 -0
  65. data/{src → dist}/utils/inlineEnsureParens.js +16 -16
  66. data/dist/utils/isEmptyBodyStmt.js +10 -0
  67. data/dist/utils/isEmptyStmts.js +10 -0
  68. data/dist/utils/literal.js +8 -0
  69. data/dist/utils/literallineWithoutBreakParent.js +8 -0
  70. data/dist/utils/makeCall.js +13 -0
  71. data/dist/utils/noIndent.js +11 -0
  72. data/dist/utils/printEmptyCollection.js +44 -0
  73. data/dist/utils/skipAssignIndent.js +15 -0
  74. data/dist/utils.js +30 -0
  75. data/node_modules/prettier/bin-prettier.js +13343 -10961
  76. data/node_modules/prettier/doc.js +4829 -0
  77. data/node_modules/prettier/index.js +24010 -22251
  78. data/node_modules/prettier/package.json +23 -0
  79. data/node_modules/prettier/parser-angular.js +66 -0
  80. data/node_modules/prettier/parser-babel.js +22 -0
  81. data/node_modules/prettier/parser-espree.js +22 -0
  82. data/node_modules/prettier/parser-flow.js +22 -0
  83. data/node_modules/prettier/parser-glimmer.js +1 -0
  84. data/node_modules/prettier/parser-graphql.js +1 -0
  85. data/node_modules/prettier/parser-html.js +132 -0
  86. data/node_modules/prettier/parser-markdown.js +34 -0
  87. data/node_modules/prettier/parser-meriyah.js +22 -0
  88. data/node_modules/prettier/parser-postcss.js +22 -0
  89. data/node_modules/prettier/parser-typescript.js +22 -0
  90. data/node_modules/prettier/parser-yaml.js +15 -0
  91. data/node_modules/prettier/third-party.js +1734 -862
  92. data/package.json +27 -19
  93. data/rubocop.yml +9 -0
  94. metadata +88 -79
  95. data/src/haml/embed.js +0 -87
  96. data/src/haml/nodes/comment.js +0 -27
  97. data/src/haml/nodes/doctype.js +0 -34
  98. data/src/haml/nodes/filter.js +0 -16
  99. data/src/haml/nodes/hamlComment.js +0 -21
  100. data/src/haml/nodes/plain.js +0 -6
  101. data/src/haml/nodes/root.js +0 -8
  102. data/src/haml/nodes/script.js +0 -33
  103. data/src/haml/nodes/silentScript.js +0 -59
  104. data/src/haml/nodes/tag.js +0 -193
  105. data/src/haml/parser.js +0 -22
  106. data/src/haml/printer.js +0 -28
  107. data/src/parser/getLang.js +0 -32
  108. data/src/parser/getNetcat.js +0 -57
  109. data/src/parser/parseSync.js +0 -43
  110. data/src/parser/requestParse.js +0 -74
  111. data/src/parser/server.rb +0 -66
  112. data/src/plugin.js +0 -148
  113. data/src/prettier.js +0 -16
  114. data/src/rbs/parser.js +0 -39
  115. data/src/rbs/printer.js +0 -605
  116. data/src/ruby/embed.js +0 -142
  117. data/src/ruby/nodes/alias.js +0 -73
  118. data/src/ruby/nodes/args.js +0 -178
  119. data/src/ruby/nodes/arrays.js +0 -162
  120. data/src/ruby/nodes/assign.js +0 -47
  121. data/src/ruby/nodes/blocks.js +0 -90
  122. data/src/ruby/nodes/calls.js +0 -199
  123. data/src/ruby/nodes/case.js +0 -65
  124. data/src/ruby/nodes/class.js +0 -64
  125. data/src/ruby/nodes/commands.js +0 -131
  126. data/src/ruby/nodes/conditionals.js +0 -280
  127. data/src/ruby/nodes/constants.js +0 -43
  128. data/src/ruby/nodes/flow.js +0 -74
  129. data/src/ruby/nodes/hashes.js +0 -164
  130. data/src/ruby/nodes/heredocs.js +0 -36
  131. data/src/ruby/nodes/hooks.js +0 -34
  132. data/src/ruby/nodes/ints.js +0 -31
  133. data/src/ruby/nodes/lambdas.js +0 -76
  134. data/src/ruby/nodes/loops.js +0 -98
  135. data/src/ruby/nodes/massign.js +0 -98
  136. data/src/ruby/nodes/methods.js +0 -74
  137. data/src/ruby/nodes/operators.js +0 -83
  138. data/src/ruby/nodes/params.js +0 -113
  139. data/src/ruby/nodes/patterns.js +0 -157
  140. data/src/ruby/nodes/regexp.js +0 -56
  141. data/src/ruby/nodes/rescue.js +0 -101
  142. data/src/ruby/nodes/return.js +0 -94
  143. data/src/ruby/nodes/statements.js +0 -142
  144. data/src/ruby/nodes/strings.js +0 -177
  145. data/src/ruby/nodes/super.js +0 -35
  146. data/src/ruby/nodes/undef.js +0 -42
  147. data/src/ruby/nodes.js +0 -34
  148. data/src/ruby/parser.js +0 -39
  149. data/src/ruby/printer.js +0 -138
  150. data/src/ruby/toProc.js +0 -105
  151. data/src/utils/containsAssignment.js +0 -11
  152. data/src/utils/getTrailingComma.js +0 -5
  153. data/src/utils/hasAncestor.js +0 -17
  154. data/src/utils/isEmptyBodyStmt.js +0 -7
  155. data/src/utils/isEmptyStmts.js +0 -11
  156. data/src/utils/literal.js +0 -7
  157. data/src/utils/literallineWithoutBreakParent.js +0 -7
  158. data/src/utils/makeCall.js +0 -14
  159. data/src/utils/noIndent.js +0 -11
  160. data/src/utils/printEmptyCollection.js +0 -49
  161. data/src/utils/skipAssignIndent.js +0 -10
  162. data/src/utils.js +0 -13
@@ -1,193 +0,0 @@
1
- const {
2
- align,
3
- concat,
4
- fill,
5
- group,
6
- hardline,
7
- ifBreak,
8
- indent,
9
- join,
10
- line,
11
- softline
12
- } = require("../../prettier");
13
-
14
- function getDynamicAttributes(header, attributes) {
15
- const pairs = attributes
16
- .slice(1, -2)
17
- .split(",")
18
- .map((pair) => pair.slice(1).split('" => '));
19
-
20
- const parts = [concat([pairs[0][0], "=", pairs[0][1]])];
21
- pairs.slice(1).forEach((pair) => {
22
- parts.push(line, concat([pair[0], "=", pair[1]]));
23
- });
24
-
25
- return group(concat(["(", align(header + 1, fill(parts)), ")"]));
26
- }
27
-
28
- function getHashValue(value, opts) {
29
- if (typeof value !== "string") {
30
- return value.toString();
31
- }
32
-
33
- // This is a very special syntax created by the parser to let us know that
34
- // this should be printed literally instead of as a string.
35
- if (value.startsWith("&")) {
36
- return value.slice(1);
37
- }
38
-
39
- const quote = opts.rubySingleQuote ? "'" : '"';
40
- return `${quote}${value}${quote}`;
41
- }
42
-
43
- function getHashKey(key, opts) {
44
- let quoted = key;
45
- const joiner = opts.rubyHashLabel ? ":" : " =>";
46
-
47
- if (key.includes(":") || key.includes("-")) {
48
- const quote = opts.rubySingleQuote ? "'" : '"';
49
- quoted = `${quote}${key}${quote}`;
50
- }
51
-
52
- return `${opts.rubyHashLabel ? "" : ":"}${quoted}${joiner}`;
53
- }
54
-
55
- function getKeyValuePair(key, value, opts) {
56
- return `${getHashKey(key, opts)} ${getHashValue(value, opts)}`;
57
- }
58
-
59
- function getStaticAttributes(header, attributes, opts) {
60
- const keys = Object.keys(attributes).filter(
61
- (name) => !["class", "id"].includes(name)
62
- );
63
-
64
- const parts = [getKeyValuePair(keys[0], attributes[keys[0]], opts)];
65
-
66
- keys.slice(1).forEach((key) => {
67
- parts.push(",", line, getKeyValuePair(key, attributes[key], opts));
68
- });
69
-
70
- return group(concat(["{", align(header + 1, fill(parts)), "}"]));
71
- }
72
-
73
- function getAttributesObject(object, opts, level = 0) {
74
- if (typeof object !== "object") {
75
- return getHashValue(object, opts);
76
- }
77
-
78
- const boundary = level === 0 ? softline : line;
79
- const parts = Object.keys(object).map((key) =>
80
- concat([
81
- getHashKey(key, opts),
82
- " ",
83
- getAttributesObject(object[key], opts, level + 1)
84
- ])
85
- );
86
-
87
- return group(
88
- concat([
89
- "{",
90
- indent(group(concat([boundary, join(concat([",", line]), parts)]))),
91
- boundary,
92
- "}"
93
- ])
94
- );
95
- }
96
-
97
- function getHeader(value, opts) {
98
- const { attributes } = value;
99
- const parts = [];
100
-
101
- if (value.name !== "div") {
102
- parts.push(`%${value.name}`);
103
- }
104
-
105
- if (attributes.class) {
106
- parts.push(`.${attributes.class.replace(/ /g, ".")}`);
107
- }
108
-
109
- if (attributes.id) {
110
- parts.push(`#${attributes.id}`);
111
- }
112
-
113
- if (value.dynamic_attributes.new) {
114
- parts.push(
115
- getDynamicAttributes(parts.join("").length, value.dynamic_attributes.new)
116
- );
117
- }
118
-
119
- if (
120
- Object.keys(attributes).some((name) => name !== "class" && name !== "id")
121
- ) {
122
- parts.push(getStaticAttributes(parts.join("").length, attributes, opts));
123
- }
124
-
125
- if (value.dynamic_attributes.old) {
126
- if (parts.length === 0) {
127
- parts.push("%div");
128
- }
129
-
130
- if (typeof value.dynamic_attributes.old === "string") {
131
- parts.push(value.dynamic_attributes.old);
132
- } else {
133
- parts.push(getAttributesObject(value.dynamic_attributes.old, opts));
134
- }
135
- }
136
-
137
- if (value.object_ref) {
138
- if (parts.length === 0) {
139
- parts.push("%div");
140
- }
141
- parts.push(value.object_ref);
142
- }
143
-
144
- if (value.nuke_outer_whitespace) {
145
- parts.push(">");
146
- }
147
-
148
- if (value.nuke_inner_whitespace) {
149
- parts.push("<");
150
- }
151
-
152
- if (value.self_closing) {
153
- parts.push("/");
154
- }
155
-
156
- if (value.value) {
157
- const prefix = value.parse ? "= " : ifBreak("", " ");
158
-
159
- return group(
160
- concat([
161
- group(concat(parts)),
162
- indent(concat([softline, prefix, value.value]))
163
- ])
164
- );
165
- }
166
-
167
- // In case none of the other if statements have matched and we're printing a
168
- // div, we need to explicitly add it back into the array.
169
- if (parts.length === 0 && value.name === "div") {
170
- parts.push("%div");
171
- }
172
-
173
- return group(concat(parts));
174
- }
175
-
176
- // https://haml.info/docs/yardoc/file.REFERENCE.html#element-name-
177
- function tag(path, opts, print) {
178
- const { children, value } = path.getValue();
179
- const header = getHeader(value, opts);
180
-
181
- if (children.length === 0) {
182
- return header;
183
- }
184
-
185
- return group(
186
- concat([
187
- header,
188
- indent(concat([hardline, join(hardline, path.map(print, "children"))]))
189
- ])
190
- );
191
- }
192
-
193
- module.exports = tag;
data/src/haml/parser.js DELETED
@@ -1,22 +0,0 @@
1
- const parseSync = require("../parser/parseSync");
2
-
3
- const parse = (text, _parsers, opts) => {
4
- return parseSync("haml", text, opts);
5
- };
6
-
7
- const pragmaPattern = /^\s*-#\s*@(prettier|format)/;
8
- const hasPragma = (text) => pragmaPattern.test(text);
9
-
10
- // These functions are just placeholders until we can actually perform this
11
- // properly. The functions are necessary otherwise the format with cursor
12
- // functions break.
13
- const locStart = (_node) => 0;
14
- const locEnd = (_node) => 0;
15
-
16
- module.exports = {
17
- parse,
18
- astFormat: "haml",
19
- hasPragma,
20
- locStart,
21
- locEnd
22
- };
data/src/haml/printer.js DELETED
@@ -1,28 +0,0 @@
1
- const embed = require("./embed");
2
- const nodes = {
3
- comment: require("./nodes/comment"),
4
- doctype: require("./nodes/doctype"),
5
- filter: require("./nodes/filter"),
6
- haml_comment: require("./nodes/hamlComment"),
7
- plain: require("./nodes/plain"),
8
- root: require("./nodes/root"),
9
- script: require("./nodes/script"),
10
- silent_script: require("./nodes/silentScript"),
11
- tag: require("./nodes/tag")
12
- };
13
-
14
- const genericPrint = (path, opts, print) => {
15
- const { type } = path.getValue();
16
-
17
- /* istanbul ignore next */
18
- if (!(type in nodes)) {
19
- throw new Error(`Unsupported node encountered: ${type}`);
20
- }
21
-
22
- return nodes[type](path, opts, print);
23
- };
24
-
25
- module.exports = {
26
- embed,
27
- print: genericPrint
28
- };
@@ -1,32 +0,0 @@
1
- // In order to properly parse ruby code, we need to tell the ruby process to
2
- // parse using UTF-8. Unfortunately, the way that you accomplish this looks
3
- // differently depending on your platform.
4
- /* istanbul ignore next */
5
- function getLang() {
6
- const { env, platform } = process;
7
- const envValue = env.LC_ALL || env.LC_CTYPE || env.LANG;
8
-
9
- // If an env var is set for the locale that already includes UTF-8 in the
10
- // name, then assume we can go with that.
11
- if (envValue && envValue.includes("UTF-8")) {
12
- return envValue;
13
- }
14
-
15
- // Otherwise, we're going to guess which encoding to use based on the system.
16
- // This is probably not the best approach in the world, as you could be on
17
- // linux and not have C.UTF-8, but in that case you're probably passing an env
18
- // var for it. This object below represents all of the possible values of
19
- // process.platform per:
20
- // https://nodejs.org/api/process.html#process_process_platform
21
- return {
22
- aix: "C.UTF-8",
23
- darwin: "en_US.UTF-8",
24
- freebsd: "C.UTF-8",
25
- linux: "C.UTF-8",
26
- openbsd: "C.UTF-8",
27
- sunos: "C.UTF-8",
28
- win32: ".UTF-8"
29
- }[platform];
30
- }
31
-
32
- module.exports = getLang;
@@ -1,57 +0,0 @@
1
- const { spawnSync } = require("child_process");
2
- const os = require("os");
3
-
4
- // Checks to see if an executable is available.
5
- function hasCommand(name) {
6
- let result;
7
-
8
- if (os.type() === "Windows_NT") {
9
- result = spawnSync("where", [name]);
10
- } else {
11
- result = spawnSync("command", ["-v", name]);
12
- }
13
-
14
- return result.status === 0;
15
- }
16
-
17
- // Finds an netcat-like adapter to use for sending data to a socket. We order
18
- // these by likelihood of being found so we can avoid some shell-outs.
19
- function getCommandAndArgs() {
20
- if (hasCommand("nc")) {
21
- return ["nc", ["-U"]];
22
- }
23
-
24
- if (hasCommand("telnet")) {
25
- return ["telnet", ["-u"]];
26
- }
27
-
28
- if (hasCommand("ncat")) {
29
- return ["ncat", ["-U"]];
30
- }
31
-
32
- if (hasCommand("socat")) {
33
- return ["socat", ["-"]];
34
- }
35
-
36
- return ["node", [require.resolve("./netcat.js")]];
37
- }
38
-
39
- let command;
40
- let args;
41
-
42
- function getNetcat(opts) {
43
- if (!command) {
44
- if (opts.rubyNetcatCommand) {
45
- const splits = opts.rubyNetcatCommand.split(" ");
46
-
47
- command = splits[0];
48
- args = splits.slice(1);
49
- } else {
50
- [command, args] = getCommandAndArgs();
51
- }
52
- }
53
-
54
- return { command, args };
55
- }
56
-
57
- module.exports = getNetcat;
@@ -1,43 +0,0 @@
1
- const requestParse = require("./requestParse");
2
-
3
- // Formats and sends a request to the parser server. We use netcat (or something
4
- // like it) here since Prettier requires the results of `parse` to be
5
- // synchronous and Node.js does not offer a mechanism for synchronous socket
6
- // requests.
7
- function parseSync(parser, source, opts) {
8
- const { stdout, stderr, status } = requestParse(parser, source, opts);
9
-
10
- // We need special handling in case the user's version of nc doesn't support
11
- // using unix sockets.
12
- if (stderr.includes("invalid option -- U")) {
13
- throw new Error(`
14
- @prettier/plugin-ruby uses netcat to communicate over unix sockets between
15
- the node.js process running prettier and an underlying Ruby process used
16
- for parsing. Unfortunately the version of netcat that you have installed
17
- (GNU netcat) does not support unix sockets. To solve this either uninstall
18
- GNU netcat and use a different implementation, or change the value of the
19
- rubyNetcatCommand option in your prettier configuration.
20
- `);
21
- }
22
-
23
- // If we didn't receive anything over stdout or we have a bad exit status,
24
- // then throw whatever we can.
25
- if (stdout.length === 0 || (status !== null && status !== 0)) {
26
- throw new Error(stderr || "An unknown error occurred");
27
- }
28
-
29
- const parsed = JSON.parse(stdout);
30
-
31
- if (parsed.error) {
32
- const error = new Error(parsed.error);
33
- if (parsed.loc) {
34
- error.loc = parsed.loc;
35
- }
36
-
37
- throw error;
38
- }
39
-
40
- return parsed;
41
- }
42
-
43
- module.exports = parseSync;
@@ -1,74 +0,0 @@
1
- const { spawn, spawnSync, execSync } = require("child_process");
2
- const path = require("path");
3
- const { existsSync, mkdtempSync } = require("fs");
4
- const process = require("process");
5
- const os = require("os");
6
-
7
- const getNetcat = require("./getNetcat");
8
- const getLang = require("./getLang");
9
-
10
- let sockfile = process.env.PRETTIER_RUBY_HOST;
11
-
12
- // Spawn the parser.rb subprocess. We do this since booting Ruby is slow, and we
13
- // can re-use the parser process multiple times since it is statelesss.
14
- function spawnParseServer() {
15
- const server = spawn(
16
- "ruby",
17
- [path.join(__dirname, "./server.rb"), sockfile],
18
- {
19
- env: Object.assign({}, process.env, { LANG: getLang() }),
20
- detached: true,
21
- stdio: "inherit"
22
- }
23
- );
24
-
25
- process.on("exit", () => {
26
- try {
27
- process.kill(-server.pid);
28
- } catch (e) {
29
- // ignore
30
- }
31
- });
32
-
33
- server.unref();
34
- const now = new Date();
35
-
36
- // Wait for server to go live.
37
- while (!existsSync(sockfile) && new Date() - now < 3000) {
38
- execSync("sleep 0.1");
39
- }
40
- }
41
-
42
- // Ensures that a parser server is currently running by checking against the
43
- // sockfile variable. If it is not, create a temporary directory to house the
44
- // sockfile and spawn the ruby process.
45
- function ensureParseServer() {
46
- if (sockfile) {
47
- return;
48
- }
49
-
50
- const tmpDir = mkdtempSync(path.join(os.tmpdir(), "prettier-ruby"));
51
- sockfile = path.join(tmpDir, `${process.pid}.sock`);
52
-
53
- spawnParseServer();
54
- }
55
-
56
- // Sends a request to the parse server to parse the given content.
57
- function requestParse(parser, source, opts) {
58
- ensureParseServer();
59
-
60
- const { command, args } = getNetcat(opts);
61
- const { stdout, stderr, status } = spawnSync(command, args.concat(sockfile), {
62
- input: `${parser}|${source}`,
63
- maxBuffer: 15 * 1024 * 1024
64
- });
65
-
66
- return {
67
- command,
68
- stdout: stdout.toString(),
69
- stderr: stderr.toString(),
70
- status
71
- };
72
- }
73
-
74
- module.exports = requestParse;
data/src/parser/server.rb DELETED
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/setup' if ENV['PLUGIN_RUBY_CI']
4
- require 'socket'
5
- require 'json'
6
-
7
- require_relative '../ruby/parser'
8
- require_relative '../rbs/parser'
9
- require_relative '../haml/parser'
10
-
11
- # Set the program name so that it's easy to find if we need it
12
- $PROGRAM_NAME = 'prettier-ruby-parser'
13
-
14
- # Make sure we trap these signals to be sure we get the quit command coming from
15
- # the parent node process
16
- quit = false
17
- trap(:QUIT) { quit = true } if RUBY_PLATFORM != 'java'
18
- trap(:INT) { quit = true }
19
- trap(:TERM) { quit = true }
20
-
21
- sockfile = ARGV.first || "/tmp/#{$PROGRAM_NAME}.sock"
22
- server = UNIXServer.new(sockfile)
23
-
24
- at_exit do
25
- server.close
26
- File.unlink(sockfile)
27
- end
28
-
29
- loop do
30
- break if quit
31
-
32
- # Start up a new thread that will handle each successive connection.
33
- Thread.new(server.accept_nonblock) do |socket|
34
- parser, source = socket.read.force_encoding('UTF-8').split('|', 2)
35
-
36
- response =
37
- case parser
38
- when 'ruby'
39
- Prettier::Parser.parse(source)
40
- when 'rbs'
41
- Prettier::RBSParser.parse(source)
42
- when 'haml'
43
- Prettier::HAMLParser.parse(source)
44
- end
45
-
46
- if response
47
- socket.write(JSON.fast_generate(response))
48
- else
49
- socket.write('{ "error": true }')
50
- end
51
- rescue Prettier::Parser::ParserError => error
52
- loc = { start: { line: error.lineno, column: error.column } }
53
- socket.write(JSON.fast_generate(error: error.message, loc: loc))
54
- rescue StandardError => error
55
- socket.write(JSON.fast_generate(error: error.message))
56
- ensure
57
- socket.close
58
- end
59
- rescue IO::WaitReadable, Errno::EINTR
60
- # Wait for select(2) to give us a connection that has content for 1 second.
61
- # Otherwise timeout and continue on (so that we hit our "break if quit"
62
- # pretty often).
63
- IO.select([server], nil, nil, 1)
64
-
65
- retry unless quit
66
- end
data/src/plugin.js DELETED
@@ -1,148 +0,0 @@
1
- const rubyPrinter = require("./ruby/printer");
2
- const rubyParser = require("./ruby/parser");
3
-
4
- const rbsPrinter = require("./rbs/printer");
5
- const rbsParser = require("./rbs/parser");
6
-
7
- const hamlPrinter = require("./haml/printer");
8
- const hamlParser = require("./haml/parser");
9
-
10
- /*
11
- * metadata mostly pulled from linguist and rubocop:
12
- * https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
13
- * https://github.com/rubocop-hq/rubocop/blob/master/spec/rubocop/target_finder_spec.rb
14
- */
15
-
16
- module.exports = {
17
- languages: [
18
- {
19
- name: "Ruby",
20
- parsers: ["ruby"],
21
- extensions: [
22
- ".arb",
23
- ".axlsx",
24
- ".builder",
25
- ".eye",
26
- ".fcgi",
27
- ".gemfile",
28
- ".gemspec",
29
- ".god",
30
- ".jb",
31
- ".jbuilder",
32
- ".mspec",
33
- ".opal",
34
- ".pluginspec",
35
- ".podspec",
36
- ".rabl",
37
- ".rake",
38
- ".rb",
39
- ".rbi",
40
- ".rbuild",
41
- ".rbw",
42
- ".rbx",
43
- ".ru",
44
- ".ruby",
45
- ".thor",
46
- ".watchr"
47
- ],
48
- filenames: [
49
- ".irbrc",
50
- ".pryrc",
51
- ".simplecov",
52
- "Appraisals",
53
- "Berksfile",
54
- "Brewfile",
55
- "Buildfile",
56
- "Capfile",
57
- "Cheffile",
58
- "Dangerfile",
59
- "Deliverfile",
60
- "Fastfile",
61
- "Gemfile",
62
- "Guardfile",
63
- "Jarfile",
64
- "Mavenfile",
65
- "Podfile",
66
- "Puppetfile",
67
- "Rakefile",
68
- "Snapfile",
69
- "Thorfile",
70
- "Vagabondfile",
71
- "Vagrantfile",
72
- "buildfile"
73
- ],
74
- interpreters: ["jruby", "macruby", "rake", "rbx", "ruby"],
75
- linguistLanguageId: 326,
76
- vscodeLanguageIds: ["ruby"]
77
- },
78
- {
79
- name: "RBS",
80
- parsers: ["rbs"],
81
- extensions: [".rbs"]
82
- },
83
- {
84
- name: "HAML",
85
- parsers: ["haml"],
86
- extensions: [".haml"],
87
- vscodeLanguageIds: ["haml"]
88
- }
89
- ],
90
- parsers: {
91
- ruby: rubyParser,
92
- rbs: rbsParser,
93
- haml: hamlParser
94
- },
95
- printers: {
96
- ruby: rubyPrinter,
97
- rbs: rbsPrinter,
98
- haml: hamlPrinter
99
- },
100
- options: {
101
- rubyArrayLiteral: {
102
- type: "boolean",
103
- category: "Ruby",
104
- default: true,
105
- description:
106
- "When possible, favor the use of string and symbol array literals."
107
- },
108
- rubyHashLabel: {
109
- type: "boolean",
110
- category: "Ruby",
111
- default: true,
112
- description:
113
- "When possible, uses the shortened hash key syntax, as opposed to hash rockets."
114
- },
115
- rubyModifier: {
116
- type: "boolean",
117
- category: "Ruby",
118
- default: true,
119
- description:
120
- "When it fits on one line, allows if, unless, while, and until statements to use the modifier form."
121
- },
122
- rubyNetcatCommand: {
123
- type: "string",
124
- category: "Ruby",
125
- description:
126
- 'The prefix of the command to execute to communicate between the node.js process and the Ruby process. (For example, "nc -U" or "telnet -u") Normally you should not set this option.'
127
- },
128
- rubySingleQuote: {
129
- type: "boolean",
130
- category: "Ruby",
131
- default: true,
132
- description:
133
- "When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals."
134
- },
135
- rubyToProc: {
136
- type: "boolean",
137
- category: "Ruby",
138
- default: false,
139
- description:
140
- "When possible, convert blocks to the more concise Symbol#to_proc syntax."
141
- }
142
- },
143
- defaultOptions: {
144
- printWidth: 80,
145
- tabWidth: 2,
146
- trailingComma: "none"
147
- }
148
- };
data/src/prettier.js DELETED
@@ -1,16 +0,0 @@
1
- // If `RBPRETTIER` is set, then this is being run from the `Prettier::run` ruby
2
- // method. In that case, we need to pull `prettier` from the node_modules
3
- // directly, as it's been shipped with the gem.
4
- /* istanbul ignore next */
5
- const source = process.env.RBPRETTIER ? "../node_modules/prettier" : "prettier";
6
-
7
- const prettier = require(source);
8
-
9
- // Just combine all the things into one big object so that we can import
10
- // whatever we need from prettier without having to dive too deeply.
11
- module.exports = Object.assign(
12
- {},
13
- prettier.doc.builders,
14
- prettier.doc.utils,
15
- prettier.util
16
- );