prettier 2.0.0.pre.rc1 → 2.0.0.pre.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1015fa9f7c5b4f580afa9c6b24042c8799762e5d13835dbb492abfe33f676b8
4
- data.tar.gz: 53045f82f75561082c6120d836d3abdffb07cccb31e5272442ef2608014f8f6d
3
+ metadata.gz: 63604b2dbf27994c44f507ef2e0b22d257c5371f45e66a78fa805c82313c5166
4
+ data.tar.gz: 546196f52a8a0ac8034e8cf4d170f61a916f9948f109d9bba18ff0d60160b100
5
5
  SHA512:
6
- metadata.gz: 4f4541af3e4e4047f03c4c34890506b25126d34e052b92023d40e7bb68b5184cfce9c91ba5794478b21b61952e1823d4f7e08d51b52d468a9de61f270f9d61a0
7
- data.tar.gz: 983d6da92e456dae0f081a2ee4b77f4a47d540415f991c51d91006a2847ac38937574e76f82bd376fb9e47401deeb5bd77414c10b3ab80a9d4adaa7a7e66499e
6
+ metadata.gz: 034daa67861d8ac125b501dc00729b3830889a9182befa40c147f4459118b62565cc1ff458ed691a6e16d290f3ba2690aa241a620f38cfe17970fd5660a332aa
7
+ data.tar.gz: 7d5d1bd5e45859d32df6d7bc151fc229bcec702d5eb556b16b5b21a58986f5d319d891aa082aff1eac68a962b120593415fa0160b37e8ee99e835453a6fec4ee
data/CHANGELOG.md CHANGED
@@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.0.0-rc2]
10
+
11
+ ### Added
12
+
13
+ - [#979](https://github.com/prettier/plugin-ruby/issues/979) - ronocod, kddnewton - Alignment of `to_not` is explicitly allowed to not indent to better support rspec.
14
+ - [#894](https://github.com/prettier/plugin-ruby/issues/894) - mister-what, kddnewton - Add a warning that this plugin will not function with the plug'n'play filesystem provided by yarn berry.
15
+
16
+ ### Changed
17
+
18
+ - [#943](https://github.com/prettier/plugin-ruby/issues/943) - valscion, kddnewton - Trailing call operators that are followed by comments should stay on the first line.
19
+
9
20
  ## [2.0.0-rc1]
10
21
 
11
22
  ### Added
@@ -1151,7 +1162,8 @@ would previously result in `array[]`, but now prints properly.
1151
1162
 
1152
1163
  - Initial release 🎉
1153
1164
 
1154
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc1...HEAD
1165
+ [unreleased]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc2...HEAD
1166
+ [2.0.0-rc2]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc1...v2.0.0-rc2
1155
1167
  [2.0.0-rc1]: https://github.com/prettier/plugin-ruby/compare/v1.6.1...v2.0.0-rc1
1156
1168
  [1.6.1]: https://github.com/prettier/plugin-ruby/compare/v1.6.0...v1.6.1
1157
1169
  [1.6.0]: https://github.com/prettier/plugin-ruby/compare/v1.5.5...v1.6.0
@@ -95,12 +95,26 @@ function spawnServer() {
95
95
  const [cmd, ...args] = info.stdout.toString().split(" ");
96
96
  return { cmd, args };
97
97
  }
98
+ // If we're in a yarn Plug'n'Play environment, then the relative paths being
99
+ // used by the parser server and the various scripts used to communicate
100
+ // therein are not going to work with its virtual file system. Presumably
101
+ // there's a way to fix this but I haven't figured out how yet.
102
+ function checkPnP() {
103
+ if (process_1.default.versions.pnp) {
104
+ throw new Error(`
105
+ @prettier/plugin-ruby does not current work within the yarn Plug'n'Play
106
+ virtual file system. If you would like to help support the effort to fix
107
+ this, please see https://github.com/prettier/plugin-ruby/issues/894.
108
+ `);
109
+ }
110
+ }
98
111
  // Formats and sends a request to the parser server. We use netcat (or something
99
112
  // like it) here since Prettier requires the results of `parse` to be
100
113
  // synchronous and Node.js does not offer a mechanism for synchronous socket
101
114
  // requests.
102
115
  function parseSync(parser, source) {
103
116
  if (!parserArgs) {
117
+ checkPnP();
104
118
  parserArgs = spawnServer();
105
119
  }
106
120
  const response = (0, child_process_1.spawnSync)(parserArgs.cmd, parserArgs.args, {
@@ -9,6 +9,10 @@ const utils_1 = require("../../utils");
9
9
  const toProc_1 = __importDefault(require("../toProc"));
10
10
  const { group, hardline, ifBreak, indent, join, softline } = prettier_1.default;
11
11
  const chained = ["call", "method_add_arg", "method_add_block"];
12
+ function hasLeadingComments(node) {
13
+ var _a;
14
+ return (_a = node.comments) === null || _a === void 0 ? void 0 : _a.some(({ leading }) => leading);
15
+ }
12
16
  const printCall = (path, opts, print) => {
13
17
  const node = path.getValue();
14
18
  const [receiverNode, , messageNode] = node.body;
@@ -18,26 +22,40 @@ const printCall = (path, opts, print) => {
18
22
  // In this case, "call" is returned for the 3rd child node. We don't alter
19
23
  // call syntax so if `call` is implicit, we don't print it out.
20
24
  const messageDoc = messageNode === "call" ? "" : path.call(print, "body", 2);
25
+ // Create some arrays that are going to represent each side of our call.
26
+ let leftSideDoc = [receiverDoc];
27
+ let rightSideDoc = [operatorDoc, messageDoc];
28
+ // If there are leading comments on the right side of the call, then it means
29
+ // we have a structure where there's a receiver and an operator together, then
30
+ // a comment, then the message, as in:
31
+ //
32
+ // foo.
33
+ // # comment
34
+ // baz
35
+ //
36
+ // In the case we need to group the receiver and the operator together or
37
+ // we'll end up with a syntax error.
38
+ const operatorIsTrailing = messageNode !== "call" && hasLeadingComments(messageNode);
39
+ if (operatorIsTrailing) {
40
+ leftSideDoc = [receiverDoc, operatorDoc];
41
+ rightSideDoc = [messageDoc];
42
+ }
21
43
  // For certain left sides of the call nodes, we want to attach directly to
22
44
  // the } or end.
23
45
  if (utils_1.noIndent.includes(receiverNode.type)) {
24
- return [receiverDoc, operatorDoc, messageDoc];
46
+ return [leftSideDoc, rightSideDoc];
25
47
  }
26
- // The right side of the call node, as in everything including the operator
27
- // and beyond.
28
- let rightSideDoc = [
29
- receiverNode.comments ? hardline : softline,
30
- operatorDoc,
31
- messageDoc
32
- ];
33
- // This is very specialized behavior wherein we group .where.not calls
34
- // together because it looks better. For more information, see
35
- // https://github.com/prettier/plugin-ruby/issues/862.
36
48
  if (receiverNode.type === "call" &&
37
49
  receiverNode.body[2] !== "call" &&
38
50
  receiverNode.body[2].body === "where" &&
39
51
  messageDoc === "not") {
40
- rightSideDoc = [operatorDoc, messageDoc];
52
+ // This is very specialized behavior wherein we group .where.not calls
53
+ // together because it looks better. For more information, see
54
+ // https://github.com/prettier/plugin-ruby/issues/862.
55
+ }
56
+ else {
57
+ // Otherwise, we're going to put a line node into the right side doc.
58
+ rightSideDoc.unshift(receiverNode.comments ? hardline : softline);
41
59
  }
42
60
  // Get a reference to the parent node so we can check if we're inside a chain
43
61
  const parentNode = path.getParentNode();
@@ -46,8 +64,30 @@ const printCall = (path, opts, print) => {
46
64
  if (chained.includes(parentNode.type) && !node.comments) {
47
65
  parentNode.chain = (node.chain || 0) + 1;
48
66
  parentNode.callChain = (node.callChain || 0) + 1;
49
- parentNode.breakDoc = (node.breakDoc || [receiverDoc]).concat(rightSideDoc);
50
67
  parentNode.firstReceiverType = node.firstReceiverType || receiverNode.type;
68
+ // Here we're going to determine what doc nodes to send up to the parent
69
+ // node to represent when we're in the multi-line form.
70
+ let breakDocLHS;
71
+ if (node.breakDoc && operatorIsTrailing) {
72
+ // Here we already have a child node that has passed up its
73
+ // representation. In this case node.breakDoc represents the receiver
74
+ // without any lines inserted. With regard to this node, it means it's
75
+ // everything up until the operator. So we're just going to append the
76
+ // operator.
77
+ breakDocLHS = node.breakDoc.concat(operatorDoc);
78
+ }
79
+ else if (node.breakDoc) {
80
+ // Here we don't need a trailing operator, so we're just going to use the
81
+ // existing node.breakDoc. The operator will be a part of the rightSideDoc
82
+ // variable.
83
+ breakDocLHS = node.breakDoc;
84
+ }
85
+ else {
86
+ // Here we're at the bottom of the chain, so there's no representation yet
87
+ // for the receiver. So we're just going to pass up the left side.
88
+ breakDocLHS = leftSideDoc;
89
+ }
90
+ parentNode.breakDoc = breakDocLHS.concat(rightSideDoc);
51
91
  }
52
92
  // If we're at the top of a chain, then we're going to print out a nice
53
93
  // multi-line layout if this doesn't break into multiple lines.
@@ -55,11 +95,11 @@ const printCall = (path, opts, print) => {
55
95
  (node.chain || 0) >= 3 &&
56
96
  node.breakDoc) {
57
97
  return ifBreak(group(indent(node.breakDoc.concat(rightSideDoc))), [
58
- receiverDoc,
98
+ leftSideDoc,
59
99
  group(rightSideDoc)
60
100
  ]);
61
101
  }
62
- return group([receiverDoc, group(indent(rightSideDoc))]);
102
+ return group([leftSideDoc, group(indent(rightSideDoc))]);
63
103
  };
64
104
  exports.printCall = printCall;
65
105
  const printMethodAddArg = (path, opts, print) => {
@@ -62,8 +62,8 @@ function hasDef(node) {
62
62
  //
63
63
  // In this case the arguments are aligned to the left side as opposed to being
64
64
  // aligned with the `receive` call.
65
- function skipArgsAlign(path) {
66
- return ["to", "not_to"].includes(path.getValue().body[2].body);
65
+ function skipArgsAlign(node) {
66
+ return ["to", "not_to", "to_not"].includes(node.body[2].body);
67
67
  }
68
68
  // If there is a ternary argument to a command and it's going to get broken
69
69
  // into multiple lines, then we're going to have to use parentheses around the
@@ -110,7 +110,7 @@ const printCommandCall = (path, opts, print) => {
110
110
  breakDoc = parts.concat("(", indent([softline, argDocs]), softline, ")");
111
111
  parts.push(" ");
112
112
  }
113
- else if (skipArgsAlign(path)) {
113
+ else if (skipArgsAlign(node)) {
114
114
  parts.push(" ");
115
115
  breakDoc = parts.concat(argDocs);
116
116
  }
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "2.0.0-rc1",
3
+ "version": "2.0.0-rc2",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "dist/plugin.js",
6
6
  "scripts": {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prettier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.rc1
4
+ version: 2.0.0.pre.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton