prettier 1.2.1 → 1.2.2
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 +16 -1
- data/README.md +2 -0
- data/lib/prettier.rb +2 -2
- data/package.json +1 -1
- data/src/nodes/calls.js +10 -5
- data/src/nodes/return.js +33 -22
- data/src/parser.rb +5 -0
- data/src/printer.js +32 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7cbdd107fd5e3baad2ba213347858ef7eb45789ac6d716924b4df76f0c08eeb
|
4
|
+
data.tar.gz: af6af93bb28ec649ffddc3190f0a61fc9516cef6249f37968ab02e8c3606d80a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44e9831cbb10a8577f1bc7637775c9edf42765769338a355bb88b96cc6215f826a6ee7098eff1791c522c8d39d46c20a9f77082472704e7b10be04f37699d238
|
7
|
+
data.tar.gz: c2a7fe8fed19e9cefd90a322ab8e2bef45c83d360f07ba9f18d301961ca28e552719f7851fd27c2a9cb68c13d985dcd85555a345aa12ad9d0fe4ac2e10de531d
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.2.2] - 2021-01-01
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- [@nathan-beam] - Gem does not work with CMD/Powershell.
|
14
|
+
- [@blampe], [@kddeisz] - Comments inside keyword parameters in method declarations are not printed.
|
15
|
+
- [@blampe], [@kddeisz] - `command_call` nodes with unary operators incorrectly parse their operator.
|
16
|
+
- [@blampe], [@kddeisz] - Returning multiple values where the first has parentheses was incorrectly removing the remaining values.
|
17
|
+
- [@johncsnyder], [@kddeisz] - Call chains whose left-most receiver is a no-indent expression should not indent their entire chain.
|
18
|
+
|
9
19
|
## [1.2.1] - 2020-12-27
|
10
20
|
|
11
21
|
### Changed
|
@@ -988,7 +998,10 @@ would previously result in `array[]`, but now prints properly.
|
|
988
998
|
|
989
999
|
- Initial release 🎉
|
990
1000
|
|
991
|
-
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.
|
1001
|
+
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.2.2...HEAD
|
1002
|
+
[1.2.2]: https://github.com/prettier/plugin-ruby/compare/v1.2.1...v1.2.2
|
1003
|
+
[1.2.1]: https://github.com/prettier/plugin-ruby/compare/v1.2.0...v1.2.1
|
1004
|
+
[1.2.0]: https://github.com/prettier/plugin-ruby/compare/v1.1.0...v1.2.0
|
992
1005
|
[1.1.0]: https://github.com/prettier/plugin-ruby/compare/v1.0.1...v1.1.0
|
993
1006
|
[1.0.1]: https://github.com/prettier/plugin-ruby/compare/v1.0.0...v1.0.1
|
994
1007
|
[1.0.0]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc2...v1.0.0
|
@@ -1049,6 +1062,7 @@ would previously result in `array[]`, but now prints properly.
|
|
1049
1062
|
[@andyw8]: https://github.com/andyw8
|
1050
1063
|
[@ashfurrow]: https://github.com/ashfurrow
|
1051
1064
|
[@awinograd]: https://github.com/awinograd
|
1065
|
+
[@blampe]: https://github.com/blampe
|
1052
1066
|
[@bugthing]: https://github.com/bugthing
|
1053
1067
|
[@cbothner]: https://github.com/cbothner
|
1054
1068
|
[@christoomey]: https://github.com/christoomey
|
@@ -1088,6 +1102,7 @@ would previously result in `array[]`, but now prints properly.
|
|
1088
1102
|
[@meleyal]: https://github.com/meleyal
|
1089
1103
|
[@mmainz]: https://github.com/mmainz
|
1090
1104
|
[@mmcnl]: https://github.com/mmcnl
|
1105
|
+
[@nathan-beam]: https://github.com/nathan-beam
|
1091
1106
|
[@noahtheduke]: https://github.com/NoahTheDuke
|
1092
1107
|
[@overload119]: https://github.com/Overload119
|
1093
1108
|
[@petevk]: https://github.com/petevk
|
data/README.md
CHANGED
@@ -230,6 +230,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
230
230
|
<td align="center"><a href="https://github.com/rindek"><img src="https://avatars1.githubusercontent.com/u/881209?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jacek Jakubik</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Arindek" title="Bug reports">🐛</a></td>
|
231
231
|
<td align="center"><a href="https://twitter.com/ykpythemind"><img src="https://avatars2.githubusercontent.com/u/22209702?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yukito Ito</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Aykpythemind" title="Bug reports">🐛</a> <a href="https://github.com/prettier/plugin-ruby/commits?author=ykpythemind" title="Code">💻</a></td>
|
232
232
|
<td align="center"><a href="https://studyfied.com/"><img src="https://avatars2.githubusercontent.com/u/45869605?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Karan Mandal</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Akaranmandal" title="Bug reports">🐛</a></td>
|
233
|
+
<td align="center"><a href="http://nathanbeam.codes/"><img src="https://avatars3.githubusercontent.com/u/24681333?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nathan Beam</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Anathan-beam" title="Bug reports">🐛</a> <a href="https://github.com/prettier/plugin-ruby/commits?author=nathan-beam" title="Code">💻</a></td>
|
234
|
+
<td align="center"><a href="https://github.com/blampe"><img src="https://avatars3.githubusercontent.com/u/848843?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Bryce Lampe</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Ablampe" title="Bug reports">🐛</a></td>
|
233
235
|
</tr>
|
234
236
|
</table>
|
235
237
|
|
data/lib/prettier.rb
CHANGED
@@ -9,8 +9,8 @@ module Prettier
|
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def run(args)
|
12
|
-
quoted = args.map { |arg| arg.start_with?('-') ? arg : "
|
13
|
-
command = "node #{BINARY} --plugin
|
12
|
+
quoted = args.map { |arg| arg.start_with?('-') ? arg : "\"#{arg}\"" }
|
13
|
+
command = "node #{BINARY} --plugin \"#{PLUGIN}\" #{quoted.join(' ')}"
|
14
14
|
|
15
15
|
system({ 'RBPRETTIER' => '1' }, command)
|
16
16
|
end
|
data/package.json
CHANGED
data/src/nodes/calls.js
CHANGED
@@ -41,15 +41,18 @@ function printCall(path, opts, print) {
|
|
41
41
|
parentNode.chain = (node.chain || 0) + 1;
|
42
42
|
parentNode.callChain = (node.callChain || 0) + 1;
|
43
43
|
parentNode.breakDoc = (node.breakDoc || [receiverDoc]).concat(rightSideDoc);
|
44
|
+
parentNode.firstReceiverType = node.firstReceiverType || receiverNode.type;
|
44
45
|
}
|
45
46
|
|
46
47
|
// If we're at the top of a chain, then we're going to print out a nice
|
47
48
|
// multi-line layout if this doesn't break into multiple lines.
|
48
49
|
if (!chained.includes(parentNode.type) && (node.chain || 0) >= 3) {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
let breakDoc = concat(node.breakDoc.concat(rightSideDoc));
|
51
|
+
if (!noIndent.includes(node.firstReceiverType)) {
|
52
|
+
breakDoc = indent(breakDoc);
|
53
|
+
}
|
54
|
+
|
55
|
+
return ifBreak(group(breakDoc), concat([receiverDoc, group(rightSideDoc)]));
|
53
56
|
}
|
54
57
|
|
55
58
|
// For certain left sides of the call nodes, we want to attach directly to
|
@@ -105,6 +108,7 @@ function printMethodAddArg(path, opts, print) {
|
|
105
108
|
if (chained.includes(parentNode.type)) {
|
106
109
|
parentNode.chain = (node.chain || 0) + 1;
|
107
110
|
parentNode.breakDoc = (node.breakDoc || [methodDoc]).concat(argsDoc);
|
111
|
+
parentNode.firstReceiverType = node.firstReceiverType;
|
108
112
|
}
|
109
113
|
|
110
114
|
// If we're at the top of a chain, then we're going to print out a nice
|
@@ -152,7 +156,7 @@ function isSorbetTypeAnnotation(node) {
|
|
152
156
|
callNode.body[0].body[0].body === "sig" &&
|
153
157
|
callNode.body[1].type === "args" &&
|
154
158
|
callNode.body[1].body.length === 0 &&
|
155
|
-
blockNode
|
159
|
+
blockNode
|
156
160
|
);
|
157
161
|
}
|
158
162
|
|
@@ -198,6 +202,7 @@ function printMethodAddBlock(path, opts, print) {
|
|
198
202
|
if (chained.includes(parentNode.type)) {
|
199
203
|
parentNode.chain = (node.chain || 0) + 1;
|
200
204
|
parentNode.breakDoc = (node.breakDoc || [callDoc]).concat(blockDoc);
|
205
|
+
parentNode.firstReceiverType = node.firstReceiverType;
|
201
206
|
}
|
202
207
|
|
203
208
|
// If we're at the top of a chain, then we're going to print out a nice
|
data/src/nodes/return.js
CHANGED
@@ -13,10 +13,13 @@ const { literal } = require("../utils");
|
|
13
13
|
// because they have low enough operator precedence that you need to explicitly
|
14
14
|
// keep them in there.
|
15
15
|
const canSkipParens = (args) => {
|
16
|
-
const
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
const stmts = args.body[0].body[0];
|
17
|
+
if (stmts.comments) {
|
18
|
+
return false;
|
19
|
+
}
|
20
|
+
|
21
|
+
const stmt = stmts.body[0];
|
22
|
+
return stmt.type !== "binary" || !["and", "or"].includes(stmt.body[1]);
|
20
23
|
};
|
21
24
|
|
22
25
|
const printReturn = (path, opts, print) => {
|
@@ -27,25 +30,27 @@ const printReturn = (path, opts, print) => {
|
|
27
30
|
return "return";
|
28
31
|
}
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
if (args.body.length === 1) {
|
34
|
+
// If the body of the return contains parens, then just skip directly to the
|
35
|
+
// content of the parens so that we can skip printing parens if we don't
|
36
|
+
// want them.
|
37
|
+
if (args.body[0] && args.body[0].type === "paren" && canSkipParens(args)) {
|
38
|
+
args = args.body[0].body[0];
|
39
|
+
steps = steps.concat("body", 0, "body", 0);
|
40
|
+
}
|
37
41
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
// If we're returning an array literal that isn't a special array, single
|
43
|
+
// element array, or an empty array, then we want to grab the arguments so
|
44
|
+
// that we can print them out as if they were normal return arguments.
|
45
|
+
if (
|
46
|
+
args.body[0] &&
|
47
|
+
args.body[0].type === "array" &&
|
48
|
+
args.body[0].body[0] &&
|
49
|
+
args.body[0].body[0].body.length > 1 &&
|
50
|
+
["args", "args_add_star"].includes(args.body[0].body[0].type)
|
51
|
+
) {
|
52
|
+
steps = steps.concat("body", 0, "body", 0);
|
53
|
+
}
|
49
54
|
}
|
50
55
|
|
51
56
|
// Now that we've established which actual node is the arguments to return,
|
@@ -56,6 +61,12 @@ const printReturn = (path, opts, print) => {
|
|
56
61
|
// be a singular doc as opposed to an array.
|
57
62
|
const value = Array.isArray(parts) ? join(concat([",", line]), parts) : parts;
|
58
63
|
|
64
|
+
// We only get here if we have comments somewhere that would prevent us from
|
65
|
+
// skipping the parentheses.
|
66
|
+
if (args.body.length === 1 && args.body[0].type === "paren") {
|
67
|
+
return concat(["return", value]);
|
68
|
+
}
|
69
|
+
|
59
70
|
return group(
|
60
71
|
concat([
|
61
72
|
"return",
|
data/src/parser.rb
CHANGED
@@ -753,6 +753,11 @@ class Prettier::Parser < Ripper
|
|
753
753
|
# of the method, the operator being used to send the method, the name of
|
754
754
|
# the method, and the arguments being passed to the method.
|
755
755
|
def on_command_call(receiver, oper, ident, args)
|
756
|
+
# Make sure we take the operator out of the scanner events so that it
|
757
|
+
# doesn't get confused for a unary operator later.
|
758
|
+
scanner_events.delete(oper)
|
759
|
+
|
760
|
+
# Grab the ending from either the arguments or the method being sent
|
756
761
|
ending = args || ident
|
757
762
|
|
758
763
|
{
|
data/src/printer.js
CHANGED
@@ -67,6 +67,38 @@ function getCommentChildNodes(node) {
|
|
67
67
|
|
68
68
|
return [node.body[0]].concat(values).concat(node.body[2]);
|
69
69
|
}
|
70
|
+
case "params": {
|
71
|
+
const [reqs, optls, rest, post, kwargs, kwargRest, block] = node.body;
|
72
|
+
let parts = reqs || [];
|
73
|
+
|
74
|
+
(optls || []).forEach((optl) => {
|
75
|
+
parts = parts.concat(optl);
|
76
|
+
});
|
77
|
+
|
78
|
+
if (rest) {
|
79
|
+
parts.push(rest);
|
80
|
+
}
|
81
|
+
|
82
|
+
parts = parts.concat(post || []);
|
83
|
+
|
84
|
+
(kwargs || []).forEach((kwarg) => {
|
85
|
+
if (kwarg[1]) {
|
86
|
+
parts = parts.concat(kwarg);
|
87
|
+
} else {
|
88
|
+
parts.push(kwarg[0]);
|
89
|
+
}
|
90
|
+
});
|
91
|
+
|
92
|
+
if (kwargRest && kwargRest !== "nil") {
|
93
|
+
parts.push(kwargRest);
|
94
|
+
}
|
95
|
+
|
96
|
+
if (block) {
|
97
|
+
parts.push(block);
|
98
|
+
}
|
99
|
+
|
100
|
+
return parts;
|
101
|
+
}
|
70
102
|
default:
|
71
103
|
return node.body;
|
72
104
|
}
|
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.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.2.3
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: prettier plugin for the Ruby programming language
|