prettier 3.2.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -2
  3. data/README.md +23 -59
  4. data/lib/prettier.rb +7 -5
  5. data/node_modules/prettier/LICENSE +5205 -0
  6. data/node_modules/prettier/README.md +109 -0
  7. data/node_modules/prettier/{bin-prettier.js → bin/prettier.cjs} +10 -5
  8. data/node_modules/prettier/doc.d.ts +240 -0
  9. data/node_modules/prettier/doc.js +1257 -1309
  10. data/node_modules/prettier/doc.mjs +1312 -0
  11. data/node_modules/prettier/index.cjs +655 -0
  12. data/node_modules/prettier/index.d.ts +915 -0
  13. data/node_modules/prettier/index.mjs +21845 -0
  14. data/node_modules/prettier/internal/cli.mjs +6978 -0
  15. data/node_modules/prettier/internal/internal.mjs +6531 -0
  16. data/node_modules/prettier/package.json +179 -6
  17. data/node_modules/prettier/plugins/acorn.d.ts +6 -0
  18. data/node_modules/prettier/plugins/acorn.js +13 -0
  19. data/node_modules/prettier/plugins/acorn.mjs +13 -0
  20. data/node_modules/prettier/plugins/angular.d.ts +8 -0
  21. data/node_modules/prettier/plugins/angular.js +2 -0
  22. data/node_modules/prettier/plugins/angular.mjs +2 -0
  23. data/node_modules/prettier/plugins/babel.d.ts +17 -0
  24. data/node_modules/prettier/plugins/babel.js +16 -0
  25. data/node_modules/prettier/plugins/babel.mjs +16 -0
  26. data/node_modules/prettier/plugins/estree.d.ts +0 -0
  27. data/node_modules/prettier/plugins/estree.js +35 -0
  28. data/node_modules/prettier/plugins/estree.mjs +35 -0
  29. data/node_modules/prettier/plugins/flow.d.ts +5 -0
  30. data/node_modules/prettier/plugins/flow.js +21 -0
  31. data/node_modules/prettier/plugins/flow.mjs +21 -0
  32. data/node_modules/prettier/plugins/glimmer.d.ts +5 -0
  33. data/node_modules/prettier/plugins/glimmer.js +30 -0
  34. data/node_modules/prettier/plugins/glimmer.mjs +30 -0
  35. data/node_modules/prettier/plugins/graphql.d.ts +5 -0
  36. data/node_modules/prettier/plugins/graphql.js +29 -0
  37. data/node_modules/prettier/plugins/graphql.mjs +29 -0
  38. data/node_modules/prettier/plugins/html.d.ts +8 -0
  39. data/node_modules/prettier/plugins/html.js +19 -0
  40. data/node_modules/prettier/plugins/html.mjs +19 -0
  41. data/node_modules/prettier/plugins/markdown.d.ts +7 -0
  42. data/node_modules/prettier/plugins/markdown.js +59 -0
  43. data/node_modules/prettier/plugins/markdown.mjs +59 -0
  44. data/node_modules/prettier/plugins/meriyah.d.ts +5 -0
  45. data/node_modules/prettier/plugins/meriyah.js +5 -0
  46. data/node_modules/prettier/plugins/meriyah.mjs +5 -0
  47. data/node_modules/prettier/plugins/postcss.d.ts +7 -0
  48. data/node_modules/prettier/plugins/postcss.js +52 -0
  49. data/node_modules/prettier/plugins/postcss.mjs +52 -0
  50. data/node_modules/prettier/plugins/typescript.d.ts +5 -0
  51. data/node_modules/prettier/plugins/typescript.js +27 -0
  52. data/node_modules/prettier/plugins/typescript.mjs +27 -0
  53. data/node_modules/prettier/plugins/yaml.d.ts +5 -0
  54. data/node_modules/prettier/plugins/yaml.js +161 -0
  55. data/node_modules/prettier/plugins/yaml.mjs +161 -0
  56. data/node_modules/prettier/standalone.d.ts +33 -0
  57. data/node_modules/prettier/standalone.js +34 -0
  58. data/node_modules/prettier/standalone.mjs +34 -0
  59. data/package.json +15 -10
  60. data/src/plugin.js +210 -14
  61. data/src/server.rb +50 -85
  62. metadata +60 -28
  63. data/CONTRIBUTING.md +0 -185
  64. data/node_modules/prettier/cli.js +0 -15085
  65. data/node_modules/prettier/index.js +0 -37282
  66. data/node_modules/prettier/parser-angular.js +0 -2
  67. data/node_modules/prettier/parser-babel.js +0 -27
  68. data/node_modules/prettier/parser-espree.js +0 -26
  69. data/node_modules/prettier/parser-flow.js +0 -35
  70. data/node_modules/prettier/parser-glimmer.js +0 -27
  71. data/node_modules/prettier/parser-graphql.js +0 -15
  72. data/node_modules/prettier/parser-html.js +0 -36
  73. data/node_modules/prettier/parser-markdown.js +0 -76
  74. data/node_modules/prettier/parser-meriyah.js +0 -19
  75. data/node_modules/prettier/parser-postcss.js +0 -76
  76. data/node_modules/prettier/parser-typescript.js +0 -280
  77. data/node_modules/prettier/parser-yaml.js +0 -150
  78. data/node_modules/prettier/third-party.js +0 -8978
  79. data/src/getInfo.js +0 -23
  80. data/src/netcat.js +0 -13
  81. data/src/parseSync.js +0 -227
