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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3abef3acea4e49130ba81afdb9bc00e73277c69e0254a1087b2c5e47feb5b104
4
- data.tar.gz: e851f061fc14352b7797ac0e2aca10c43f052b8bd19aa817473cfb6b75bde44c
3
+ metadata.gz: d7cbdd107fd5e3baad2ba213347858ef7eb45789ac6d716924b4df76f0c08eeb
4
+ data.tar.gz: af6af93bb28ec649ffddc3190f0a61fc9516cef6249f37968ab02e8c3606d80a
5
5
  SHA512:
6
- metadata.gz: 6fd8aba1071ff34709e7f3ad3ddd256cfbdc890ffb02fdef3d3567331a53d9b1974d02fd943ce03cab565822d750288bbe5582bc3c4a2d26bf0f170d2c3d15c6
7
- data.tar.gz: 8e66f396c113f162fb6c8c747a60d45dd38a554c13cab3ac1ae12456ff15fc49d2945ce69c1db53d89f1f82a69d0b30017ebfdcd99fbb2cb2fbbc29c4dbf398b
6
+ metadata.gz: 44e9831cbb10a8577f1bc7637775c9edf42765769338a355bb88b96cc6215f826a6ee7098eff1791c522c8d39d46c20a9f77082472704e7b10be04f37699d238
7
+ data.tar.gz: c2a7fe8fed19e9cefd90a322ab8e2bef45c83d360f07ba9f18d301961ca28e552719f7851fd27c2a9cb68c13d985dcd85555a345aa12ad9d0fe4ac2e10de531d
@@ -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.1.0...HEAD
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
 
@@ -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 : "'#{arg}'" }
13
- command = "node #{BINARY} --plugin '#{PLUGIN}' #{quoted.join(' ')}"
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/ruby.js",
6
6
  "scripts": {
@@ -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
- return ifBreak(
50
- group(indent(concat(node.breakDoc.concat(rightSideDoc)))),
51
- concat([receiverDoc, group(rightSideDoc)])
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.type === "brace_block"
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
@@ -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 statement = args.body[0].body[0].body[0];
17
- return (
18
- statement.type !== "binary" || !["and", "or"].includes(statement.body[1])
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
- // If the body of the return contains parens, then just skip directly to the
31
- // content of the parens so that we can skip printing parens if we don't
32
- // want them.
33
- if (args.body[0] && args.body[0].type === "paren" && canSkipParens(args)) {
34
- args = args.body[0].body[0];
35
- steps = steps.concat("body", 0, "body", 0);
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
- // If we're returning an array literal that isn't a special array, single
39
- // element array, or an empty array, then we want to grab the arguments so
40
- // that we can print them out as if they were normal return arguments.
41
- if (
42
- args.body[0] &&
43
- args.body[0].type === "array" &&
44
- args.body[0].body[0] &&
45
- args.body[0].body[0].body.length > 1 &&
46
- ["args", "args_add_star"].includes(args.body[0].body[0].type)
47
- ) {
48
- steps = steps.concat("body", 0, "body", 0);
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",
@@ -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
  {
@@ -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.1
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: 2020-12-27 00:00:00.000000000 Z
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.1.4
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