prettier 1.2.3 → 1.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +349 -358
- data/README.md +21 -93
- data/node_modules/prettier/index.js +54 -54
- data/package.json +1 -2
- data/rubocop.yml +26 -0
- data/src/haml/embed.js +87 -0
- data/src/haml/nodes/comment.js +27 -0
- data/src/haml/nodes/doctype.js +34 -0
- data/src/haml/nodes/filter.js +16 -0
- data/src/haml/nodes/hamlComment.js +21 -0
- data/src/haml/nodes/plain.js +6 -0
- data/src/haml/nodes/root.js +8 -0
- data/src/haml/nodes/script.js +33 -0
- data/src/haml/nodes/silentScript.js +59 -0
- data/src/haml/nodes/tag.js +193 -0
- data/src/haml/parser.js +22 -0
- data/src/haml/parser.rb +138 -0
- data/src/haml/printer.js +28 -0
- data/src/parser/getLang.js +32 -0
- data/src/parser/getNetcat.js +50 -0
- data/src/parser/netcat.js +15 -0
- data/src/parser/parseSync.js +33 -0
- data/src/parser/requestParse.js +74 -0
- data/src/parser/server.rb +61 -0
- data/src/plugin.js +26 -4
- data/src/prettier.js +1 -0
- data/src/rbs/parser.js +39 -0
- data/src/rbs/parser.rb +94 -0
- data/src/rbs/printer.js +605 -0
- data/src/ruby/embed.js +58 -8
- data/src/ruby/nodes/args.js +20 -6
- data/src/ruby/nodes/blocks.js +64 -59
- data/src/ruby/nodes/calls.js +12 -43
- data/src/ruby/nodes/class.js +17 -27
- data/src/ruby/nodes/commands.js +7 -2
- data/src/ruby/nodes/conditionals.js +1 -1
- data/src/ruby/nodes/hashes.js +28 -14
- data/src/ruby/nodes/hooks.js +9 -19
- data/src/ruby/nodes/loops.js +4 -10
- data/src/ruby/nodes/methods.js +8 -17
- data/src/ruby/nodes/params.js +22 -14
- data/src/ruby/nodes/patterns.js +9 -5
- data/src/ruby/nodes/rescue.js +32 -25
- data/src/ruby/nodes/return.js +0 -4
- data/src/ruby/nodes/statements.js +11 -13
- data/src/ruby/nodes/strings.js +27 -35
- data/src/ruby/parser.js +2 -49
- data/src/ruby/parser.rb +256 -232
- data/src/ruby/printer.js +0 -2
- data/src/ruby/toProc.js +4 -8
- data/src/utils.js +1 -0
- data/src/utils/isEmptyBodyStmt.js +7 -0
- data/src/utils/isEmptyStmts.js +9 -5
- data/src/utils/makeCall.js +3 -0
- data/src/utils/noIndent.js +1 -0
- data/src/utils/printEmptyCollection.js +9 -2
- metadata +26 -2
data/src/ruby/printer.js
CHANGED
data/src/ruby/toProc.js
CHANGED
@@ -12,15 +12,11 @@ const isCall = (node) => ["::", "."].includes(node) || node.type === "@period";
|
|
12
12
|
//
|
13
13
|
// This works with `do` blocks as well.
|
14
14
|
const toProc = (path, node) => {
|
15
|
-
if (!node) {
|
16
|
-
return null;
|
17
|
-
}
|
18
|
-
|
19
15
|
const [variables, blockContents] = node.body;
|
20
16
|
|
21
17
|
// Ensure that there are variables being passed to this block.
|
22
18
|
const params = variables && variables.body[0];
|
23
|
-
if (!params
|
19
|
+
if (!params) {
|
24
20
|
return null;
|
25
21
|
}
|
26
22
|
|
@@ -39,7 +35,7 @@ const toProc = (path, node) => {
|
|
39
35
|
if (blockContents.type === "bodystmt") {
|
40
36
|
// We’re in a `do` block
|
41
37
|
const blockStatements = blockContents.body[0];
|
42
|
-
const rescueElseEnsure =
|
38
|
+
const rescueElseEnsure = blockContents.body.slice(1);
|
43
39
|
|
44
40
|
// You can’t use the to_proc shortcut if you’re rescuing
|
45
41
|
if (rescueElseEnsure.some(Boolean)) {
|
@@ -84,7 +80,7 @@ const toProc = (path, node) => {
|
|
84
80
|
|
85
81
|
if (path.getValue().type === "method_add_block") {
|
86
82
|
assocNode = path.getParentNode();
|
87
|
-
} else
|
83
|
+
} else {
|
88
84
|
assocNode = path.getParentNode(2);
|
89
85
|
}
|
90
86
|
|
@@ -97,7 +93,7 @@ const toProc = (path, node) => {
|
|
97
93
|
|
98
94
|
if (
|
99
95
|
key.type === "symbol_literal" &&
|
100
|
-
["if", "unless"].includes(key.body[0].body
|
96
|
+
["if", "unless"].includes(key.body[0].body)
|
101
97
|
) {
|
102
98
|
return null;
|
103
99
|
}
|
data/src/utils.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module.exports = {
|
2
2
|
containsAssignment: require("./utils/containsAssignment"),
|
3
3
|
getTrailingComma: require("./utils/getTrailingComma"),
|
4
|
+
isEmptyBodyStmt: require("./utils/isEmptyBodyStmt"),
|
4
5
|
isEmptyStmts: require("./utils/isEmptyStmts"),
|
5
6
|
hasAncestor: require("./utils/hasAncestor"),
|
6
7
|
literal: require("./utils/literal"),
|
data/src/utils/isEmptyStmts.js
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
function isEmptyStmts(node) {
|
2
|
+
return (
|
3
|
+
node &&
|
4
|
+
node.type === "stmts" &&
|
5
|
+
node.body.length === 1 &&
|
6
|
+
node.body[0].type === "void_stmt" &&
|
7
|
+
!node.body[0].comments
|
8
|
+
);
|
9
|
+
}
|
6
10
|
|
7
11
|
module.exports = isEmptyStmts;
|
data/src/utils/makeCall.js
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
function makeCall(path, opts, print) {
|
2
2
|
const operation = path.getValue().body[1];
|
3
3
|
|
4
|
+
// Ignoring the next block for coverage information because it's only relevant
|
5
|
+
// in Ruby 2.5 and below.
|
6
|
+
/* istanbul ignore next */
|
4
7
|
if ([".", "&."].includes(operation)) {
|
5
8
|
return operation;
|
6
9
|
}
|
data/src/utils/noIndent.js
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
const { concat, group, hardline, indent, join, line } = require("../prettier");
|
2
2
|
|
3
|
+
function containedWithin(node) {
|
4
|
+
return function containedWithinNode(comment) {
|
5
|
+
return comment.sc >= node.sc && comment.ec <= node.ec;
|
6
|
+
};
|
7
|
+
}
|
8
|
+
|
3
9
|
// Empty collections are array or hash literals that do not contain any
|
4
10
|
// contents. They can, however, have comments inside the body. You can solve
|
5
11
|
// this by having a child node inside the array that gets the comments attached
|
@@ -7,11 +13,12 @@ const { concat, group, hardline, indent, join, line } = require("../prettier");
|
|
7
13
|
// print out the non-leading comments here.
|
8
14
|
function printEmptyCollection(path, opts, startToken, endToken) {
|
9
15
|
const node = path.getValue();
|
16
|
+
const containedWithinNode = containedWithin(node);
|
10
17
|
|
11
18
|
// If there are no comments or only leading comments, then we can just print
|
12
19
|
// out the start and end token and be done, as there are no comments inside
|
13
20
|
// the body of this node.
|
14
|
-
if (!node.comments || !node.comments.some(
|
21
|
+
if (!node.comments || !node.comments.some(containedWithinNode)) {
|
15
22
|
return `${startToken}${endToken}`;
|
16
23
|
}
|
17
24
|
|
@@ -21,7 +28,7 @@ function printEmptyCollection(path, opts, startToken, endToken) {
|
|
21
28
|
const printComment = (commentPath) => {
|
22
29
|
const comment = commentPath.getValue();
|
23
30
|
|
24
|
-
if (
|
31
|
+
if (containedWithinNode(comment)) {
|
25
32
|
comment.printed = true;
|
26
33
|
comments.push(opts.printer.printComment(commentPath));
|
27
34
|
}
|
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.
|
4
|
+
version: 1.5.0
|
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-01-
|
11
|
+
date: 2021-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -30,8 +30,31 @@ files:
|
|
30
30
|
- node_modules/prettier/index.js
|
31
31
|
- node_modules/prettier/third-party.js
|
32
32
|
- package.json
|
33
|
+
- rubocop.yml
|
34
|
+
- src/haml/embed.js
|
35
|
+
- src/haml/nodes/comment.js
|
36
|
+
- src/haml/nodes/doctype.js
|
37
|
+
- src/haml/nodes/filter.js
|
38
|
+
- src/haml/nodes/hamlComment.js
|
39
|
+
- src/haml/nodes/plain.js
|
40
|
+
- src/haml/nodes/root.js
|
41
|
+
- src/haml/nodes/script.js
|
42
|
+
- src/haml/nodes/silentScript.js
|
43
|
+
- src/haml/nodes/tag.js
|
44
|
+
- src/haml/parser.js
|
45
|
+
- src/haml/parser.rb
|
46
|
+
- src/haml/printer.js
|
47
|
+
- src/parser/getLang.js
|
48
|
+
- src/parser/getNetcat.js
|
49
|
+
- src/parser/netcat.js
|
50
|
+
- src/parser/parseSync.js
|
51
|
+
- src/parser/requestParse.js
|
52
|
+
- src/parser/server.rb
|
33
53
|
- src/plugin.js
|
34
54
|
- src/prettier.js
|
55
|
+
- src/rbs/parser.js
|
56
|
+
- src/rbs/parser.rb
|
57
|
+
- src/rbs/printer.js
|
35
58
|
- src/ruby/embed.js
|
36
59
|
- src/ruby/nodes.js
|
37
60
|
- src/ruby/nodes/alias.js
|
@@ -74,6 +97,7 @@ files:
|
|
74
97
|
- src/utils/getTrailingComma.js
|
75
98
|
- src/utils/hasAncestor.js
|
76
99
|
- src/utils/inlineEnsureParens.js
|
100
|
+
- src/utils/isEmptyBodyStmt.js
|
77
101
|
- src/utils/isEmptyStmts.js
|
78
102
|
- src/utils/literal.js
|
79
103
|
- src/utils/literalLineNoBreak.js
|