data/src/getInfo.js DELETED
@@ -1,23 +0,0 @@
1
- const { existsSync, readFileSync } = require("fs");
2
-
3
- // This is how long to wait for the parser to spin up. For the most part, 5
4
- // seconds is plenty of time. But in some environments, it may be necessary to
5
- // increase this value.
6
- const timeoutMs = parseInt(process.env.PRETTIER_RUBY_TIMEOUT_MS || "5000", 10);
7
-
8
- const filepath = process.argv[process.argv.length - 1];
9
-
10
- const timeout = setTimeout(() => {
11
- clearInterval(interval);
12
- throw new Error(`Failed to get information from parse server in time. If this
13
- happens repeatedly, try increasing the PRETTIER_RUBY_TIMEOUT_MS environment
14
- variable beyond 5000.`);
15
- }, timeoutMs);
16
-
17
- const interval = setInterval(() => {
18
- if (existsSync(filepath)) {
19
- process.stdout.write(readFileSync(filepath).toString("utf8"));
20
- clearTimeout(timeout);
21
- clearInterval(interval);
22
- }
23
- }, 100);
data/src/netcat.js DELETED
@@ -1,13 +0,0 @@
1
- // A simple fallback when no netcat-compatible adapter is found on the system.
2
- // On average, this is 2-3x slower than netcat, but still much faster than
3
- // spawning a new Ruby process.
4
-
5
- const { createConnection } = require("net");
6
-
7
- const sock = process.argv[process.argv.length - 1];
8
- const client = createConnection(sock, () => process.stdin.pipe(client));
9
-
10
- client.on("data", (data) => process.stdout.write(data));
11
- client.on("error", (error) => {
12
- console.error(error);
13
- });
data/src/parseSync.js DELETED
@@ -1,227 +0,0 @@
1
- const { spawn, spawnSync } = require("child_process");
2
- const {
3
- existsSync,
4
- unlinkSync,
5
- mkdtempSync,
6
- copyFileSync,
7
- mkdirSync,
8
- rmdirSync
9
- } = require("fs");
10
- const os = require("os");
11
- const path = require("path");
12
- const process = require("process");
13
-
14
- let parserArgs;
15
-
16
- if (process.env.PRETTIER_RUBY_HOST) {
17
- const [cmd, ...args] = process.env.PRETTIER_RUBY_HOST.split(" ");
18
- parserArgs = { cmd, args };
19
- }
20
-
21
- // In order to properly parse ruby code, we need to tell the ruby process to
22
- // parse using UTF-8. Unfortunately, the way that you accomplish this looks
23
- // differently depending on your platform.
24
- /* istanbul ignore next */
25
- function getLang() {
26
- const { env, platform } = process;
27
- const envValue = env.LC_ALL || env.LC_CTYPE || env.LANG;
28
-
29
- // If an env var is set for the locale that already includes UTF-8 in the
30
- // name, then assume we can go with that.
31
- if (envValue && envValue.includes("UTF-8")) {
32
- return envValue;
33
- }
34
-
35
- // Otherwise, we're going to guess which encoding to use based on the system.
36
- // This is probably not the best approach in the world, as you could be on
37
- // linux and not have C.UTF-8, but in that case you're probably passing an env
38
- // var for it. This object below represents all of the possible values of
39
- // process.platform per:
40
- // https://nodejs.org/api/process.html#process_process_platform
41
- return {
42
- aix: "C.UTF-8",
43
- android: "C.UTF-8",
44
- cygwin: "C.UTF-8",
45
- darwin: "en_US.UTF-8",
46
- freebsd: "C.UTF-8",
47
- haiku: "C.UTF-8",
48
- linux: "C.UTF-8",
49
- netbsd: "C.UTF-8",
50
- openbsd: "C.UTF-8",
51
- sunos: "C.UTF-8",
52
- win32: ".UTF-8"
53
- }[platform];
54
- }
55
-
56
- // Generate the filepath that should be used to communicate the connection
57
- // information between this process and the parser server.
58
- function getInfoFilepath() {
59
- return path.join(os.tmpdir(), `prettier-ruby-parser-${process.pid}.info`);
60
- }
61
-
62
- // Create a file that will act as a communication mechanism, spawn a parser
63
- // server with that filepath as an argument, then spawn another process that
64
- // will read that information in order to enable us to connect to it in the
65
- // spawnSync function.
66
- function spawnServer(opts) {
67
- const tempDir = mkdtempSync(path.join(os.tmpdir(), "prettier-plugin-ruby-"));
68
- const filepath = getInfoFilepath();
69
-
70
- let serverRbPath = path.join(__dirname, "./server.rb");
71
- let getInfoJsPath = path.join(__dirname, "./getInfo.js");
72
- let cleanupTempFiles;
73
-
74
- if (runningInPnPZip()) {
75
- // If we're running in a Yarn PnP environment inside a ZIP file, it's not possible to run
76
- // the Ruby server or the getInfo.js script directly. Instead, we need to copy them and all
77
- // the files they depend on to a temporary directory.
78
-
79
- const sourceFiles = ["server.rb", "getInfo.js", "netcat.js"];
80
- serverRbPath = path.join(tempDir, "server.rb");
81
- getInfoJsPath = path.join(tempDir, "getInfo.js");
82
-
83
- sourceFiles.forEach((rubyFile) => {
84
- const destDir = path.join(tempDir, path.dirname(rubyFile));
85
- if (!existsSync(destDir)) {
86
- mkdirSync(destDir);
87
- }
88
- copyFileSync(
89
- path.join(__dirname, "..", "src", rubyFile),
90
- path.join(tempDir, rubyFile)
91
- );
92
- });
93
-
94
- cleanupTempFiles = () => {
95
- [
96
- getInfoJsPath,
97
- ...sourceFiles.map((rubyFile) => path.join(tempDir, rubyFile))
98
- ].forEach((tmpFilePath) => {
99
- if (existsSync(tmpFilePath)) {
100
- unlinkSync(tmpFilePath);
101
- }
102
- });
103
-
104
- sourceFiles.forEach((rubyFile) => {
105
- const tempSubdir = path.join(tempDir, path.dirname(rubyFile));
106
- if (existsSync(tempSubdir)) {
107
- rmdirSync(tempSubdir);
108
- }
109
- });
110
-
111
- if (existsSync(tempDir)) {
112
- rmdirSync(tempDir);
113
- }
114
- };
115
- }
116
-
117
- const plugins = new Set(opts.rubyPlugins.split(","));
118
- if (opts.singleQuote) {
119
- plugins.add("plugin/single_quotes");
120
- }
121
-
122
- if (opts.trailingComma !== "none") {
123
- plugins.add("plugin/trailing_comma");
124
- }
125
-
126
- const rubyPlugins = Array.from(plugins).join(",");
127
-
128
- const server = spawn(
129
- "ruby",
130
- [serverRbPath, `--plugins=${rubyPlugins}`, filepath],
131
- {
132
- env: Object.assign({}, process.env, { LANG: getLang() }),
133
- detached: true,
134
- stdio: "inherit"
135
- }
136
- );
137
-
138
- server.unref();
139
- process.on("exit", () => {
140
- if (existsSync(filepath)) {
141
- unlinkSync(filepath);
142
- }
143
-
144
- if (cleanupTempFiles != null) {
145
- cleanupTempFiles();
146
- }
147
-
148
- try {
149
- if (server.pid) {
150
- // Kill the server process if it's still running. If we're on windows
151
- // we're going to use the process ID number. If we're not, we're going
152
- // to use the negative process ID to indicate the group.
153
- const pid = process.platform === "win32" ? server.pid : -server.pid;
154
- process.kill(pid);
155
- }
156
- } catch (e) {
157
- if (process.env.PLUGIN_RUBY_CI) {
158
- throw new Error(`Failed to kill the parser server: ${e}`);
159
- }
160
- }
161
- });
162
-
163
- const info = spawnSync("node", [getInfoJsPath, filepath]);
164
-
165
- if (info.status !== 0) {
166
- throw new Error(`
167
- We failed to spawn our parser server. Please report this error on GitHub
168
- at https://github.com/prettier/plugin-ruby. The error message was:
169
-
170
- ${info.stderr.toString()}.
171
- `);
172
- }
173
-
174
- const [cmd, ...args] = info.stdout.toString().split(" ");
175
- return { cmd, args };
176
- }
177
-
178
- // If we're in a yarn Plug'n'Play environment, then the relative paths being
179
- // used by the parser server and the various scripts used to communicate
180
- // therein are not going to work with its virtual file system.
181
- function runningInPnPZip() {
182
- return process.versions.pnp && __dirname.includes(".zip");
183
- }
184
-
185
- // Formats and sends a request to the parser server. We use netcat (or something
186
- // like it) here since Prettier requires the results of `parse` to be
187
- // synchronous and Node.js does not offer a mechanism for synchronous socket
188
- // requests.
189
- function parseSync(parser, source, opts) {
190
- if (!parserArgs) {
191
- parserArgs = spawnServer(opts);
192
- }
193
-
194
- const response = spawnSync(parserArgs.cmd, parserArgs.args, {
195
- input: `${parser}|${opts.printWidth}|${opts.tabWidth}|${source}`,
196
- maxBuffer: 15 * 1024 * 1024
197
- });
198
-
199
- const stdout = response.stdout.toString();
200
- const stderr = response.stderr.toString();
201
- const { status } = response;
202
-
203
- // If we didn't receive anything over stdout or we have a bad exit status,
204
- // then throw whatever we can.
205
- if (stdout.length === 0 || (status !== null && status !== 0)) {
206
- throw new Error(stderr || "An unknown error occurred");
207
- }
208
-
209
- const parsed = JSON.parse(stdout);
210
-
211
- if (parsed.error) {
212
- const error = new Error(parsed.error);
213
- if (parsed.loc) {
214
- error.loc = parsed.loc;
215
- }
216
-
217
- throw error;
218
- }
219
-
220
- return parsed;
221
- }
222
-
223
- module.exports = {
224
- getLang,
225
- getInfoFilepath,
226
- parseSync
227
- };