prettier 1.6.0 → 1.6.1

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.
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/plugin.js",
6
6
  "scripts": {
@@ -33,12 +33,23 @@ function printCall(path, opts, print) {
33
33
 
34
34
  // The right side of the call node, as in everything including the operator
35
35
  // and beyond.
36
- const rightSideDoc = concat([
36
+ let rightSideDoc = concat([
37
37
  receiverNode.comments ? hardline : softline,
38
38
  operatorDoc,
39
39
  messageDoc
40
40
  ]);
41
41
 
42
+ // This is very specialized behavior wherein we group .where.not calls
43
+ // together because it looks better. For more information, see
44
+ // https://github.com/prettier/plugin-ruby/issues/862.
45
+ if (
46
+ receiverNode.type === "call" &&
47
+ receiverNode.body[2].body === "where" &&
48
+ messageDoc === "not"
49
+ ) {
50
+ rightSideDoc = concat([operatorDoc, messageDoc]);
51
+ }
52
+
42
53
  // Get a reference to the parent node so we can check if we're inside a chain
43
54
  const parentNode = path.getParentNode();
44
55
 
@@ -110,9 +121,38 @@ function printMethodAddArg(path, opts, print) {
110
121
  parentNode.firstReceiverType = node.firstReceiverType;
111
122
  }
112
123
 
124
+ // This is the threshold at which we will start to try to make a nicely
125
+ // indented call chain. For the most part, it's always 3.
126
+ let threshold = 3;
127
+
128
+ // Here, we have very specialized behavior where if we're within a sig block,
129
+ // then we're going to assume we're creating a Sorbet type signature. In that
130
+ // case, we really want the threshold to be lowered to 2 so that we create
131
+ // method chains off of any two method calls within the block. For more
132
+ // details, see
133
+ // https://github.com/prettier/plugin-ruby/issues/863.
134
+ let sigBlock = path.getParentNode(2);
135
+ if (sigBlock) {
136
+ // If we're at a do_block, then we want to go one more level up. This is
137
+ // because do_blocks have bodystmt nodes instead of just stmt nodes.
138
+ if (sigBlock.type === "do_block") {
139
+ sigBlock = path.getParentNode(3);
140
+ }
141
+
142
+ if (
143
+ sigBlock.type === "method_add_block" &&
144
+ sigBlock.body[1] &&
145
+ sigBlock.body[0].type === "method_add_arg" &&
146
+ sigBlock.body[0].body[0].type === "fcall" &&
147
+ sigBlock.body[0].body[0].body[0].body === "sig"
148
+ ) {
149
+ threshold = 2;
150
+ }
151
+ }
152
+
113
153
  // If we're at the top of a chain, then we're going to print out a nice
114
154
  // multi-line layout if this doesn't break into multiple lines.
115
- if (!chained.includes(parentNode.type) && (node.chain || 0) >= 3) {
155
+ if (!chained.includes(parentNode.type) && (node.chain || 0) >= threshold) {
116
156
  // This is pretty specialized behavior. Basically if we're at the top of a
117
157
  // chain but we've only had method calls without arguments and now we have
118
158
  // arguments, then we're effectively trying to call a method with arguments
@@ -152,8 +152,10 @@ function printDynaSymbol(path, opts, print) {
152
152
  if (isQuoteLocked(node)) {
153
153
  if (node.quote.startsWith("%")) {
154
154
  quote = opts.rubySingleQuote ? "'" : '"';
155
- } else {
155
+ } else if (node.quote.startsWith(":")) {
156
156
  quote = node.quote.slice(1);
157
+ } else {
158
+ quote = node.quote;
157
159
  }
158
160
  } else {
159
161
  quote = opts.rubySingleQuote && isSingleQuotable(node) ? "'" : '"';
@@ -3,7 +3,6 @@ const noIndent = [
3
3
  "hash",
4
4
  "heredoc",
5
5
  "if",
6
- "method_add_block",
7
6
  "unless",
8
7
  "xstring_literal"
9
8
  ];
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.6.0
4
+ version: 1.6.1
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-06-23 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -27,7 +27,9 @@ files:
27
27
  - lib/prettier.rb
28
28
  - lib/prettier/rake/task.rb
29
29
  - node_modules/prettier/bin-prettier.js
30
+ - node_modules/prettier/doc.js
30
31
  - node_modules/prettier/index.js
32
+ - node_modules/prettier/package.json
31
33
  - node_modules/prettier/parser-angular.js
32
34
  - node_modules/prettier/parser-babel.js
33
35
  - node_modules/prettier/parser-espree.js