prettier 0.12.2 → 0.12.3

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: e5c497d3b03fb7fff00e144eeb766f83e8f14908836d01246d9525582572c50e
4
- data.tar.gz: f941eb2e4b5739e01dc082b6ba215950835b8208c73f86481dec3ea3f5f036cb
3
+ metadata.gz: 2ad3bf2a469895aec98cbf18d946801ac1d3e4193752e4255aca13042a3bd75f
4
+ data.tar.gz: 9b4e4fa497a06c2e2e2475e1ce10aea29b4c852a6eae7150ff8da3f39da3c60d
5
5
  SHA512:
6
- metadata.gz: 884ce77a4f9b37979701b1e0cd8c99f97b49905b469b4acc7929284a0c48cc378b3f900656c885955e99ab0475dfef673123d4f7dc6fd937461c6430de7a7753
7
- data.tar.gz: 30fae9b3033f03f708be4d82508e6be78cfc25f48cb47b8a90e27f165b29ba21154cdcbf943811cc1801b08ef085fceccb28deea7d79d92f8ee026ff310e41d5
6
+ metadata.gz: 2967c369962a05b9b35bea2e23d100b2b5229e2dc3830d26c7c7b279fd768dae27afe34e93e55ba0a1a4bb1164a47d7644cf98b3462e6dd897228ef2a3c14c86
7
+ data.tar.gz: f89e8b4df94cd5a0b94ad78302ddf70838a46e16cb01418e76fb5fbb5f04e987f6a1570dddcf9efea39868b2426a1866f64bdc69214aeec576ac08351e8c323e
data/CHANGELOG.md CHANGED
@@ -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
+ ## [0.12.3] - 2019-05-16
10
+
11
+ ### Changed
12
+
13
+ - [INTERNAL] Move arg, assign, constant, flow, massign, operator, scope, and statement nodes into their own files.
14
+ - [INTERNAL] Move `@int`, `access_ctrl`, `assocsplat`, `block_var`, `else`, `number_arg`, `super`, `undef`, `var_ref`, and `var_ref` as well as various call and symbol nodes into appropriate files.
15
+ - Better support for excessed commas in block args. Previously `proc { |x,| }` would add an extra space, but now it does not.
16
+ - [INTERNAL] Add a lot more documentation to the parser.
17
+ - Previously, the unary `not` operator inside a ternary (e.g., `a ? not(b) : c`) would break because it wouldn't add parentheses, but now it adds them. (Thanks to @glejeune for the report.)
18
+ - `if` and `unless` nodes used to not be able to handle if a comment was the only statement in the body. For example,
19
+
20
+ <!-- prettier-ignore -->
21
+ ```ruby
22
+ if foo
23
+ # comment
24
+ end
25
+ ```
26
+
27
+ would get printed as
28
+
29
+ <!-- prettier-ignore -->
30
+ ```ruby
31
+ # comment if foo
32
+ ```
33
+
34
+ Now the `if` and `unless` printers check for the presence of single comments.
35
+
36
+ - Fixes an error where `command` nodes within `def` nodes would fail to format if it was only a single block argument. For example,
37
+
38
+ <!-- prettier-ignore -->
39
+ ```ruby
40
+ def curry(&block)
41
+ new &block
42
+ end
43
+ ```
44
+
45
+ would fail, but now works. (Thanks to @JoshuaKGoldberg for the report.)
46
+
47
+ - Comments on lines with array references were previously deleting the array references entirely. For example,
48
+
49
+ <!-- prettier-ignore -->
50
+ ```ruby
51
+ array[index] # comment
52
+ ```
53
+
54
+ would previously result in `array[]`, but now prints properly. (Thanks to @xipgroc for the report.)
55
+
9
56
  ## [0.12.2] - 2019-04-30
10
57
 
11
58
  ### Changed
@@ -334,7 +381,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
334
381
 
335
382
  - Initial release 🎉
336
383
 
337
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.12.2...HEAD
384
+ [unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.12.3...HEAD
385
+ [0.12.3]: https://github.com/prettier/plugin-ruby/compare/v0.12.2...v0.12.3
338
386
  [0.12.2]: https://github.com/prettier/plugin-ruby/compare/v0.12.1...v0.12.2
339
387
  [0.12.1]: https://github.com/prettier/plugin-ruby/compare/v0.12.0...v0.12.1
340
388
  [0.12.0]: https://github.com/prettier/plugin-ruby/compare/v0.11.0...v0.12.0
data/CONTRIBUTING.md CHANGED
@@ -6,7 +6,7 @@ Want to contribute? There's a few moving parts that you'll need to know about:
6
6
  - Prettier - Provides building blocks for formatting documents in a stylistic way
7
7
  - Testing - Ensuring that there are no formatting or semantic regressions
8
8
 
9
- Your input Ruby code is parsed by Ripper, and pretty printed using the building blocks provided by Prettier. To ensure there are no regressions, Jest snapshots are used to keep track of the formatting before and after. Additionally there are Ruby tests written with Minitest to ensure there are no semantic regressions after the code has been tidied up.
9
+ Your input Ruby code is parsed by Ripper, and pretty printed using the building blocks provided by Prettier. Jest tests are used to protect against regressions and allow for test driving the development.
10
10
 
11
11
  ## Ripper
12
12
 
data/README.md CHANGED
@@ -22,9 +22,7 @@
22
22
  </a>
23
23
  </p>
24
24
 
25
- `@prettier/plugin-ruby` is a [prettier](https://prettier.io/) plugin for the Ruby programming language. `prettier` is an opinionated code formatter that supports multiple languages and integrates with most editors. The idea is to eliminate discussions of style in code review and allow developers to get back to thinking about code design instead.
26
-
27
- Under the hood `@prettier/plugin-ruby` uses Ruby's own `ripper` library which allows this package to maintain parity with the existing Ruby parser. `@prettier/plugin-ruby` supports Ruby versions `2.5`, `2.6`, and `trunk`.
25
+ `@prettier/plugin-ruby` is a [prettier](https://prettier.io/) plugin for the Ruby programming language (versions `2.5` and above). `prettier` is an opinionated code formatter that supports multiple languages and integrates with most editors. The idea is to eliminate discussions of style in code review and allow developers to get back to thinking about code design instead.
28
26
 
29
27
  For example, the below [code segment](http://www.rubyinside.com/advent2006/4-ruby-obfuscation.html):
30
28
 
@@ -70,35 +68,53 @@ end
70
68
 
71
69
  ## Getting started
72
70
 
73
- First, your system on which you're running is going to need a couple of things:
71
+ To run `prettier` with the Ruby plugin, you're going to need [`ruby`](https://www.ruby-lang.org/en/documentation/installation/) (version `2.5` or newer) and [`node`](https://nodejs.org/en/download/) (version `8.3` or newer). If you're integrating with a project that is not already using `prettier`, you should use the ruby gem. Otherwise you can use the `npm` package directly.
72
+
73
+ ### Ruby gem
74
74
 
75
- - [`ruby`](https://www.ruby-lang.org/en/documentation/installation/) `2.5` or newer - there are a lot of ways to install `ruby`, but I recommend [`rbenv`](https://github.com/rbenv/rbenv)
76
- - [`node`](https://nodejs.org/en/download/) `8.3` or newer - `prettier` is a JavaScript package, so you're going to need to install `node` to work with it
77
- - [`npm`](https://www.npmjs.com/get-npm) or [`yarn`](https://yarnpkg.com/en/docs/getting-started) - these are package managers for JavaScript, either one will do
75
+ Add this line to your application's Gemfile:
78
76
 
79
- Second, you're going to need to list `@prettier/plugin-ruby` as a JavaScript dependency from within whatever project on which you're working.
77
+ ```ruby
78
+ gem 'prettier'
79
+ ```
80
80
 
81
- If you do not already have a `package.json` file in the root of your repository, you can create one with:
81
+ And then execute:
82
82
 
83
83
  ```bash
84
- echo '{ "name": "My Project" }' > package.json
84
+ bundle
85
85
  ```
86
86
 
87
- After that you can add `prettier` and `@prettier/plugin-ruby` to your `package.json`'s `devDependencies` by running `npm install --save-dev prettier @prettier/plugin-ruby` if you are using `npm` or `yarn add --dev prettier @prettier/plugin-ruby` if you are using `yarn`.
87
+ Or install it yourself as:
88
88
 
89
- Now, you can run `prettier` to tidy up your `ruby` files! Verify by running against one single file:
89
+ ```bash
90
+ gem install prettier
91
+ ```
92
+
93
+ The `rbprettier` executable is now installed and ready for use:
90
94
 
91
95
  ```bash
92
- ./node_modules/.bin/prettier --write path/to/file.rb
96
+ bundle exec rbprettier --write '**/*.rb'
93
97
  ```
94
98
 
95
- If you're happy, you can can run `prettier` on an entire codebase:
99
+ ### `npm` package
100
+
101
+ If you're using the `npm` CLI, then add the plugin by:
96
102
 
97
103
  ```bash
98
- ./node_modules/.bin/prettier --write '**/*.{rb,rake}'
104
+ npm install --save-dev prettier @prettier/plugin-ruby
99
105
  ```
100
106
 
101
- Note that you can also install `prettier` globally with `npm install -g prettier @prettier/plugin-ruby` or you can add `./node_modules/.bin` to your `$PATH` so you don't need to reference the executable from the directory each time.
107
+ Or if you're using `yarn`, then add the plugin by:
108
+
109
+ ```bash
110
+ yarn add --dev prettier @prettier/plugin-ruby
111
+ ```
112
+
113
+ The `prettier` executable is now installed and ready for use:
114
+
115
+ ```bash
116
+ ./node_modules/.bin/prettier --write '**/*.rb'
117
+ ```
102
118
 
103
119
  ## Configuration
104
120
 
@@ -127,7 +143,7 @@ file](https://prettier.io/docs/en/configuration.html). For example:
127
143
  Or, they can be passed to `prettier` as arguments:
128
144
 
129
145
  ```bash
130
- ./node_modules/.bin/prettier --prefer-single-quotes false --write '**/*.{rb,rake}'
146
+ prettier --prefer-single-quotes false --write '**/*.rb'
131
147
  ```
132
148
 
133
149
  ## Contributing
@@ -144,7 +160,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
144
160
 
145
161
  <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
146
162
  <!-- prettier-ignore -->
147
- <table><tr><td align="center"><a href="https://kevindeisz.com"><img src="https://avatars2.githubusercontent.com/u/5093358?v=4" width="100px;" alt="Kevin Deisz"/><br /><sub><b>Kevin Deisz</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Code">💻</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Documentation">📖</a> <a href="#maintenance-kddeisz" title="Maintenance">🚧</a> <a href="#review-kddeisz" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Tests">⚠️</a></td><td align="center"><a href="https://www.alanfoster.me/"><img src="https://avatars2.githubusercontent.com/u/1271782?v=4" width="100px;" alt="Alan Foster"/><br /><sub><b>Alan Foster</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Code">💻</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Documentation">📖</a> <a href="#review-AlanFoster" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/johnschoeman"><img src="https://avatars0.githubusercontent.com/u/16049495?v=4" width="100px;" alt="johnschoeman"/><br /><sub><b>johnschoeman</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=johnschoeman" title="Tests">⚠️</a></td><td align="center"><a href="https://twitter.com/aaronjensen"><img src="https://avatars3.githubusercontent.com/u/8588?v=4" width="100px;" alt="Aaron Jensen"/><br /><sub><b>Aaron Jensen</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=aaronjensen" title="Documentation">📖</a></td><td align="center"><a href="http://cameronbothner.com"><img src="https://avatars1.githubusercontent.com/u/4642599?v=4" width="100px;" alt="Cameron Bothner"/><br /><sub><b>Cameron Bothner</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=cbothner" title="Code">💻</a></td><td align="center"><a href="https://localhost.dev"><img src="https://avatars3.githubusercontent.com/u/47308085?v=4" width="100px;" alt="localhost.dev"/><br /><sub><b>localhost.dev</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Alocalhostdotdev" title="Bug reports">🐛</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=localhostdotdev" title="Code">💻</a></td><td align="center"><a href="https://deecewan.github.io"><img src="https://avatars0.githubusercontent.com/u/4755785?v=4" width="100px;" alt="David Buchan-Swanson"/><br /><sub><b>David Buchan-Swanson</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Adeecewan" title="Bug reports">🐛</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=deecewan" title="Code">💻</a></td></tr><tr><td align="center"><a href="https://github.com/jpickwell"><img src="https://avatars1.githubusercontent.com/u/4682321?v=4" width="100px;" alt="Jordan Pickwell"/><br /><sub><b>Jordan Pickwell</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Ajpickwell" title="Bug reports">🐛</a></td><td align="center"><a href="http://codingitwrong.com"><img src="https://avatars0.githubusercontent.com/u/15832198?v=4" width="100px;" alt="Josh Justice"/><br /><sub><b>Josh Justice</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3ACodingItWrong" title="Bug reports">🐛</a></td><td align="center"><a href="https://github.com/xipgroc"><img src="https://avatars0.githubusercontent.com/u/28561131?v=4" width="100px;" alt="xipgroc"/><br /><sub><b>xipgroc</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Axipgroc" title="Bug reports">🐛</a></td></tr></table>
163
+ <table><tr><td align="center"><a href="https://kevindeisz.com"><img src="https://avatars2.githubusercontent.com/u/5093358?v=4" width="100px;" alt="Kevin Deisz"/><br /><sub><b>Kevin Deisz</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Code">💻</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Documentation">📖</a> <a href="#maintenance-kddeisz" title="Maintenance">🚧</a> <a href="#review-kddeisz" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=kddeisz" title="Tests">⚠️</a></td><td align="center"><a href="https://www.alanfoster.me/"><img src="https://avatars2.githubusercontent.com/u/1271782?v=4" width="100px;" alt="Alan Foster"/><br /><sub><b>Alan Foster</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Code">💻</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Documentation">📖</a> <a href="#review-AlanFoster" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=AlanFoster" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/johnschoeman"><img src="https://avatars0.githubusercontent.com/u/16049495?v=4" width="100px;" alt="johnschoeman"/><br /><sub><b>johnschoeman</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=johnschoeman" title="Tests">⚠️</a></td><td align="center"><a href="https://twitter.com/aaronjensen"><img src="https://avatars3.githubusercontent.com/u/8588?v=4" width="100px;" alt="Aaron Jensen"/><br /><sub><b>Aaron Jensen</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=aaronjensen" title="Documentation">📖</a></td><td align="center"><a href="http://cameronbothner.com"><img src="https://avatars1.githubusercontent.com/u/4642599?v=4" width="100px;" alt="Cameron Bothner"/><br /><sub><b>Cameron Bothner</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/commits?author=cbothner" title="Code">💻</a></td><td align="center"><a href="https://localhost.dev"><img src="https://avatars3.githubusercontent.com/u/47308085?v=4" width="100px;" alt="localhost.dev"/><br /><sub><b>localhost.dev</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Alocalhostdotdev" title="Bug reports">🐛</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=localhostdotdev" title="Code">💻</a></td><td align="center"><a href="https://deecewan.github.io"><img src="https://avatars0.githubusercontent.com/u/4755785?v=4" width="100px;" alt="David Buchan-Swanson"/><br /><sub><b>David Buchan-Swanson</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Adeecewan" title="Bug reports">🐛</a> <a href="https://github.com/kddeisz/plugin-ruby/commits?author=deecewan" title="Code">💻</a></td></tr><tr><td align="center"><a href="https://github.com/jpickwell"><img src="https://avatars1.githubusercontent.com/u/4682321?v=4" width="100px;" alt="Jordan Pickwell"/><br /><sub><b>Jordan Pickwell</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Ajpickwell" title="Bug reports">🐛</a></td><td align="center"><a href="http://codingitwrong.com"><img src="https://avatars0.githubusercontent.com/u/15832198?v=4" width="100px;" alt="Josh Justice"/><br /><sub><b>Josh Justice</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3ACodingItWrong" title="Bug reports">🐛</a></td><td align="center"><a href="https://github.com/xipgroc"><img src="https://avatars0.githubusercontent.com/u/28561131?v=4" width="100px;" alt="xipgroc"/><br /><sub><b>xipgroc</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Axipgroc" title="Bug reports">🐛</a></td><td align="center"><a href="http://lejeun.es"><img src="https://avatars1.githubusercontent.com/u/15168?v=4" width="100px;" alt="Gregoire Lejeune"/><br /><sub><b>Gregoire Lejeune</b></sub></a><br /><a href="https://github.com/kddeisz/plugin-ruby/issues?q=author%3Aglejeune" title="Bug reports">🐛</a></td></tr></table>
148
164
 
149
165
  <!-- ALL-CONTRIBUTORS-LIST:END -->
150
166
 
@@ -14,7 +14,7 @@ var thirdParty__default = thirdParty['default'];
14
14
  var readline = _interopDefault(require('readline'));
15
15
 
16
16
  var name = "prettier";
17
- var version$1 = "1.17.0";
17
+ var version$1 = "1.17.1";
18
18
  var description = "Prettier is an opinionated code formatter";
19
19
  var bin = {
20
20
  "prettier": "./bin/prettier.js"
@@ -110,7 +110,7 @@ var devDependencies = {
110
110
  "jest-snapshot-serializer-raw": "1.1.0",
111
111
  "jest-watch-typeahead": "0.1.0",
112
112
  "mkdirp": "0.5.1",
113
- "prettier": "1.16.4",
113
+ "prettier": "1.17.0",
114
114
  "prettylint": "1.0.0",
115
115
  "rimraf": "2.6.2",
116
116
  "rollup": "0.47.6",
@@ -13965,7 +13965,6 @@ function formatRange(text, opts) {
13965
13965
  var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
13966
13966
  rangeStart: 0,
13967
13967
  rangeEnd: Infinity,
13968
- printWidth: opts.printWidth - alignmentSize,
13969
13968
  // track the cursor offset only if it's within our range
13970
13969
  cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
13971
13970
  }), alignmentSize); // Since the range contracts to avoid trailing whitespace,
@@ -22827,27 +22826,36 @@ var utils$4 = {
22827
22826
 
22828
22827
  var hasFlowShorthandAnnotationComment$1 = utils$4.hasFlowShorthandAnnotationComment;
22829
22828
 
22830
- function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
22829
+ function hasClosureCompilerTypeCastComment(text, path$$1) {
22831
22830
  // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
22832
22831
  // Syntax example: var x = /** @type {string} */ (fruit);
22833
22832
  var n = path$$1.getValue();
22834
- return util$1.getNextNonSpaceNonCommentCharacter(text, n, locEnd) === ")" && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
22833
+ return isParenthesized(n) && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
22835
22834
 
22836
22835
  function hasAncestorTypeCastComment(index) {
22837
22836
  var ancestor = path$$1.getParentNode(index);
22838
- return ancestor && util$1.getNextNonSpaceNonCommentCharacter(text, ancestor, locEnd) !== ")" && /^[\s(]*$/.test(text.slice(locStart(ancestor), locStart(n))) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
22837
+ return ancestor && !isParenthesized(ancestor) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
22839
22838
  }
22840
22839
 
22841
22840
  function hasTypeCastComment(node) {
22842
22841
  return node.comments && node.comments.some(function (comment) {
22843
- return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value) && util$1.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
22842
+ return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value);
22844
22843
  });
22845
22844
  }
22846
22845
 
22846
+ function isParenthesized(node) {
22847
+ // Closure typecast comments only really make sense when _not_ using
22848
+ // typescript or flow parsers, so we take advantage of the babel parser's
22849
+ // parenthesized expressions.
22850
+ return node.extra && node.extra.parenthesized;
22851
+ }
22852
+
22847
22853
  function isTypeCastComment(comment) {
22848
- var trimmed = comment.trim();
22854
+ var cleaned = comment.trim().split("\n").map(function (line) {
22855
+ return line.replace(/^[\s*]+/, "");
22856
+ }).join(" ").trim();
22849
22857
 
22850
- if (!/^\*\s*@type\s*\{[^]+\}$/.test(trimmed)) {
22858
+ if (!/^@type\s+\{[^]+\}$/.test(cleaned)) {
22851
22859
  return false;
22852
22860
  }
22853
22861
 
@@ -22858,7 +22866,7 @@ function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
22858
22866
  var _iteratorError = undefined;
22859
22867
 
22860
22868
  try {
22861
- for (var _iterator = trimmed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
22869
+ for (var _iterator = cleaned[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
22862
22870
  var char = _step.value;
22863
22871
 
22864
22872
  if (char === "{") {
@@ -22926,7 +22934,7 @@ function needsParens(path$$1, options) {
22926
22934
  // parentheses.
22927
22935
 
22928
22936
 
22929
- if (hasClosureCompilerTypeCastComment(options.originalText, path$$1, options.locStart, options.locEnd)) {
22937
+ if (hasClosureCompilerTypeCastComment(options.originalText, path$$1)) {
22930
22938
  return true;
22931
22939
  }
22932
22940
 
@@ -23237,6 +23245,7 @@ function needsParens(path$$1, options) {
23237
23245
  case "TSAsExpression":
23238
23246
  case "TSNonNullExpression":
23239
23247
  case "BindExpression":
23248
+ case "OptionalMemberExpression":
23240
23249
  return true;
23241
23250
 
23242
23251
  case "MemberExpression":
@@ -30230,8 +30239,8 @@ function print(path$$1, options, print) {
30230
30239
  case "BlockStatement":
30231
30240
  {
30232
30241
  var pp = path$$1.getParentNode(1);
30233
- var isElseIf = pp && pp.inverse && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
30234
- var hasElseIf = n.inverse && n.inverse.body[0] && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
30242
+ var isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
30243
+ var hasElseIf = n.inverse && n.inverse.body.length === 1 && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
30235
30244
  var indentElse = hasElseIf ? function (a) {
30236
30245
  return a;
30237
30246
  } : indent$6;
@@ -12,7 +12,7 @@ var thirdParty = require('./third-party');
12
12
  var thirdParty__default = thirdParty['default'];
13
13
 
14
14
  var name = "prettier";
15
- var version$1 = "1.17.0";
15
+ var version$1 = "1.17.1";
16
16
  var description = "Prettier is an opinionated code formatter";
17
17
  var bin = {
18
18
  "prettier": "./bin/prettier.js"
@@ -108,7 +108,7 @@ var devDependencies = {
108
108
  "jest-snapshot-serializer-raw": "1.1.0",
109
109
  "jest-watch-typeahead": "0.1.0",
110
110
  "mkdirp": "0.5.1",
111
- "prettier": "1.16.4",
111
+ "prettier": "1.17.0",
112
112
  "prettylint": "1.0.0",
113
113
  "rimraf": "2.6.2",
114
114
  "rollup": "0.47.6",
@@ -13963,7 +13963,6 @@ function formatRange(text, opts) {
13963
13963
  var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
13964
13964
  rangeStart: 0,
13965
13965
  rangeEnd: Infinity,
13966
- printWidth: opts.printWidth - alignmentSize,
13967
13966
  // track the cursor offset only if it's within our range
13968
13967
  cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
13969
13968
  }), alignmentSize); // Since the range contracts to avoid trailing whitespace,
@@ -22825,27 +22824,36 @@ var utils$4 = {
22825
22824
 
22826
22825
  var hasFlowShorthandAnnotationComment$1 = utils$4.hasFlowShorthandAnnotationComment;
22827
22826
 
22828
- function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
22827
+ function hasClosureCompilerTypeCastComment(text, path$$1) {
22829
22828
  // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
22830
22829
  // Syntax example: var x = /** @type {string} */ (fruit);
22831
22830
  var n = path$$1.getValue();
22832
- return util$1.getNextNonSpaceNonCommentCharacter(text, n, locEnd) === ")" && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
22831
+ return isParenthesized(n) && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
22833
22832
 
22834
22833
  function hasAncestorTypeCastComment(index) {
22835
22834
  var ancestor = path$$1.getParentNode(index);
22836
- return ancestor && util$1.getNextNonSpaceNonCommentCharacter(text, ancestor, locEnd) !== ")" && /^[\s(]*$/.test(text.slice(locStart(ancestor), locStart(n))) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
22835
+ return ancestor && !isParenthesized(ancestor) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
22837
22836
  }
22838
22837
 
22839
22838
  function hasTypeCastComment(node) {
22840
22839
  return node.comments && node.comments.some(function (comment) {
22841
- return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value) && util$1.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
22840
+ return comment.leading && comments$3.isBlockComment(comment) && isTypeCastComment(comment.value);
22842
22841
  });
22843
22842
  }
22844
22843
 
22844
+ function isParenthesized(node) {
22845
+ // Closure typecast comments only really make sense when _not_ using
22846
+ // typescript or flow parsers, so we take advantage of the babel parser's
22847
+ // parenthesized expressions.
22848
+ return node.extra && node.extra.parenthesized;
22849
+ }
22850
+
22845
22851
  function isTypeCastComment(comment) {
22846
- var trimmed = comment.trim();
22852
+ var cleaned = comment.trim().split("\n").map(function (line) {
22853
+ return line.replace(/^[\s*]+/, "");
22854
+ }).join(" ").trim();
22847
22855
 
22848
- if (!/^\*\s*@type\s*\{[^]+\}$/.test(trimmed)) {
22856
+ if (!/^@type\s+\{[^]+\}$/.test(cleaned)) {
22849
22857
  return false;
22850
22858
  }
22851
22859
 
@@ -22856,7 +22864,7 @@ function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
22856
22864
  var _iteratorError = undefined;
22857
22865
 
22858
22866
  try {
22859
- for (var _iterator = trimmed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
22867
+ for (var _iterator = cleaned[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
22860
22868
  var char = _step.value;
22861
22869
 
22862
22870
  if (char === "{") {
@@ -22924,7 +22932,7 @@ function needsParens(path$$1, options) {
22924
22932
  // parentheses.
22925
22933
 
22926
22934
 
22927
- if (hasClosureCompilerTypeCastComment(options.originalText, path$$1, options.locStart, options.locEnd)) {
22935
+ if (hasClosureCompilerTypeCastComment(options.originalText, path$$1)) {
22928
22936
  return true;
22929
22937
  }
22930
22938
 
@@ -23235,6 +23243,7 @@ function needsParens(path$$1, options) {
23235
23243
  case "TSAsExpression":
23236
23244
  case "TSNonNullExpression":
23237
23245
  case "BindExpression":
23246
+ case "OptionalMemberExpression":
23238
23247
  return true;
23239
23248
 
23240
23249
  case "MemberExpression":
@@ -30228,8 +30237,8 @@ function print(path$$1, options, print) {
30228
30237
  case "BlockStatement":
30229
30238
  {
30230
30239
  var pp = path$$1.getParentNode(1);
30231
- var isElseIf = pp && pp.inverse && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
30232
- var hasElseIf = n.inverse && n.inverse.body[0] && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
30240
+ var isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
30241
+ var hasElseIf = n.inverse && n.inverse.body.length === 1 && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
30233
30242
  var indentElse = hasElseIf ? function (a) {
30234
30243
  return a;
30235
30244
  } : indent$6;
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/ruby.js",
6
6
  "scripts": {
@@ -26,7 +26,7 @@
26
26
  "all-contributors-cli": "^6.1.2",
27
27
  "eslint": "^5.15.0",
28
28
  "eslint-config-airbnb-base": "^13.1.0",
29
- "eslint-config-prettier": "^4.1.0",
29
+ "eslint-config-prettier": "^4.3.0",
30
30
  "eslint-plugin-import": "^2.16.0",
31
31
  "jest": "^24.0.0"
32
32
  },
data/src/nodes.js CHANGED
@@ -1,594 +1,28 @@
1
- const {
2
- align,
3
- breakParent,
4
- concat,
5
- dedent,
6
- group,
7
- hardline,
8
- ifBreak,
9
- indent,
10
- join,
11
- line,
12
- literalline,
13
- markAsRoot,
14
- removeLines,
15
- softline,
16
- trim
17
- } = require("./builders");
18
-
19
- const toProc = require("./toProc");
20
- const {
21
- concatBody,
22
- empty,
23
- first,
24
- literal,
25
- makeArgs,
26
- makeCall,
27
- makeList,
28
- prefix,
29
- skipAssignIndent
30
- } = require("./utils");
31
-
32
- const nodes = {
33
- "@int": (path, _opts, _print) => {
34
- const { body } = path.getValue();
35
-
36
- // If the number is octal and does not contain the optional "o" character
37
- // after the leading 0, add it in.
38
- if (/^0[0-9]/.test(body)) {
39
- return `0o${body.slice(1)}`;
40
- }
41
-
42
- // If the number is a decimal number, is sufficiently large, and is not
43
- // already formatted with underscores, then add them in in between the
44
- // numbers every three characters starting from the right.
45
- if (!body.startsWith("0") && body.length >= 4 && !body.includes("_")) {
46
- return ` ${body}`
47
- .slice((body.length + 2) % 3)
48
- .match(/.{3}/g)
49
- .join("_")
50
- .trim();
51
- }
52
-
53
- return body;
54
- },
55
- "@__end__": (path, _opts, _print) => {
56
- const { body } = path.getValue();
57
- return concat([trim, "__END__", literalline, body]);
58
- },
59
- access_ctrl: first,
60
- arg_paren: (path, opts, print) => {
61
- if (path.getValue().body[0] === null) {
62
- return "";
63
- }
64
-
65
- const { addTrailingCommas } = opts;
66
- const { args, heredocs } = makeArgs(path, opts, print, 0);
67
-
68
- const argsNode = path.getValue().body[0];
69
- const hasBlock = argsNode.type === "args_add_block" && argsNode.body[1];
70
-
71
- if (heredocs.length > 1) {
72
- return concat(["(", join(", ", args), ")"].concat(heredocs));
73
- }
74
-
75
- const parenDoc = group(
76
- concat([
77
- "(",
78
- indent(
79
- concat([
80
- softline,
81
- join(concat([",", line]), args),
82
- addTrailingCommas && !hasBlock ? ifBreak(",", "") : ""
83
- ])
84
- ),
85
- concat([softline, ")"])
86
- ])
87
- );
88
-
89
- if (heredocs.length === 1) {
90
- return group(concat([parenDoc].concat(heredocs)));
91
- }
92
-
93
- return parenDoc;
94
- },
95
- args: (path, opts, print) => {
96
- const args = path.map(print, "body");
97
- let blockNode = null;
98
-
99
- [1, 2, 3].find(parent => {
100
- const parentNode = path.getParentNode(parent);
101
- blockNode =
102
- parentNode &&
103
- parentNode.type === "method_add_block" &&
104
- parentNode.body[1];
105
- return blockNode;
106
- });
107
-
108
- const proc = blockNode && toProc(blockNode);
109
- if (proc) {
110
- args.push(proc);
111
- }
112
-
113
- return args;
114
- },
115
- args_add_block: (path, opts, print) => {
116
- const parts = path.call(print, "body", 0);
117
-
118
- if (path.getValue().body[1]) {
119
- parts.push(concat(["&", path.call(print, "body", 1)]));
120
- }
121
-
122
- return parts;
123
- },
124
- args_add_star: (path, opts, print) => {
125
- const printed = path.map(print, "body");
126
- const parts = printed[0]
127
- .concat([concat(["*", printed[1]])])
128
- .concat(printed.slice(2));
129
-
130
- return parts;
131
- },
132
- assoc_splat: prefix("**"),
133
- assign: (path, opts, print) => {
134
- const [printedTarget, printedValue] = path.map(print, "body");
135
- let adjustedValue = printedValue;
136
-
137
- if (
138
- ["mrhs_add_star", "mrhs_new_from_args"].includes(
139
- path.getValue().body[1].type
140
- )
141
- ) {
142
- adjustedValue = group(join(concat([",", line]), printedValue));
143
- }
144
-
145
- if (skipAssignIndent(path.getValue().body[1])) {
146
- return group(concat([printedTarget, " = ", adjustedValue]));
147
- }
148
-
149
- return group(
150
- concat([printedTarget, " =", indent(concat([line, adjustedValue]))])
151
- );
152
- },
153
- assign_error: (_path, _opts, _print) => {
154
- throw new Error("Can't set variable");
155
- },
156
- binary: (path, opts, print) => {
157
- const operator = path.getValue().body[1];
158
- const useNoSpace = operator === "**";
159
-
160
- return group(
161
- concat([
162
- concat([path.call(print, "body", 0), useNoSpace ? "" : " "]),
163
- operator,
164
- indent(
165
- concat([useNoSpace ? softline : line, path.call(print, "body", 2)])
166
- )
167
- ])
168
- );
169
- },
170
- block_var: (path, opts, print) => {
171
- const parts = ["|", removeLines(path.call(print, "body", 0))];
172
-
173
- // The second part of this node is a list of optional block-local variables
174
- if (path.getValue().body[1]) {
175
- parts.push("; ", join(", ", path.map(print, "body", 1)));
176
- }
177
-
178
- parts.push("| ");
179
- return concat(parts);
180
- },
181
- blockarg: (path, opts, print) => concat(["&", path.call(print, "body", 0)]),
182
- bodystmt: (path, opts, print) => {
183
- const [_statements, rescue, elseClause, ensure] = path.getValue().body;
184
- const parts = [path.call(print, "body", 0)];
185
-
186
- if (rescue) {
187
- parts.push(dedent(concat([hardline, path.call(print, "body", 1)])));
188
- }
189
-
190
- if (elseClause) {
191
- // Before Ruby 2.6, this piece of bodystmt was an explicit "else" node
192
- const stmts =
193
- elseClause.type === "else"
194
- ? path.call(print, "body", 2, "body", 0)
195
- : path.call(print, "body", 2);
196
-
197
- parts.push(concat([dedent(concat([hardline, "else"])), hardline, stmts]));
198
- }
199
-
200
- if (ensure) {
201
- parts.push(dedent(concat([hardline, path.call(print, "body", 3)])));
202
- }
203
-
204
- return group(concat(parts));
205
- },
206
- break: (path, opts, print) => {
207
- const content = path.getValue().body[0];
208
-
209
- if (content.body.length === 0) {
210
- return "break";
211
- }
212
-
213
- if (content.body[0].body[0].type === "paren") {
214
- return concat([
215
- "break ",
216
- path.call(print, "body", 0, "body", 0, "body", 0, "body", 0)
217
- ]);
218
- }
219
-
220
- return concat(["break ", join(", ", path.call(print, "body", 0))]);
221
- },
222
- class: (path, opts, print) => {
223
- const [_constant, superclass, statements] = path.getValue().body;
224
-
225
- const parts = ["class ", path.call(print, "body", 0)];
226
- if (superclass) {
227
- parts.push(" < ", path.call(print, "body", 1));
228
- }
229
-
230
- // If the body is empty, we can replace with a ;
231
- const stmts = statements.body[0].body;
232
- if (stmts.length === 1 && stmts[0].type === "void_stmt") {
233
- return group(concat([concat(parts), ifBreak(line, "; "), "end"]));
234
- }
235
-
236
- return group(
237
- concat([
238
- concat(parts),
239
- indent(concat([hardline, path.call(print, "body", 2)])),
240
- concat([hardline, "end"])
241
- ])
242
- );
243
- },
244
- class_name_error: (_path, _opts, _print) => {
245
- throw new Error("class/module name must be CONSTANT");
246
- },
247
- const_path_field: (path, opts, print) => join("::", path.map(print, "body")),
248
- const_path_ref: (path, opts, print) => join("::", path.map(print, "body")),
249
- const_ref: first,
250
- defined: (path, opts, print) =>
251
- group(
252
- concat([
253
- "defined?(",
254
- indent(concat([softline, path.call(print, "body", 0)])),
255
- concat([softline, ")"])
256
- ])
257
- ),
258
- dot2: (path, opts, print) =>
259
- concat([
260
- path.call(print, "body", 0),
261
- "..",
262
- path.getValue().body[1] ? path.call(print, "body", 1) : ""
263
- ]),
264
- dot3: (path, opts, print) =>
265
- concat([
266
- path.call(print, "body", 0),
267
- "...",
268
- path.getValue().body[1] ? path.call(print, "body", 1) : ""
269
- ]),
270
- dyna_symbol: (path, opts, print) => {
271
- const { quote } = path.getValue().body[0];
272
-
273
- return concat([":", quote, concat(path.call(print, "body", 0)), quote]);
274
- },
275
- else: (path, opts, print) => {
276
- const stmts = path.getValue().body[0];
277
-
278
- return concat([
279
- stmts.body.length === 1 && stmts.body[0].type === "command"
280
- ? breakParent
281
- : "",
282
- "else",
283
- indent(concat([softline, path.call(print, "body", 0)]))
284
- ]);
285
- },
286
- embdoc: (path, _opts, _print) => concat([trim, path.getValue().body]),
287
- excessed_comma: empty,
288
- fcall: concatBody,
289
- field: (path, opts, print) =>
290
- group(
291
- concat([
292
- path.call(print, "body", 0),
293
- concat([makeCall(path, opts, print), path.call(print, "body", 2)])
294
- ])
295
- ),
296
- massign: (path, opts, print) => {
297
- let right = path.call(print, "body", 1);
298
-
299
- if (
300
- ["mrhs_add_star", "mrhs_new_from_args"].includes(
301
- path.getValue().body[1].type
302
- )
303
- ) {
304
- right = group(join(concat([",", line]), right));
305
- }
306
-
307
- return group(
308
- concat([
309
- group(join(concat([",", line]), path.call(print, "body", 0))),
310
- " =",
311
- indent(concat([line, right]))
312
- ])
313
- );
314
- },
315
- method_add_arg: (path, opts, print) => {
316
- const [method, args] = path.map(print, "body");
317
- const argNode = path.getValue().body[1];
318
-
319
- // This case will ONLY be hit if we can successfully turn the block into a
320
- // to_proc call. In that case, we just explicitly add the parens around it.
321
- if (argNode.type === "args" && args.length > 0) {
322
- return concat([method, "("].concat(args).concat(")"));
323
- }
324
-
325
- return concat([method, args]);
326
- },
327
- method_add_block: (path, opts, print) => {
328
- const [method, block] = path.getValue().body;
329
- const proc = toProc(block);
330
-
331
- if (proc && method.type === "call") {
332
- return group(
333
- concat([
334
- path.call(print, "body", 0),
335
- "(",
336
- indent(concat([softline, proc])),
337
- concat([softline, ")"])
338
- ])
339
- );
340
- }
341
- if (proc) {
342
- return path.call(print, "body", 0);
343
- }
344
- return concat(path.map(print, "body"));
345
- },
346
- methref: (path, opts, print) => join(".:", path.map(print, "body")),
347
- mlhs: makeList,
348
- mlhs_add_post: (path, opts, print) =>
349
- path.call(print, "body", 0).concat(path.call(print, "body", 1)),
350
- mlhs_add_star: (path, opts, print) =>
351
- path
352
- .call(print, "body", 0)
353
- .concat([
354
- path.getValue().body[1]
355
- ? concat(["*", path.call(print, "body", 1)])
356
- : "*"
357
- ]),
358
- mlhs_paren: (path, opts, print) => {
359
- if (["massign", "mlhs_paren"].includes(path.getParentNode().type)) {
360
- // If we're nested in brackets as part of the left hand side of an
361
- // assignment, i.e., (a, b, c) = 1, 2, 3
362
- // ignore the current node and just go straight to the content
363
- return path.call(print, "body", 0);
364
- }
365
-
366
- return group(
367
- concat([
368
- "(",
369
- indent(
370
- concat([
371
- softline,
372
- join(concat([",", line]), path.call(print, "body", 0))
373
- ])
374
- ),
375
- concat([softline, ")"])
376
- ])
377
- );
378
- },
379
- mrhs: makeList,
380
- mrhs_add_star: (path, opts, print) =>
381
- path
382
- .call(print, "body", 0)
383
- .concat([concat(["*", path.call(print, "body", 1)])]),
384
- mrhs_new_from_args: (path, opts, print) => {
385
- const parts = path.call(print, "body", 0);
386
-
387
- if (path.getValue().body.length > 1) {
388
- parts.push(path.call(print, "body", 1));
389
- }
390
-
391
- return parts;
392
- },
393
- module: (path, opts, print) => {
394
- const declaration = group(concat(["module ", path.call(print, "body", 0)]));
395
-
396
- // If the body is empty, we can replace with a ;
397
- const stmts = path.getValue().body[1].body[0].body;
398
- if (stmts.length === 1 && stmts[0].type === "void_stmt") {
399
- return group(concat([declaration, ifBreak(line, "; "), "end"]));
400
- }
401
-
402
- return group(
403
- concat([
404
- declaration,
405
- indent(concat([hardline, path.call(print, "body", 1)])),
406
- concat([hardline, "end"])
407
- ])
408
- );
409
- },
410
- next: (path, opts, print) => {
411
- const args = path.getValue().body[0].body[0];
412
-
413
- if (!args) {
414
- return "next";
415
- }
416
-
417
- if (args.body[0].type === "paren") {
418
- // Ignoring the parens node and just going straight to the content
419
- return concat([
420
- "next ",
421
- path.call(print, "body", 0, "body", 0, "body", 0, "body", 0)
422
- ]);
423
- }
424
-
425
- return concat(["next ", join(", ", path.call(print, "body", 0))]);
426
- },
427
- number_arg: first,
428
- opassign: (path, opts, print) =>
429
- group(
430
- concat([
431
- path.call(print, "body", 0),
432
- " ",
433
- path.call(print, "body", 1),
434
- indent(concat([line, path.call(print, "body", 2)]))
435
- ])
436
- ),
437
- paren: (path, opts, print) => {
438
- if (!path.getValue().body[0]) {
439
- return "()";
440
- }
441
-
442
- let content = path.call(print, "body", 0);
443
-
444
- if (
445
- ["args", "args_add_star", "args_add_block"].includes(
446
- path.getValue().body[0].type
447
- )
448
- ) {
449
- content = join(concat([",", line]), content);
450
- }
451
-
452
- return group(
453
- concat([
454
- "(",
455
- indent(concat([softline, content])),
456
- concat([softline, ")"])
457
- ])
458
- );
459
- },
460
- program: (path, opts, print) =>
461
- markAsRoot(
462
- concat([join(literalline, path.map(print, "body")), literalline])
463
- ),
464
- return: (path, opts, print) => {
465
- const args = path.getValue().body[0].body[0];
466
-
467
- if (!args) {
468
- return "return";
469
- }
470
-
471
- if (args.body[0] && args.body[0].type === "paren") {
472
- // Ignoring the parens node and just going straight to the content
473
- return concat([
474
- "return ",
475
- path.call(print, "body", 0, "body", 0, "body", 0, "body", 0)
476
- ]);
477
- }
478
-
479
- return concat(["return ", join(", ", path.call(print, "body", 0))]);
480
- },
481
- return0: literal("return"),
482
- sclass: (path, opts, print) =>
483
- group(
484
- concat([
485
- concat(["class << ", path.call(print, "body", 0)]),
486
- indent(concat([hardline, path.call(print, "body", 1)])),
487
- concat([hardline, "end"])
488
- ])
489
- ),
490
- stmts: (path, opts, print) => {
491
- const stmts = path.getValue().body;
492
- const parts = [];
493
- let lineNo = null;
494
-
495
- stmts.forEach((stmt, index) => {
496
- if (stmt.type === "void_stmt") {
497
- return;
498
- }
499
-
500
- const printed = path.call(print, "body", index);
501
-
502
- if (lineNo === null) {
503
- parts.push(printed);
504
- } else if (
505
- stmt.start - lineNo > 1 ||
506
- [stmt.type, stmts[index - 1].type].includes("access_ctrl")
507
- ) {
508
- parts.push(hardline, hardline, printed);
509
- } else if (
510
- stmt.start !== lineNo ||
511
- path.getParentNode().type !== "string_embexpr"
512
- ) {
513
- parts.push(hardline, printed);
514
- } else {
515
- parts.push("; ", printed);
516
- }
517
-
518
- lineNo = stmt.end;
519
- });
520
-
521
- return concat(parts);
522
- },
523
- super: (path, opts, print) => {
524
- const args = path.getValue().body[0];
525
-
526
- if (args.type === "arg_paren") {
527
- // In case there are explicitly no arguments but they are using parens,
528
- // we assume they are attempting to override the initializer and pass no
529
- // arguments up.
530
- if (args.body[0] === null) {
531
- return "super()";
532
- }
533
-
534
- return concat(["super", path.call(print, "body", 0)]);
535
- }
536
-
537
- return concat(["super ", join(", ", path.call(print, "body", 0))]);
538
- },
539
- symbol: prefix(":"),
540
- symbol_literal: concatBody,
541
- top_const_field: prefix("::"),
542
- top_const_ref: prefix("::"),
543
- unary: (path, opts, print) => {
544
- const operator = path.getValue().body[0];
545
-
546
- return concat([
547
- operator === "not" ? "not " : operator[0],
548
- path.call(print, "body", 1)
549
- ]);
550
- },
551
- undef: (path, opts, print) =>
552
- group(
553
- concat([
554
- "undef ",
555
- align(
556
- "undef ".length,
557
- join(concat([",", line]), path.map(print, "body", 0))
558
- )
559
- ])
560
- ),
561
- var_field: concatBody,
562
- var_ref: first,
563
- vcall: first,
564
- yield: (path, opts, print) => {
565
- if (path.getValue().body[0].type === "paren") {
566
- return concat(["yield", path.call(print, "body", 0)]);
567
- }
568
-
569
- return concat(["yield ", join(", ", path.call(print, "body", 0))]);
570
- },
571
- yield0: literal("yield"),
572
- zsuper: literal("super")
573
- };
574
-
575
1
  module.exports = Object.assign(
576
2
  {},
577
3
  require("./nodes/alias"),
4
+ require("./nodes/args"),
578
5
  require("./nodes/arrays"),
6
+ require("./nodes/assign"),
579
7
  require("./nodes/blocks"),
580
8
  require("./nodes/calls"),
581
9
  require("./nodes/case"),
582
10
  require("./nodes/commands"),
583
11
  require("./nodes/conditionals"),
12
+ require("./nodes/constants"),
13
+ require("./nodes/flow"),
584
14
  require("./nodes/hashes"),
585
15
  require("./nodes/hooks"),
16
+ require("./nodes/ints"),
586
17
  require("./nodes/lambdas"),
587
18
  require("./nodes/loops"),
19
+ require("./nodes/massign"),
588
20
  require("./nodes/methods"),
21
+ require("./nodes/operators"),
589
22
  require("./nodes/params"),
590
23
  require("./nodes/regexp"),
591
24
  require("./nodes/rescue"),
592
- require("./nodes/strings"),
593
- nodes
25
+ require("./nodes/scopes"),
26
+ require("./nodes/statements"),
27
+ require("./nodes/strings")
594
28
  );