prettier 1.5.0 → 1.5.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -2
- data/README.md +22 -12
- data/node_modules/prettier/index.js +53 -53
- data/node_modules/prettier/parser-angular.js +46 -0
- data/node_modules/prettier/parser-babel.js +1 -0
- data/node_modules/prettier/parser-espree.js +1 -0
- data/node_modules/prettier/parser-flow.js +1 -0
- data/node_modules/prettier/parser-glimmer.js +1 -0
- data/node_modules/prettier/parser-graphql.js +1 -0
- data/node_modules/prettier/parser-html.js +113 -0
- data/node_modules/prettier/parser-markdown.js +19 -0
- data/node_modules/prettier/parser-meriyah.js +1 -0
- data/node_modules/prettier/parser-postcss.js +1 -0
- data/node_modules/prettier/parser-typescript.js +1 -0
- data/node_modules/prettier/parser-yaml.js +15 -0
- data/package.json +4 -4
- data/rubocop.yml +3 -0
- data/src/haml/nodes/tag.js +45 -6
- data/src/haml/parser.js +2 -2
- data/src/haml/parser.rb +8 -3
- data/src/parser/netcat.js +0 -2
- data/src/parser/parseSync.js +151 -14
- data/src/parser/server.rb +7 -2
- data/src/plugin.js +6 -0
- data/src/rbs/parser.js +2 -2
- data/src/rbs/parser.rb +7 -3
- data/src/rbs/printer.js +14 -4
- data/src/ruby/embed.js +7 -5
- data/src/ruby/nodes/args.js +67 -19
- data/src/ruby/nodes/arrays.js +36 -33
- data/src/ruby/nodes/commands.js +1 -1
- data/src/ruby/nodes/heredocs.js +5 -3
- data/src/ruby/parser.js +2 -2
- data/src/ruby/parser.rb +81 -6
- data/src/ruby/printer.js +8 -3
- data/src/utils.js +1 -1
- data/src/utils/inlineEnsureParens.js +8 -1
- data/src/utils/literallineWithoutBreakParent.js +7 -0
- metadata +16 -7
- data/src/parser/getLang.js +0 -32
- data/src/parser/getNetcat.js +0 -50
- data/src/parser/requestParse.js +0 -74
- data/src/utils/literalLineNoBreak.js +0 -7
data/src/ruby/printer.js
CHANGED
@@ -38,7 +38,8 @@ const noComments = [
|
|
38
38
|
"args_add_star",
|
39
39
|
"mlhs",
|
40
40
|
"mlhs_add_post",
|
41
|
-
"mlhs_add_star"
|
41
|
+
"mlhs_add_star",
|
42
|
+
"mlhs_paren"
|
42
43
|
];
|
43
44
|
|
44
45
|
// Certain nodes are used more for organizational purposed than for actually
|
@@ -97,8 +98,12 @@ function getCommentChildNodes(node) {
|
|
97
98
|
|
98
99
|
return parts;
|
99
100
|
}
|
100
|
-
default:
|
101
|
-
|
101
|
+
default: {
|
102
|
+
if (Array.isArray(node.body)) {
|
103
|
+
return node.body.filter((child) => child && typeof child === "object");
|
104
|
+
}
|
105
|
+
return [];
|
106
|
+
}
|
102
107
|
}
|
103
108
|
}
|
104
109
|
|
data/src/utils.js
CHANGED
@@ -5,7 +5,7 @@ module.exports = {
|
|
5
5
|
isEmptyStmts: require("./utils/isEmptyStmts"),
|
6
6
|
hasAncestor: require("./utils/hasAncestor"),
|
7
7
|
literal: require("./utils/literal"),
|
8
|
-
|
8
|
+
literallineWithoutBreakParent: require("./utils/literallineWithoutBreakParent"),
|
9
9
|
makeCall: require("./utils/makeCall"),
|
10
10
|
noIndent: require("./utils/noIndent"),
|
11
11
|
printEmptyCollection: require("./utils/printEmptyCollection"),
|
@@ -1,4 +1,11 @@
|
|
1
|
-
const needsParens = [
|
1
|
+
const needsParens = [
|
2
|
+
"args",
|
3
|
+
"assign",
|
4
|
+
"assoc_new",
|
5
|
+
"call",
|
6
|
+
"massign",
|
7
|
+
"opassign"
|
8
|
+
];
|
2
9
|
|
3
10
|
// If you have a modifier statement (for instance an inline if statement or an
|
4
11
|
// inline while loop) there are times when you need to wrap the entire statement
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prettier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -28,6 +28,18 @@ files:
|
|
28
28
|
- lib/prettier/rake/task.rb
|
29
29
|
- node_modules/prettier/bin-prettier.js
|
30
30
|
- node_modules/prettier/index.js
|
31
|
+
- node_modules/prettier/parser-angular.js
|
32
|
+
- node_modules/prettier/parser-babel.js
|
33
|
+
- node_modules/prettier/parser-espree.js
|
34
|
+
- node_modules/prettier/parser-flow.js
|
35
|
+
- node_modules/prettier/parser-glimmer.js
|
36
|
+
- node_modules/prettier/parser-graphql.js
|
37
|
+
- node_modules/prettier/parser-html.js
|
38
|
+
- node_modules/prettier/parser-markdown.js
|
39
|
+
- node_modules/prettier/parser-meriyah.js
|
40
|
+
- node_modules/prettier/parser-postcss.js
|
41
|
+
- node_modules/prettier/parser-typescript.js
|
42
|
+
- node_modules/prettier/parser-yaml.js
|
31
43
|
- node_modules/prettier/third-party.js
|
32
44
|
- package.json
|
33
45
|
- rubocop.yml
|
@@ -44,11 +56,8 @@ files:
|
|
44
56
|
- src/haml/parser.js
|
45
57
|
- src/haml/parser.rb
|
46
58
|
- src/haml/printer.js
|
47
|
-
- src/parser/getLang.js
|
48
|
-
- src/parser/getNetcat.js
|
49
59
|
- src/parser/netcat.js
|
50
60
|
- src/parser/parseSync.js
|
51
|
-
- src/parser/requestParse.js
|
52
61
|
- src/parser/server.rb
|
53
62
|
- src/plugin.js
|
54
63
|
- src/prettier.js
|
@@ -100,7 +109,7 @@ files:
|
|
100
109
|
- src/utils/isEmptyBodyStmt.js
|
101
110
|
- src/utils/isEmptyStmts.js
|
102
111
|
- src/utils/literal.js
|
103
|
-
- src/utils/
|
112
|
+
- src/utils/literallineWithoutBreakParent.js
|
104
113
|
- src/utils/makeCall.js
|
105
114
|
- src/utils/noIndent.js
|
106
115
|
- src/utils/printEmptyCollection.js
|
@@ -124,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
133
|
- !ruby/object:Gem::Version
|
125
134
|
version: '0'
|
126
135
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
136
|
+
rubygems_version: 3.1.4
|
128
137
|
signing_key:
|
129
138
|
specification_version: 4
|
130
139
|
summary: prettier plugin for the Ruby programming language
|
data/src/parser/getLang.js
DELETED
@@ -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;
|
data/src/parser/getNetcat.js
DELETED
@@ -1,50 +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 getCommandAndArg() {
|
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 arg;
|
41
|
-
|
42
|
-
function getNetcat() {
|
43
|
-
if (!command) {
|
44
|
-
[command, arg] = getCommandAndArg();
|
45
|
-
}
|
46
|
-
|
47
|
-
return { command, arg };
|
48
|
-
}
|
49
|
-
|
50
|
-
module.exports = getNetcat;
|
data/src/parser/requestParse.js
DELETED
@@ -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) {
|
58
|
-
ensureParseServer();
|
59
|
-
|
60
|
-
const { command, arg } = getNetcat();
|
61
|
-
const { stdout, stderr, status } = spawnSync(command, [arg, 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;
|