prettier 0.13.0 → 0.14.0

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: d4d48bb295fd20db723ba6491459aa439df3258c9ccea2ebbca3d47e76001de4
4
- data.tar.gz: ac54ec92f5cfb7812419c04993c8113143bd0610a433969e96d5d2651a931974
3
+ metadata.gz: b8e2166de3bdb098137b5445e9db41d9c6eb1f1677fe8edfd9bbb7fb25704091
4
+ data.tar.gz: 8284b60434648ad65daae6a2d24677ec197cde21b986e69e88adcbc0560592bf
5
5
  SHA512:
6
- metadata.gz: 9dff32300805824e2ca6d0353ea17525f26dbbeea44140cd1c25bd65f28cd3a00b9b69d3702d4fce82bbfe65dee5464919f069d02d191b6a93fd15d4f2501284
7
- data.tar.gz: e71972c078fec8a949efe8398ad649b10e5f74860daa2789c891d613203dfb23d4568f9ce88a7c926886fce853c7e1423bf13c64e2262e39b1cf5c5c9bf19cdc
6
+ metadata.gz: 9d94d15c6f8c4b295596bfd821884937954ebc854cc6d2c292a8ea77a8ba23d99bf3c80cda43bcd8c5fb60b72e334b7f90ae18729b884c8c2a7eab6b44bda0d3
7
+ data.tar.gz: 563ab1b61b66e0ade505742063c9c949c16087942d68853eb07ec9ee4b4d56ec69219355ab80a230028efa44af1c9012a30c1556743f19025ffe625c8f2affbd
@@ -6,6 +6,46 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.14.0] - 2019-07-17
10
+
11
+ ### Added
12
+
13
+ - Support for pattern matching for variables and array patterns. Currently waiting on Ripper support for hash patterns. For examples, check out the [test/js/patterns.test.js](test/js/patterns.test.js) file.
14
+
15
+ ### Changed
16
+
17
+ - if/else blocks that had method calls on the end of them that were also transformed into ternaries need to have parens added to them. For example,
18
+
19
+ <!-- prettier-ignore -->
20
+ ```ruby
21
+ if foo
22
+ 1
23
+ else
24
+ 2
25
+ end.to_s
26
+ ```
27
+
28
+ now correctly gets transformed into:
29
+
30
+ <!-- prettier-ignore -->
31
+ ```ruby
32
+ (foo ? 1 : 2).to_s
33
+ ```
34
+
35
+ (Thanks to @jviney for the report.)
36
+
37
+ - Fixed a bug where multiple newlines at the end of the file would cause a crash. (Thanks to @acrewdson for the report.)
38
+ - If a variable is assigned inside of the predicate of a conditional, then we can't change it into the single-line version as this breaks. For example,
39
+
40
+ <!-- prettier-ignore -->
41
+ ```ruby
42
+ if foo = 1
43
+ foo
44
+ end
45
+ ```
46
+
47
+ must stay the same. (Thanks to @jviney for the report.)
48
+
9
49
  ## [0.13.0] - 2019-07-05
10
50
 
11
51
  ### Added
@@ -423,7 +463,8 @@ would previously result in `array[]`, but now prints properly. (Thanks to @xipgr
423
463
 
424
464
  - Initial release 🎉
425
465
 
426
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.13.0...HEAD
466
+ [unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.14.0...HEAD
467
+ [0.14.0]: https://github.com/prettier/plugin-ruby/compare/v0.13.0...v0.14.0
427
468
  [0.13.0]: https://github.com/prettier/plugin-ruby/compare/v0.12.3...v0.13.0
428
469
  [0.12.3]: https://github.com/prettier/plugin-ruby/compare/v0.12.2...v0.12.3
429
470
  [0.12.2]: https://github.com/prettier/plugin-ruby/compare/v0.12.1...v0.12.2
data/README.md CHANGED
@@ -182,6 +182,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
182
182
  <tr>
183
183
  <td align="center"><a href="https://janpiotrowski.de"><img src="https://avatars0.githubusercontent.com/u/183673?v=4" width="100px;" alt="Jan Piotrowski"/><br /><sub><b>Jan Piotrowski</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/commits?author=janpio" title="Documentation">📖</a></td>
184
184
  <td align="center"><a href="https://www.andywaite.com"><img src="https://avatars1.githubusercontent.com/u/13400?v=4" width="100px;" alt="Andy Waite"/><br /><sub><b>Andy Waite</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/commits?author=andyw8" title="Documentation">📖</a></td>
185
+ <td align="center"><a href="https://github.com/jviney"><img src="https://avatars3.githubusercontent.com/u/7051?v=4" width="100px;" alt="Jonathan Viney"/><br /><sub><b>Jonathan Viney</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Ajviney" title="Bug reports">🐛</a></td>
186
+ <td align="center"><a href="https://github.com/acrewdson"><img src="https://avatars0.githubusercontent.com/u/10353074?v=4" width="100px;" alt="acrewdson"/><br /><sub><b>acrewdson</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Aacrewdson" title="Bug reports">🐛</a></td>
185
187
  </tr>
186
188
  </table>
187
189
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/ruby.js",
6
6
  "scripts": {
@@ -20,6 +20,7 @@ module.exports = Object.assign(
20
20
  require("./nodes/methods"),
21
21
  require("./nodes/operators"),
22
22
  require("./nodes/params"),
23
+ require("./nodes/patterns"),
23
24
  require("./nodes/regexp"),
24
25
  require("./nodes/rescue"),
25
26
  require("./nodes/scopes"),
@@ -2,7 +2,7 @@ const { concat, group, indent, softline } = require("../prettier");
2
2
  const toProc = require("../toProc");
3
3
  const { concatBody, first, makeCall } = require("../utils");
4
4
 
5
- const noIndent = ["array", "hash", "method_add_block", "xstring_literal"];
5
+ const noIndent = ["array", "hash", "if", "method_add_block", "xstring_literal"];
6
6
 
7
7
  module.exports = {
8
8
  call: (path, opts, print) => {
@@ -113,11 +113,11 @@ const printSingle = keyword => (path, { inlineConditionals }, print) => {
113
113
  concat([softline, "end"])
114
114
  ]);
115
115
 
116
- const stmts = path.getValue().body[1];
116
+ const [predicate, stmts] = path.getValue().body;
117
117
  const hasComments =
118
118
  stmts.type === "stmts" && stmts.body.some(stmt => stmt.type === "@comment");
119
119
 
120
- if (!inlineConditionals || hasComments) {
120
+ if (!inlineConditionals || hasComments || predicate.type === "assign") {
121
121
  return multiline;
122
122
  }
123
123
 
@@ -154,17 +154,20 @@ const canTernary = path => {
154
154
  // A normalized print function for both `if` and `unless` nodes.
155
155
  const printConditional = keyword => (path, { inlineConditionals }, print) => {
156
156
  if (canTernary(path)) {
157
- const ternaryConditions = printTernaryClauses(
158
- keyword,
159
- path.call(print, "body", 1),
160
- path.call(print, "body", 2, "body", 0)
157
+ let ternaryParts = [path.call(print, "body", 0), " ? "].concat(
158
+ printTernaryClauses(
159
+ keyword,
160
+ path.call(print, "body", 1),
161
+ path.call(print, "body", 2, "body", 0)
162
+ )
161
163
  );
162
164
 
165
+ if (["binary", "call"].includes(path.getParentNode().type)) {
166
+ ternaryParts = ["("].concat(ternaryParts).concat(")");
167
+ }
168
+
163
169
  return group(
164
- ifBreak(
165
- printWithAddition(keyword, path, print),
166
- concat([path.call(print, "body", 0), " ? "].concat(ternaryConditions))
167
- )
170
+ ifBreak(printWithAddition(keyword, path, print), concat(ternaryParts))
168
171
  );
169
172
  }
170
173
 
@@ -0,0 +1,43 @@
1
+ const { concat, group, hardline, indent, join, line } = require("../prettier");
2
+
3
+ module.exports = {
4
+ aryptn: (path, opts, print) => {
5
+ const [constant, preargs, splatarg, postargs] = path.getValue().body;
6
+ let args = [];
7
+
8
+ if (preargs) {
9
+ args = args.concat(path.map(print, "body", 1));
10
+ }
11
+
12
+ if (splatarg) {
13
+ args.push(concat(["*", path.call(print, "body", 2)]));
14
+ }
15
+
16
+ if (postargs) {
17
+ args = args.concat(path.map(print, "body", 3));
18
+ }
19
+
20
+ args = group(join(concat([",", line]), args));
21
+
22
+ if (constant || path.getParentNode().type === "binary") {
23
+ args = concat(["[", args, "]"]);
24
+ }
25
+
26
+ if (constant) {
27
+ return concat([path.call(print, "body", 0), args]);
28
+ }
29
+
30
+ return args;
31
+ },
32
+ hshptn: () => {
33
+ throw new Error(
34
+ "Hash pattern not currently supported (https://bugs.ruby-lang.org/issues/16008)"
35
+ );
36
+ },
37
+ in: (path, opts, print) =>
38
+ concat([
39
+ "in ",
40
+ path.call(print, "body", 0),
41
+ indent(concat([hardline, path.call(print, "body", 1)]))
42
+ ])
43
+ };
@@ -123,9 +123,7 @@ class RipperJS < Ripper
123
123
  @scanner_events = []
124
124
  @line_counts = [0]
125
125
 
126
- source.split("\n").each do |line|
127
- line_counts << line_counts.last + line.size + 1
128
- end
126
+ source.lines.each { |line| line_counts << line_counts.last + line.size }
129
127
  end
130
128
 
131
129
  def self.prepended(base)
@@ -156,12 +154,6 @@ class RipperJS < Ripper
156
154
  scanner_events.delete_at(index)
157
155
  end
158
156
 
159
- # :backref, :const, :embdoc, :embdoc_beg, :embdoc_end,
160
- # :embexpr_beg, :embexpr_end, :embvar, :heredoc_beg, :heredoc_end,
161
- # :ident, :lbrace, :lbracket, :lparen, :op, :period, :regexp_beg,
162
- # :regexp_end, :rparen, :symbeg, :symbols_beg, :tlambda, :tlambeg,
163
- # :tstring_beg, :tstring_content, :tstring_end
164
-
165
157
  events = {
166
158
  BEGIN: [:@kw, 'BEGIN'],
167
159
  END: [:@kw, 'END'],
@@ -186,6 +178,7 @@ class RipperJS < Ripper
186
178
  for: [:@kw, 'for'],
187
179
  hash: :@lbrace,
188
180
  if: [:@kw, 'if'],
181
+ in: [:@kw, 'in'],
189
182
  kwrest_param: [:@op, '**'],
190
183
  lambda: :@tlambda,
191
184
  mlhs_paren: :@lparen,
@@ -253,6 +246,21 @@ class RipperJS < Ripper
253
246
  end
254
247
  end
255
248
 
249
+ # Array pattern nodes contain an odd mix of potential child nodes based on
250
+ # which kind of pattern is being used.
251
+ def on_aryptn(*body)
252
+ char_start, char_end = char_pos, char_pos
253
+
254
+ body.flatten(1).each do |part|
255
+ next unless part
256
+
257
+ char_start = [char_start, part[:char_start]].min
258
+ char_end = [char_end, part[:char_end]].max
259
+ end
260
+
261
+ super(*body).merge!(char_start: char_start, char_end: char_end)
262
+ end
263
+
256
264
  # Params have a somewhat interesting structure in that they are an array
257
265
  # of arrays where the position in the top-level array indicates the type
258
266
  # of param and the subarray is the list of parameters of that type. We
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: 0.13.0
4
+ version: 0.14.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: 2019-07-09 00:00:00.000000000 Z
11
+ date: 2019-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,7 @@ files:
94
94
  - src/nodes/methods.js
95
95
  - src/nodes/operators.js
96
96
  - src/nodes/params.js
97
+ - src/nodes/patterns.js
97
98
  - src/nodes/regexp.js
98
99
  - src/nodes/rescue.js
99
100
  - src/nodes/scopes.js