prettier 1.1.0 → 1.2.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: 0110d43bf561f7af177d93dce16dd6c8802bff3eb5c6603f6b72460903186b43
4
- data.tar.gz: 48dd261628c7127b3baca0c6934c21993b68831c6d545494967642f5783e3d16
3
+ metadata.gz: c97988d5dd7fe35aa5fd73777f31f8217809ea0eee189cab7ac70c266569857b
4
+ data.tar.gz: 478c15e6cbd8d8efb16fc37e028afb8c88f3671aa77f36d3df0cd115b239c83a
5
5
  SHA512:
6
- metadata.gz: 2caa7e2cb715c7a3c1124210b1a2efa064425ef4b2075abd84b7092e28eae67c66fc1aabf93cd6c5493b86c5c735fe9965c9f0f347be4b57f5690f74690d79b4
7
- data.tar.gz: 16f4abe1b2ca8099660cd22a541bac6a220f661db879bf9742e85645abfe0cbf36146872c6dfe33af30bc5c8b303144720abe5233d4a1748390a7ff587e8c005
6
+ metadata.gz: 38ae06510c4872ba7f4ede36dc6b5f4aae3c7183c9c48b4e515733074e9ce27d2ddb4b189c25600d1daf123b8f5eccbb8b12c953e5192a62e08a63cb9716298e
7
+ data.tar.gz: 9456c53fe9ad823defb3d69fd4dd4504ee1e9d4af5d522fd8352141d61a5d975aa6043b62d78dd077f000258e400ee98fce8131ada5dac066021bb27e9f40de5
@@ -6,6 +6,13 @@ 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.0] - 2020-12-26
10
+
11
+ ### Added
12
+
13
+ - [@kddeisz] - Support for the `fndptn` node for Ruby 3.0 pattern matching.
14
+ - [@kddeisz] - Support for Ruby 3.0+ single-line method definitions.
15
+
9
16
  ## [1.1.0] - 2020-12-20
10
17
 
11
18
  ### Added
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/ruby.js",
6
6
  "scripts": {
@@ -31,9 +31,17 @@ function printOpAssign(path, opts, print) {
31
31
  );
32
32
  }
33
33
 
34
+ function printVarField(path, opts, print) {
35
+ if (path.getValue().body) {
36
+ return path.call(print, "body", 0);
37
+ }
38
+
39
+ return "*";
40
+ }
41
+
34
42
  module.exports = {
35
43
  assign: printAssign,
36
44
  opassign: printOpAssign,
37
- var_field: first,
45
+ var_field: printVarField,
38
46
  var_ref: first
39
47
  };
@@ -1,4 +1,4 @@
1
- const { concat, group, hardline, indent } = require("../prettier");
1
+ const { concat, group, hardline, indent, line } = require("../prettier");
2
2
  const { first } = require("../utils");
3
3
 
4
4
  function printMethod(offset) {
@@ -48,8 +48,17 @@ function printMethod(offset) {
48
48
  };
49
49
  }
50
50
 
51
+ function printSingleLineMethod(path, opts, print) {
52
+ const [nameDoc, stmtDoc] = path.map(print, "body");
53
+
54
+ return group(
55
+ concat(["def ", nameDoc, " =", indent(group(concat([line, stmtDoc])))])
56
+ );
57
+ }
58
+
51
59
  module.exports = {
52
60
  access_ctrl: first,
53
61
  def: printMethod(0),
54
- defs: printMethod(2)
62
+ defs: printMethod(2),
63
+ defsl: printSingleLineMethod
55
64
  };
@@ -48,6 +48,22 @@ function printAryPtn(path, opts, print) {
48
48
  return args;
49
49
  }
50
50
 
51
+ function printFndPtn(path, opts, print) {
52
+ const [constant] = path.getValue().body;
53
+
54
+ let args = [path.call(print, "body", 1)]
55
+ .concat(path.map(print, "body", 2))
56
+ .concat(path.call(print, "body", 3));
57
+
58
+ args = concat(["[", group(join(concat([",", line]), args)), "]"]);
59
+
60
+ if (constant) {
61
+ return concat([path.call(print, "body", 0), args]);
62
+ }
63
+
64
+ return args;
65
+ }
66
+
51
67
  function printHshPtn(path, opts, print) {
52
68
  const [constant, keyValuePairs, keyValueRest] = path.getValue().body;
53
69
  let args = [];
@@ -113,6 +129,7 @@ function printIn(path, opts, print) {
113
129
 
114
130
  module.exports = {
115
131
  aryptn: printAryPtn,
132
+ fndptn: printFndPtn,
116
133
  hshptn: printHshPtn,
117
134
  in: printIn
118
135
  };
@@ -814,18 +814,43 @@ class Prettier::Parser < Ripper
814
814
  # │ └> params
815
815
  # └> ident
816
816
  #
817
+ # You can also have single-line methods since Ruby 3.0+, which have slightly
818
+ # different syntax but still flow through this method. Those look like:
819
+ #
820
+ # def foo = bar
821
+ # | |
822
+ # | └> stmt
823
+ # └> ident
824
+ #
817
825
  def on_def(ident, params, bodystmt)
818
826
  # Make sure to delete this scanner event in case you're defining something
819
827
  # like def class which would lead to this being a kw and causing all kinds
820
828
  # of trouble
821
829
  scanner_events.delete(ident)
822
830
 
831
+ # Find the beginning of the method definition, which works for single-line
832
+ # and normal method definitions.
833
+ beging = find_scanner_event(:@kw, 'def')
834
+
835
+ # If there is not a params node, then we have a single-line method
836
+ unless params
837
+ return(
838
+ {
839
+ type: :defsl,
840
+ body: [ident, bodystmt],
841
+ start: beging[:start],
842
+ char_start: beging[:char_start],
843
+ end: bodystmt[:end],
844
+ char_end: bodystmt[:char_end]
845
+ }
846
+ )
847
+ end
848
+
823
849
  if params[:type] == :params && !params[:body].any?
824
850
  location = ident[:char_end]
825
851
  params.merge!(char_start: location, char_end: location)
826
852
  end
827
853
 
828
- beging = find_scanner_event(:@kw, 'def')
829
854
  ending = find_scanner_event(:@kw, 'end')
830
855
 
831
856
  bodystmt.bind(
@@ -1157,6 +1182,24 @@ class Prettier::Parser < Ripper
1157
1182
  }
1158
1183
  end
1159
1184
 
1185
+ # fndptn is a parser event that represents matching against a pattern where
1186
+ # you find a pattern in an array using the Ruby 3.0+ pattern matching syntax.
1187
+ def on_fndptn(const, presplat, args, postsplat)
1188
+ beging = const || find_scanner_event(:@lbracket)
1189
+ ending = find_scanner_event(:@rbracket)
1190
+
1191
+ pieces = [const, presplat, *args, postsplat].compact
1192
+
1193
+ {
1194
+ type: :fndptn,
1195
+ body: [const, presplat, args, postsplat],
1196
+ start: beging[:start],
1197
+ char_start: beging[:char_start],
1198
+ end: ending[:end],
1199
+ char_end: ending[:char_end]
1200
+ }
1201
+ end
1202
+
1160
1203
  # for is a parser event that represents using the somewhat esoteric for
1161
1204
  # loop. It accepts as arguments an ident which is the iterating variable,
1162
1205
  # an enumerable for that which is being enumerated, and a stmts event that
@@ -2306,7 +2349,7 @@ class Prettier::Parser < Ripper
2306
2349
  else
2307
2350
  # You can hit this pattern if you're assigning to a splat using pattern
2308
2351
  # matching syntax in Ruby 2.7+
2309
- { type: :var_field, body: [] }
2352
+ { type: :var_field, body: nil }
2310
2353
  end
2311
2354
  end
2312
2355
 
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.1.0
4
+ version: 1.2.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: 2020-12-20 00:00:00.000000000 Z
11
+ date: 2020-12-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: