prettier 1.0.0 → 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: 1738251faac58ab78438da2dcf568a86708d1ccb651d7ec593f0e3c3efc5075a
4
- data.tar.gz: 91666c89e8846d9a908883339238dfec94816adb14c8949fe9232590e493c48b
3
+ metadata.gz: d7cbdd107fd5e3baad2ba213347858ef7eb45789ac6d716924b4df76f0c08eeb
4
+ data.tar.gz: af6af93bb28ec649ffddc3190f0a61fc9516cef6249f37968ab02e8c3606d80a
5
5
  SHA512:
6
- metadata.gz: d7df78d09da53ada78d9d9a0d3421e279bc0f1593aaff7a099ef397deea85f4fdde3a044ef91bb88f8f5d6a4f91d52d303e912e60f84b946c35528c0c6f139e1
7
- data.tar.gz: 95e810fa06b71063a010f8e3e3dd3cf7302e2cf1b3573f8da4b7e7fed9288ecaf4d75cbd6429c4b04dbc31728dc879cf1605c8c104fc130bdbfc30583c837e5b
6
+ metadata.gz: 44e9831cbb10a8577f1bc7637775c9edf42765769338a355bb88b96cc6215f826a6ee7098eff1791c522c8d39d46c20a9f77082472704e7b10be04f37699d238
7
+ data.tar.gz: c2a7fe8fed19e9cefd90a322ab8e2bef45c83d360f07ba9f18d301961ca28e552719f7851fd27c2a9cb68c13d985dcd85555a345aa12ad9d0fe4ac2e10de531d
@@ -6,6 +6,53 @@ 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
+
19
+ ## [1.2.1] - 2020-12-27
20
+
21
+ ### Changed
22
+
23
+ - [@kddeisz] - Handle single-line method definitions with parameters.
24
+ - [@kddeisz] - Handle hash and array patterns nested within find patterns.
25
+ - [@kddeisz] - Handle rightward assignment.
26
+ - [@kddeisz] - Handle find patterns with named boundaries.
27
+ - [@kddeisz] - Handle rightward assignment in conditionals.
28
+
29
+ ## [1.2.0] - 2020-12-26
30
+
31
+ ### Added
32
+
33
+ - [@kddeisz] - Support for the `fndptn` node for Ruby 3.0 pattern matching.
34
+ - [@kddeisz] - Support for Ruby 3.0+ single-line method definitions.
35
+
36
+ ## [1.1.0] - 2020-12-20
37
+
38
+ ### Added
39
+
40
+ - [@kddeisz] - Now that the comments are all fixed up, we can support `# prettier-ignore` comments.
41
+
42
+ ### Changed
43
+
44
+ - [@rindek], [@kddeisz] - Do not remove parentheses when receiver looks like a constant.
45
+ - [@rindek], [@kddeisz] - Do not remove parentheses when using the special `call` syntax with no arguments.
46
+ - [@ykpythemind] - Do not change regexp bounds if the body has certain content.
47
+ - [@karanmandal], [@kddeisz] - Correctly print for loops.
48
+ - [@rafbm], [@kddeisz] - If there are method chains with arguments only at the end, we should group the method chain and the method args.
49
+
50
+ ## [1.0.1] - 2020-12-12
51
+
52
+ ### Changed
53
+
54
+ - [@steobrien], [@kddeisz] - Ensure leading comments in empty array and hash literals do not duplicate.
55
+
9
56
  ## [1.0.0] - 2020-12-11
10
57
 
11
58
  ### Changed
@@ -951,7 +998,12 @@ would previously result in `array[]`, but now prints properly.
951
998
 
952
999
  - Initial release 🎉
953
1000
 
954
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.0.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
1005
+ [1.1.0]: https://github.com/prettier/plugin-ruby/compare/v1.0.1...v1.1.0
1006
+ [1.0.1]: https://github.com/prettier/plugin-ruby/compare/v1.0.0...v1.0.1
955
1007
  [1.0.0]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc2...v1.0.0
956
1008
  [1.0.0-rc2]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc1...v1.0.0-rc2
957
1009
  [1.0.0-rc1]: https://github.com/prettier/plugin-ruby/compare/v0.22.0...v1.0.0-rc1
@@ -1010,6 +1062,7 @@ would previously result in `array[]`, but now prints properly.
1010
1062
  [@andyw8]: https://github.com/andyw8
1011
1063
  [@ashfurrow]: https://github.com/ashfurrow
1012
1064
  [@awinograd]: https://github.com/awinograd
1065
+ [@blampe]: https://github.com/blampe
1013
1066
  [@bugthing]: https://github.com/bugthing
1014
1067
  [@cbothner]: https://github.com/cbothner
1015
1068
  [@christoomey]: https://github.com/christoomey
@@ -1038,6 +1091,7 @@ would previously result in `array[]`, but now prints properly.
1038
1091
  [@jpickwell]: https://github.com/jpickwell
1039
1092
  [@jrdioko]: https://github.com/jrdioko
1040
1093
  [@jviney]: https://github.com/jviney
1094
+ [@karanmandal]: https://github.com/karanmandal
1041
1095
  [@kddeisz]: https://github.com/kddeisz
1042
1096
  [@kmcq]: https://github.com/kmcq
1043
1097
  [@krachtstefan]: https://github.com/krachtstefan
@@ -1048,10 +1102,13 @@ would previously result in `array[]`, but now prints properly.
1048
1102
  [@meleyal]: https://github.com/meleyal
1049
1103
  [@mmainz]: https://github.com/mmainz
1050
1104
  [@mmcnl]: https://github.com/mmcnl
1105
+ [@nathan-beam]: https://github.com/nathan-beam
1051
1106
  [@noahtheduke]: https://github.com/NoahTheDuke
1052
1107
  [@overload119]: https://github.com/Overload119
1053
1108
  [@petevk]: https://github.com/petevk
1054
1109
  [@pje]: https://github.com/pje
1110
+ [@rafbm]: https://github.com/rafbm
1111
+ [@rindek]: https://github.com/rindek
1055
1112
  [@rosskinsella]: https://github.com/RossKinsella
1056
1113
  [@rsullivan00]: https://github.com/Rsullivan00
1057
1114
  [@ryan-hunter-pc]: https://github.com/ryan-hunter-pc
@@ -1061,4 +1118,5 @@ would previously result in `array[]`, but now prints properly.
1061
1118
  [@tobyndockerill]: https://github.com/tobyndockerill
1062
1119
  [@uri]: https://github.com/uri
1063
1120
  [@xipgroc]: https://github.com/xipgroc
1121
+ [@ykpythemind]: https://github.com/ykpythemind
1064
1122
  [@yuki24]: https://github.com/yuki24
data/README.md CHANGED
@@ -227,6 +227,11 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
227
227
  <tr>
228
228
  <td align="center"><a href="https://github.com/mmcnl"><img src="https://avatars2.githubusercontent.com/u/1498727?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Matt McNeil</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Ammcnl" title="Bug reports">🐛</a></td>
229
229
  <td align="center"><a href="https://github.com/johncsnyder"><img src="https://avatars2.githubusercontent.com/u/9882099?v=4?s=100" width="100px;" alt=""/><br /><sub><b>John Snyder</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Ajohncsnyder" title="Bug reports">🐛</a></td>
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
+ <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
+ <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>
230
235
  </tr>
231
236
  </table>
232
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
@@ -5249,19 +5249,19 @@ var errors = {
5249
5249
  UndefinedParserError
5250
5250
  };
5251
5251
 
5252
- /*! *****************************************************************************
5253
- Copyright (c) Microsoft Corporation.
5254
-
5255
- Permission to use, copy, modify, and/or distribute this software for any
5256
- purpose with or without fee is hereby granted.
5257
-
5258
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
5259
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
5260
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
5261
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
5262
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
5263
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
5264
- PERFORMANCE OF THIS SOFTWARE.
5252
+ /*! *****************************************************************************
5253
+ Copyright (c) Microsoft Corporation.
5254
+
5255
+ Permission to use, copy, modify, and/or distribute this software for any
5256
+ purpose with or without fee is hereby granted.
5257
+
5258
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
5259
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
5260
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
5261
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
5262
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
5263
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
5264
+ PERFORMANCE OF THIS SOFTWARE.
5265
5265
  ***************************************************************************** */
5266
5266
 
5267
5267
  /* global Reflect, Promise */
@@ -14638,7 +14638,6 @@ function printAstToDoc(ast, options, alignmentSize = 0) {
14638
14638
  } // We let JSXElement print its comments itself because it adds () around
14639
14639
  // UnionTypeAnnotation has to align the child without the comments
14640
14640
 
14641
-
14642
14641
  let res;
14643
14642
 
14644
14643
  if (printer.willPrintOwnComments && printer.willPrintOwnComments(path, options)) {
@@ -14675,6 +14674,7 @@ function printPrettierIgnoredNode(node, options) {
14675
14674
  locStart,
14676
14675
  locEnd
14677
14676
  } = options;
14677
+
14678
14678
  const start = locStart(node);
14679
14679
  const end = locEnd(node);
14680
14680
 
@@ -24808,11 +24808,11 @@ var ini = createCommonjsModule(function (module, exports) {
24808
24808
  });
24809
24809
 
24810
24810
  var fs = __importStar(fs__default['default']);
24811
- /**
24812
- * define the possible values:
24813
- * section: [section]
24814
- * param: key=value
24815
- * comment: ;this is a comment
24811
+ /**
24812
+ * define the possible values:
24813
+ * section: [section]
24814
+ * param: key=value
24815
+ * comment: ;this is a comment
24816
24816
  */
24817
24817
 
24818
24818
 
@@ -24821,9 +24821,9 @@ var ini = createCommonjsModule(function (module, exports) {
24821
24821
  param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
24822
24822
  comment: /^\s*[#;].*$/
24823
24823
  };
24824
- /**
24825
- * Parses an .ini file
24826
- * @param file The location of the .ini file
24824
+ /**
24825
+ * Parses an .ini file
24826
+ * @param file The location of the .ini file
24827
24827
  */
24828
24828
 
24829
24829
  function parse(file) {
@@ -29644,8 +29644,8 @@ var path_1 = createCommonjsModule(function (module, exports) {
29644
29644
  const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
29645
29645
 
29646
29646
  const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
29647
- /**
29648
- * Designed to work only with simple paths: `dir\\file`.
29647
+ /**
29648
+ * Designed to work only with simple paths: `dir\\file`.
29649
29649
  */
29650
29650
 
29651
29651
  function unixify(filepath) {
@@ -34268,17 +34268,17 @@ var pattern = createCommonjsModule(function (module, exports) {
34268
34268
  exports.isStaticPattern = isStaticPattern;
34269
34269
 
34270
34270
  function isDynamicPattern(pattern, options = {}) {
34271
- /**
34272
- * A special case with an empty string is necessary for matching patterns that start with a forward slash.
34273
- * An empty string cannot be a dynamic pattern.
34274
- * For example, the pattern `/lib/*` will be spread into parts: '', 'lib', '*'.
34271
+ /**
34272
+ * A special case with an empty string is necessary for matching patterns that start with a forward slash.
34273
+ * An empty string cannot be a dynamic pattern.
34274
+ * For example, the pattern `/lib/*` will be spread into parts: '', 'lib', '*'.
34275
34275
  */
34276
34276
  if (pattern === '') {
34277
34277
  return false;
34278
34278
  }
34279
- /**
34280
- * When the `caseSensitiveMatch` option is disabled, all patterns must be marked as dynamic, because we cannot check
34281
- * filepath directly (without read directory).
34279
+ /**
34280
+ * When the `caseSensitiveMatch` option is disabled, all patterns must be marked as dynamic, because we cannot check
34281
+ * filepath directly (without read directory).
34282
34282
  */
34283
34283
 
34284
34284
 
@@ -34389,17 +34389,17 @@ var pattern = createCommonjsModule(function (module, exports) {
34389
34389
  } = picomatch$1.scan(pattern, Object.assign(Object.assign({}, options), {
34390
34390
  parts: true
34391
34391
  }));
34392
- /**
34393
- * The scan method returns an empty array in some cases.
34394
- * See micromatch/picomatch#58 for more details.
34392
+ /**
34393
+ * The scan method returns an empty array in some cases.
34394
+ * See micromatch/picomatch#58 for more details.
34395
34395
  */
34396
34396
 
34397
34397
  if (parts.length === 0) {
34398
34398
  parts = [pattern];
34399
34399
  }
34400
- /**
34401
- * The scan method does not return an empty part for the pattern with a forward slash.
34402
- * This is another part of micromatch/picomatch#58.
34400
+ /**
34401
+ * The scan method does not return an empty part for the pattern with a forward slash.
34402
+ * This is another part of micromatch/picomatch#58.
34403
34403
  */
34404
34404
 
34405
34405
 
@@ -34804,8 +34804,8 @@ var constants$5 = createCommonjsModule(function (module, exports) {
34804
34804
  const SUPPORTED_MINOR_VERSION = 10;
34805
34805
  const IS_MATCHED_BY_MAJOR = MAJOR_VERSION > SUPPORTED_MAJOR_VERSION;
34806
34806
  const IS_MATCHED_BY_MAJOR_AND_MINOR = MAJOR_VERSION === SUPPORTED_MAJOR_VERSION && MINOR_VERSION >= SUPPORTED_MINOR_VERSION;
34807
- /**
34808
- * IS `true` for Node.js 10.10 and greater.
34807
+ /**
34808
+ * IS `true` for Node.js 10.10 and greater.
34809
34809
  */
34810
34810
 
34811
34811
  exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = IS_MATCHED_BY_MAJOR || IS_MATCHED_BY_MAJOR_AND_MINOR;
@@ -35894,9 +35894,9 @@ var matcher = createCommonjsModule(function (module, exports) {
35894
35894
  }
35895
35895
 
35896
35896
  _fillStorage() {
35897
- /**
35898
- * The original pattern may include `{,*,**,a/*}`, which will lead to problems with matching (unresolved level).
35899
- * So, before expand patterns with brace expansion into separated patterns.
35897
+ /**
35898
+ * The original pattern may include `{,*,**,a/*}`, which will lead to problems with matching (unresolved level).
35899
+ * So, before expand patterns with brace expansion into separated patterns.
35900
35900
  */
35901
35901
  const patterns = utils$3.pattern.expandPatternsWithBraceExpansion(this._patterns);
35902
35902
 
@@ -35958,12 +35958,12 @@ var partial = createCommonjsModule(function (module, exports) {
35958
35958
 
35959
35959
  for (const pattern of patterns) {
35960
35960
  const section = pattern.sections[0];
35961
- /**
35962
- * In this case, the pattern has a globstar and we must read all directories unconditionally,
35963
- * but only if the level has reached the end of the first group.
35964
- *
35965
- * fixtures/{a,b}/**
35966
- * ^ true/false ^ always true
35961
+ /**
35962
+ * In this case, the pattern has a globstar and we must read all directories unconditionally,
35963
+ * but only if the level has reached the end of the first group.
35964
+ *
35965
+ * fixtures/{a,b}/**
35966
+ * ^ true/false ^ always true
35967
35967
  */
35968
35968
 
35969
35969
  if (!pattern.complete && levels > section.length) {
@@ -36045,8 +36045,8 @@ var deep = createCommonjsModule(function (module, exports) {
36045
36045
  }
36046
36046
 
36047
36047
  _isSkippedByDeep(basePath, entryPath) {
36048
- /**
36049
- * Avoid unnecessary depth calculations when it doesn't matter.
36048
+ /**
36049
+ * Avoid unnecessary depth calculations when it doesn't matter.
36050
36050
  */
36051
36051
  if (this._settings.deep === Infinity) {
36052
36052
  return false;
@@ -36534,10 +36534,10 @@ async function FastGlob(source, options) {
36534
36534
  function stream(source, options) {
36535
36535
  assertPatternsInput(source);
36536
36536
  const works = getWorks(source, stream$5.default, options);
36537
- /**
36538
- * The stream returned by the provider cannot work with an asynchronous iterator.
36539
- * To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams.
36540
- * This affects performance (+25%). I don't see best solution right now.
36537
+ /**
36538
+ * The stream returned by the provider cannot work with an asynchronous iterator.
36539
+ * To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams.
36540
+ * This affects performance (+25%). I don't see best solution right now.
36541
36541
  */
36542
36542
 
36543
36543
  return utils$3.stream.merge(works);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "1.0.0",
3
+ "version": "1.2.2",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/ruby.js",
6
6
  "scripts": {
@@ -50,6 +50,8 @@
50
50
  }
51
51
  },
52
52
  "jest": {
53
+ "globalSetup": "./test/js/globalSetup.js",
54
+ "globalTeardown": "./test/js/globalTeardown.js",
53
55
  "setupFilesAfterEnv": [
54
56
  "./test/js/setupTests.js"
55
57
  ],
@@ -1,7 +1,6 @@
1
1
  const {
2
2
  concat,
3
3
  group,
4
- hardline,
5
4
  ifBreak,
6
5
  indent,
7
6
  join,
@@ -9,7 +8,7 @@ const {
9
8
  softline
10
9
  } = require("../prettier");
11
10
 
12
- const { getTrailingComma } = require("../utils");
11
+ const { getTrailingComma, printEmptyCollection } = require("../utils");
13
12
 
14
13
  // Checks that every argument within this args node is a string_literal node
15
14
  // that has no spaces or interpolations. This means we're dealing with an array
@@ -93,24 +92,6 @@ function printSpecialArray(start) {
93
92
  };
94
93
  }
95
94
 
96
- function printEmptyArrayWithComments(path, opts) {
97
- const arrayNode = path.getValue();
98
-
99
- const printComment = (commentPath, index) => {
100
- arrayNode.comments[index].printed = true;
101
- return opts.printer.printComment(commentPath);
102
- };
103
-
104
- return concat([
105
- "[",
106
- indent(
107
- concat([hardline, join(hardline, path.map(printComment, "comments"))])
108
- ),
109
- line,
110
- "]"
111
- ]);
112
- }
113
-
114
95
  // An array node is any literal array in Ruby. This includes all of the special
115
96
  // array literals as well as regular arrays. If it is a special array literal
116
97
  // then it will have one child that represents the special array, otherwise it
@@ -122,7 +103,7 @@ function printArray(path, opts, print) {
122
103
  // If there is no inner arguments node, then we're dealing with an empty
123
104
  // array, so we can go ahead and return.
124
105
  if (args === null) {
125
- return array.comments ? printEmptyArrayWithComments(path, opts) : "[]";
106
+ return printEmptyCollection(path, opts, "[", "]");
126
107
  }
127
108
 
128
109
  // If we have an array that contains only simple string literals with no
@@ -31,9 +31,13 @@ function printOpAssign(path, opts, print) {
31
31
  );
32
32
  }
33
33
 
34
+ function printVarField(path, opts, print) {
35
+ return path.getValue().body ? path.call(print, "body", 0) : "";
36
+ }
37
+
34
38
  module.exports = {
35
39
  assign: printAssign,
36
40
  opassign: printOpAssign,
37
- var_field: first,
41
+ var_field: printVarField,
38
42
  var_ref: first
39
43
  };
@@ -39,16 +39,20 @@ function printCall(path, opts, print) {
39
39
  // right side of the expression, as we want to have a nice multi-line layout.
40
40
  if (chained.includes(parentNode.type)) {
41
41
  parentNode.chain = (node.chain || 0) + 1;
42
+ parentNode.callChain = (node.callChain || 0) + 1;
42
43
  parentNode.breakDoc = (node.breakDoc || [receiverDoc]).concat(rightSideDoc);
44
+ parentNode.firstReceiverType = node.firstReceiverType || receiverNode.type;
43
45
  }
44
46
 
45
47
  // If we're at the top of a chain, then we're going to print out a nice
46
48
  // multi-line layout if this doesn't break into multiple lines.
47
49
  if (!chained.includes(parentNode.type) && (node.chain || 0) >= 3) {
48
- return ifBreak(
49
- group(indent(concat(node.breakDoc.concat(rightSideDoc)))),
50
- concat([receiverDoc, group(rightSideDoc)])
51
- );
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)]));
52
56
  }
53
57
 
54
58
  // For certain left sides of the call nodes, we want to attach directly to
@@ -62,13 +66,31 @@ function printCall(path, opts, print) {
62
66
 
63
67
  function printMethodAddArg(path, opts, print) {
64
68
  const node = path.getValue();
65
- const argNode = node.body[1];
66
69
 
70
+ const [methodNode, argNode] = node.body;
67
71
  const [methodDoc, argsDoc] = path.map(print, "body");
68
72
 
69
73
  // You can end up here if you have a method with a ? ending, presumably
70
- // because the parser knows that it cannot be a local variable.
74
+ // because the parser knows that it cannot be a local variable. You can also
75
+ // end up here if you are explicitly using an empty set of parentheses.
71
76
  if (argsDoc.length === 0) {
77
+ // If you're using an explicit set of parentheses on something that looks
78
+ // like a constant, then we need to match that in order to maintain valid
79
+ // Ruby. For example, you could do something like Foo(), on which we would
80
+ // need to keep the parentheses to make it look like a method call.
81
+ if (methodNode.type === "fcall" && methodNode.body[0].type === "@const") {
82
+ return concat([methodDoc, "()"]);
83
+ }
84
+
85
+ // If you're using an explicit set parentheses with the special call syntax,
86
+ // then we need to explicitly print out an extra set of parentheses. For
87
+ // example, if you call something like Foo.new.() (implicitly calling the
88
+ // #call method on a new instance of the Foo class), then we have to print
89
+ // out those parentheses, otherwise we'll end up with Foo.new.
90
+ if (methodNode.type === "call" && methodNode.body[2] === "call") {
91
+ return concat([methodDoc, "()"]);
92
+ }
93
+
72
94
  return methodDoc;
73
95
  }
74
96
 
@@ -86,11 +108,27 @@ function printMethodAddArg(path, opts, print) {
86
108
  if (chained.includes(parentNode.type)) {
87
109
  parentNode.chain = (node.chain || 0) + 1;
88
110
  parentNode.breakDoc = (node.breakDoc || [methodDoc]).concat(argsDoc);
111
+ parentNode.firstReceiverType = node.firstReceiverType;
89
112
  }
90
113
 
91
114
  // If we're at the top of a chain, then we're going to print out a nice
92
115
  // multi-line layout if this doesn't break into multiple lines.
93
116
  if (!chained.includes(parentNode.type) && (node.chain || 0) >= 3) {
117
+ // This is pretty specialized behavior. Basically if we're at the top of a
118
+ // chain but we've only had method calls without arguments and now we have
119
+ // arguments, then we're effectively trying to call a method with arguments
120
+ // that is nested under a bunch of stuff. So we group together to first part
121
+ // to make it so just the arguments break. This looks like, for example:
122
+ //
123
+ // config.action_dispatch.rescue_responses.merge!(
124
+ // 'ActiveRecord::ConnectionTimeoutError' => :service_unavailable,
125
+ // 'ActiveRecord::QueryCanceled' => :service_unavailable
126
+ // )
127
+ //
128
+ if (node.callChain === node.chain) {
129
+ return concat([group(indent(concat(node.breakDoc))), group(argsDoc)]);
130
+ }
131
+
94
132
  return ifBreak(
95
133
  group(indent(concat(node.breakDoc.concat(argsDoc)))),
96
134
  concat([methodDoc, argsDoc])
@@ -118,7 +156,7 @@ function isSorbetTypeAnnotation(node) {
118
156
  callNode.body[0].body[0].body === "sig" &&
119
157
  callNode.body[1].type === "args" &&
120
158
  callNode.body[1].body.length === 0 &&
121
- blockNode.type === "brace_block"
159
+ blockNode
122
160
  );
123
161
  }
124
162
 
@@ -164,6 +202,7 @@ function printMethodAddBlock(path, opts, print) {
164
202
  if (chained.includes(parentNode.type)) {
165
203
  parentNode.chain = (node.chain || 0) + 1;
166
204
  parentNode.breakDoc = (node.breakDoc || [callDoc]).concat(blockDoc);
205
+ parentNode.firstReceiverType = node.firstReceiverType;
167
206
  }
168
207
 
169
208
  // If we're at the top of a chain, then we're going to print out a nice