prettier 0.22.0 → 1.0.0.pre.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +63 -7
- data/CONTRIBUTING.md +1 -1
- data/README.md +13 -14
- data/package.json +1 -1
- data/src/embed.js +5 -5
- data/src/nodes/args.js +2 -3
- data/src/nodes/arrays.js +7 -4
- data/src/nodes/calls.js +4 -5
- data/src/nodes/conditionals.js +4 -4
- data/src/nodes/hashes.js +7 -6
- data/src/nodes/heredocs.js +2 -2
- data/src/nodes/hooks.js +5 -3
- data/src/nodes/loops.js +4 -3
- data/src/nodes/methods.js +2 -0
- data/src/nodes/operators.js +24 -13
- data/src/nodes/regexp.js +23 -8
- data/src/nodes/rescue.js +2 -2
- data/src/nodes/statements.js +33 -23
- data/src/nodes/strings.js +11 -10
- data/src/parser.rb +153 -42
- data/src/printer.js +3 -1
- data/src/ruby.js +8 -21
- data/src/toProc.js +1 -1
- data/src/utils.js +13 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2bdbafe8bc7bd8ebc0f77727584bfa80773721ca5e77f820df84b8e7c7e0951
|
4
|
+
data.tar.gz: 53e157e6880b56e642690fb90f6244ad669739a2e5fb697cde0c8082facc2c20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 854c61aa25de0a708606f89cb4bd3dde7dee10ecec89cfc7660bf03722ea12603bbb4dbf5f8d8b25f14359de55b419f2758522198cae9926d03fe77fab7aa001
|
7
|
+
data.tar.gz: d9c821b5367084de39bbe51c60a58642210caa5da04757c6fafbabec6e204adfdd9d7b656e34c3a94e50af26d5c6ceda9236edf68e96c98ed1e941957fe47c4a
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,57 @@ 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.0.0-rc1] - 2020-12-09
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- [@kddeisz] - Rename options to prep for v1.0 release.
|
14
|
+
- `addTrailingCommas` -> `trailingComma`, `"es5"` means `true`
|
15
|
+
- `inlineConditionals` and `inlineLoops` -> `rubyModifier`
|
16
|
+
- `preferHashLabels` -> `rubyHashLabel`
|
17
|
+
- `preferSingleQuotes` -> `rubySingleQuote`
|
18
|
+
- `toProcTransform` -> `rubyToProc`
|
19
|
+
- [@andyw8], [@kddeisz] - Fix for Ruby `2.5.1` dyna_symbols. Turns out they were previously incorrectly reported as `xstring` nodes.
|
20
|
+
- [@andyw8], [@kddeisz] - Fix for plain `rescue` nodes with only comments in the body.
|
21
|
+
- [@andyw8], [@kddeisz] - Move declaration-type comments up to the line in the original source, as in:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
def foo # :nodoc:
|
25
|
+
bar
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
The comment in the above example should stay in place.
|
30
|
+
|
31
|
+
- [@janklimo] - Respect special call syntax, e.g., `a.(1, 2, 3)` should remain the same.
|
32
|
+
- [@kddeisz] - Fix up a bug with `ensure` being used in a `bodystmt` and not a `begin`.
|
33
|
+
- [@kddeisz] - Fix up a bug with negative ranges, e.g., `-4..-3`.
|
34
|
+
- [@kddeisz] - Fix up a bug with operator aliases, e.g., `alias << push`.
|
35
|
+
- [@kddeisz] - Fix up a bug with calls and unary nodes, e.g., `!!foo&.bar`.
|
36
|
+
- [@kddeisz] - Fix up a bug with multiple rescue clauses and comments, e.g.,
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
begin
|
40
|
+
|
41
|
+
rescue Foo, Bar
|
42
|
+
# comment
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
- [@kddeisz] - Handle string literals that start with `%Q`.
|
47
|
+
- [@kddeisz] - Handle question method methods in the predicate of an if with a comment in the body.
|
48
|
+
- [@kddeisz] - Fix bare `break` with comments immediately after.
|
49
|
+
- [@kddeisz] - Fix for heredocs with comments immediately after the declaration.
|
50
|
+
- [@kddeisz] - Fix for comments when you're defining a method whose name overlaps with a keyword.
|
51
|
+
- [@kddeisz] - Don't automatically indent inside interpolated expressions from within a heredoc.
|
52
|
+
- [@kddeisz] - Don't convert into string literal arrays if the elements have brackets.
|
53
|
+
- [@kddeisz] - Ensure you break the parent when there is an assignment in the predicate of a loop.
|
54
|
+
- [@kddeisz] - Fix up a bug with keyword aliases, e.g., `alias in within`.
|
55
|
+
- [@kddeisz] - Force using braces for regex if a regex starts with a blank space.
|
56
|
+
- [@kddeisz] - Force using braces for regex if a regex starts with an equals sign.
|
57
|
+
- [@kddeisz] - Fix up a bug with constant aliases, e.g., `alias in IN`.
|
58
|
+
- [@andyw8], [@kddeisz] - Ensure `rescue` comments stay on the same line as their declaration.
|
59
|
+
|
9
60
|
# [0.22.0] - 2020-12-08
|
10
61
|
|
11
62
|
### Changed
|
@@ -877,7 +928,8 @@ would previously result in `array[]`, but now prints properly.
|
|
877
928
|
|
878
929
|
- Initial release 🎉
|
879
930
|
|
880
|
-
[unreleased]: https://github.com/prettier/plugin-ruby/compare/
|
931
|
+
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc1...HEAD
|
932
|
+
[1.0.0-rc1]: https://github.com/prettier/plugin-ruby/compare/v0.22.0...v1.0.0-rc1
|
881
933
|
[0.22.0]: https://github.com/prettier/plugin-ruby/compare/v0.21.0...v0.22.0
|
882
934
|
[0.21.0]: https://github.com/prettier/plugin-ruby/compare/v0.20.1...v0.21.0
|
883
935
|
[0.20.1]: https://github.com/prettier/plugin-ruby/compare/v0.20.0...v0.20.1
|
@@ -930,6 +982,7 @@ would previously result in `array[]`, but now prints properly.
|
|
930
982
|
[@alanfoster]: https://github.com/AlanFoster
|
931
983
|
[@alse]: https://github.com/alse
|
932
984
|
[@andrewraycode]: https://github.com/AndrewRayCode
|
985
|
+
[@andyw8]: https://github.com/andyw8
|
933
986
|
[@ashfurrow]: https://github.com/ashfurrow
|
934
987
|
[@awinograd]: https://github.com/awinograd
|
935
988
|
[@bugthing]: https://github.com/bugthing
|
@@ -937,12 +990,13 @@ would previously result in `array[]`, but now prints properly.
|
|
937
990
|
[@christoomey]: https://github.com/christoomey
|
938
991
|
[@cldevs]: https://github.com/cldevs
|
939
992
|
[@codingitwrong]: https://github.com/CodingItWrong
|
993
|
+
[@coiti]: https://github.com/coiti
|
940
994
|
[@deecewan]: https://github.com/deecewan
|
941
995
|
[@dudeofawesome]: https://github.com/dudeofawesome
|
942
996
|
[@eins78]: https://github.com/eins78
|
943
|
-
[@ftes]: https://github.com/ftes
|
944
997
|
[@flyerhzm]: https://github.com/flyerhzm
|
945
998
|
[@fruetel]: https://github.com/Fruetel
|
999
|
+
[@ftes]: https://github.com/ftes
|
946
1000
|
[@gin0606]: https://github.com/gin0606
|
947
1001
|
[@github0013]: https://github.com/github0013
|
948
1002
|
[@glejeune]: https://github.com/glejeune
|
@@ -951,7 +1005,9 @@ would previously result in `array[]`, but now prints properly.
|
|
951
1005
|
[@jakeprime]: https://github.com/jakeprime
|
952
1006
|
[@jamescostian]: https://github.com/jamescostian
|
953
1007
|
[@janklimo]: https://github.com/janklimo
|
1008
|
+
[@jbielick]: https://github.com/jbielick
|
954
1009
|
[@joeyjoejoejr]: https://github.com/joeyjoejoejr
|
1010
|
+
[@johncsnyder]: https://github.com/johncsnyder
|
955
1011
|
[@johnschoeman]: https://github.com/johnschoeman
|
956
1012
|
[@joshuakgoldberg]: https://github.com/JoshuaKGoldberg
|
957
1013
|
[@jpickwell]: https://github.com/jpickwell
|
@@ -966,18 +1022,18 @@ would previously result in `array[]`, but now prints properly.
|
|
966
1022
|
[@matt-wratt]: https://github.com/matt-wratt
|
967
1023
|
[@meleyal]: https://github.com/meleyal
|
968
1024
|
[@mmainz]: https://github.com/mmainz
|
1025
|
+
[@mmcnl]: https://github.com/mmcnl
|
969
1026
|
[@noahtheduke]: https://github.com/NoahTheDuke
|
970
1027
|
[@overload119]: https://github.com/Overload119
|
971
1028
|
[@petevk]: https://github.com/petevk
|
972
1029
|
[@pje]: https://github.com/pje
|
973
1030
|
[@rosskinsella]: https://github.com/RossKinsella
|
1031
|
+
[@rsullivan00]: https://github.com/Rsullivan00
|
1032
|
+
[@ryan-hunter-pc]: https://github.com/ryan-hunter-pc
|
974
1033
|
[@shaydavidson]: https://github.com/ShayDavidson
|
1034
|
+
[@steobrien]: https://github.com/steobrien
|
1035
|
+
[@sviccari]: https://github.com/SViccari
|
975
1036
|
[@tobyndockerill]: https://github.com/tobyndockerill
|
976
1037
|
[@uri]: https://github.com/uri
|
977
1038
|
[@xipgroc]: https://github.com/xipgroc
|
978
1039
|
[@yuki24]: https://github.com/yuki24
|
979
|
-
[@rsullivan00]: https://github.com/Rsullivan00
|
980
|
-
[@steobrien]: https://github.com/steobrien
|
981
|
-
[@jbielick]: https://github.com/jbielick
|
982
|
-
[@coiti]: https://github.com/coiti
|
983
|
-
[@johncsnyder]: https://github.com/johncsnyder
|
data/CONTRIBUTING.md
CHANGED
@@ -129,7 +129,7 @@ In order to support all preferences, the Ruby options need to be distinct from t
|
|
129
129
|
|
130
130
|
### What versions of Ruby are supported?
|
131
131
|
|
132
|
-
|
132
|
+
We support all Ruby versions that are under security maintenance or better (https://www.ruby-lang.org/en/downloads/branches/). This means at the moment we support back to Ruby 2.5. This is not to say that prettier can't parse and print code that was written while running earlier versions of Ruby, it's just that the Ruby process running prettier (whatever `ruby` resolves to when the process runs) must be >= 2.5.
|
133
133
|
|
134
134
|
### Do you support ERB files (.html.erb, .js.erb, etc.)?
|
135
135
|
|
data/README.md
CHANGED
@@ -122,31 +122,30 @@ The `prettier` executable is now installed and ready for use:
|
|
122
122
|
|
123
123
|
Below are the options (from [`src/ruby.js`](src/ruby.js)) that `@prettier/plugin-ruby` currently supports:
|
124
124
|
|
125
|
-
| API Option
|
126
|
-
|
|
127
|
-
| `printWidth`
|
128
|
-
| `requirePragma`
|
129
|
-
| `
|
130
|
-
| `
|
131
|
-
| `
|
132
|
-
| `
|
133
|
-
| `
|
134
|
-
| `
|
135
|
-
| `toProcTransform` | `--to-proc-transform` | `false` | When possible, convert blocks to the more concise `Symbol#to_proc` syntax. |
|
125
|
+
| API Option | CLI Option | Default | Description |
|
126
|
+
| ----------------- | --------------------- | :-----: | ------------------------------------------------------------------------------------------------------------------------------------ |
|
127
|
+
| `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
|
128
|
+
| `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). |
|
129
|
+
| `rubyHashLabel` | `--ruby-hash-label` | `true` | When possible, uses the shortened hash key syntax, as opposed to hash rockets. |
|
130
|
+
| `rubyModifier` | `--ruby-modifier` | `true` | When it fits on one line, allows while and until statements to use the modifier form. |
|
131
|
+
| `rubySingleQuote` | `--ruby-single-quote` | `true` | When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals. |
|
132
|
+
| `rubyToProc` | `--ruby-to-proc` | `false` | When possible, convert blocks to the more concise `Symbol#to_proc` syntax. |
|
133
|
+
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
|
134
|
+
| `trailingComma` | `--trailing-comma` | `"es5"` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#trailing-comma)). `"es5"` is equivalent to `true`. |
|
136
135
|
|
137
136
|
Any of these can be added to your existing [prettier configuration
|
138
137
|
file](https://prettier.io/docs/en/configuration.html). For example:
|
139
138
|
|
140
139
|
```json
|
141
140
|
{
|
142
|
-
"
|
141
|
+
"rubySingleQuote": false
|
143
142
|
}
|
144
143
|
```
|
145
144
|
|
146
145
|
Or, they can be passed to `prettier` as arguments:
|
147
146
|
|
148
147
|
```bash
|
149
|
-
prettier --
|
148
|
+
prettier --ruby-single-quote false --write '**/*.rb'
|
150
149
|
```
|
151
150
|
|
152
151
|
## Contributing
|
@@ -181,7 +180,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
181
180
|
</tr>
|
182
181
|
<tr>
|
183
182
|
<td align="center"><a href="https://janpiotrowski.de"><img src="https://avatars0.githubusercontent.com/u/183673?v=4?s=100" width="100px;" alt=""/><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
|
-
<td align="center"><a href="https://www.andywaite.com"><img src="https://avatars1.githubusercontent.com/u/13400?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Andy Waite</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/commits?author=andyw8" title="Documentation">📖</a></td>
|
183
|
+
<td align="center"><a href="https://www.andywaite.com"><img src="https://avatars1.githubusercontent.com/u/13400?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Andy Waite</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/commits?author=andyw8" title="Documentation">📖</a> <a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Aandyw8" title="Bug reports">🐛</a></td>
|
185
184
|
<td align="center"><a href="https://github.com/jviney"><img src="https://avatars3.githubusercontent.com/u/7051?v=4?s=100" width="100px;" alt=""/><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
185
|
<td align="center"><a href="https://github.com/acrewdson"><img src="https://avatars0.githubusercontent.com/u/10353074?v=4?s=100" width="100px;" alt=""/><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>
|
187
186
|
<td align="center"><a href="https://orleans.io"><img src="https://avatars0.githubusercontent.com/u/1683595?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Louis Orleans</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Adudeofawesome" title="Bug reports">🐛</a></td>
|
data/package.json
CHANGED
data/src/embed.js
CHANGED
@@ -31,7 +31,7 @@ const replaceNewlines = (doc) =>
|
|
31
31
|
: currentDoc
|
32
32
|
);
|
33
33
|
|
34
|
-
const embed = (path,
|
34
|
+
const embed = (path, print, textToDoc, _opts) => {
|
35
35
|
const node = path.getValue();
|
36
36
|
|
37
37
|
// Currently we only support embedded formatting on heredoc nodes
|
@@ -47,7 +47,7 @@ const embed = (path, _print, textToDoc, _opts) => {
|
|
47
47
|
|
48
48
|
// Next, find the parser associated with this heredoc (if there is one). For
|
49
49
|
// example, if you use <<~CSS, we'd hook it up to the css parser.
|
50
|
-
const parser = parsers[beging.slice(3).toLowerCase()];
|
50
|
+
const parser = parsers[beging.body.slice(3).toLowerCase()];
|
51
51
|
if (!parser) {
|
52
52
|
return null;
|
53
53
|
}
|
@@ -62,9 +62,9 @@ const embed = (path, _print, textToDoc, _opts) => {
|
|
62
62
|
|
63
63
|
// If we're using a squiggly heredoc, then we can properly handle indentation
|
64
64
|
// ourselves.
|
65
|
-
if (beging[2] === "~") {
|
65
|
+
if (beging.body[2] === "~") {
|
66
66
|
return concat([
|
67
|
-
beging,
|
67
|
+
path.call(print, "beging"),
|
68
68
|
lineSuffix(
|
69
69
|
group(
|
70
70
|
concat([indent(markAsRoot(formatted)), literalLineNoBreak, ending])
|
@@ -77,7 +77,7 @@ const embed = (path, _print, textToDoc, _opts) => {
|
|
77
77
|
// content as it is.
|
78
78
|
return markAsRoot(
|
79
79
|
concat([
|
80
|
-
beging,
|
80
|
+
path.call(print, "beging"),
|
81
81
|
lineSuffix(group(concat([formatted, literalLineNoBreak, ending])))
|
82
82
|
])
|
83
83
|
);
|
data/src/nodes/args.js
CHANGED
@@ -9,12 +9,11 @@ const {
|
|
9
9
|
} = require("../prettier");
|
10
10
|
|
11
11
|
const toProc = require("../toProc");
|
12
|
-
const { docLength } = require("../utils");
|
12
|
+
const { docLength, getTrailingComma } = require("../utils");
|
13
13
|
|
14
14
|
module.exports = {
|
15
15
|
arg_paren: (path, opts, print) => {
|
16
16
|
const argsNode = path.getValue().body[0];
|
17
|
-
const { addTrailingCommas } = opts;
|
18
17
|
|
19
18
|
if (argsNode === null) {
|
20
19
|
return "";
|
@@ -41,7 +40,7 @@ module.exports = {
|
|
41
40
|
// parentheses or surrounding lines yet added.
|
42
41
|
let argsDocs = [
|
43
42
|
join(concat([",", line]), args),
|
44
|
-
|
43
|
+
getTrailingComma(opts) && !hasBlock ? ifBreak(",", "") : ""
|
45
44
|
];
|
46
45
|
|
47
46
|
// Here we're going to make a determination on whether or not we should put
|
data/src/nodes/arrays.js
CHANGED
@@ -9,6 +9,8 @@ const {
|
|
9
9
|
softline
|
10
10
|
} = require("../prettier");
|
11
11
|
|
12
|
+
const { getTrailingComma } = require("../utils");
|
13
|
+
|
12
14
|
// Checks that every argument within this args node is a string_literal node
|
13
15
|
// that has no spaces or interpolations. This means we're dealing with an array
|
14
16
|
// that looks something like:
|
@@ -37,9 +39,10 @@ function isStringArray(args) {
|
|
37
39
|
return false;
|
38
40
|
}
|
39
41
|
|
40
|
-
// Finally, verify that the string doesn't contain a space
|
41
|
-
// character so that we know it can be put into a string
|
42
|
-
|
42
|
+
// Finally, verify that the string doesn't contain a space, an escape
|
43
|
+
// character, or brackets so that we know it can be put into a string
|
44
|
+
// literal array.
|
45
|
+
return !/[\s\\[\]]/.test(part.body);
|
43
46
|
});
|
44
47
|
}
|
45
48
|
|
@@ -153,7 +156,7 @@ function printArray(path, opts, print) {
|
|
153
156
|
concat([
|
154
157
|
softline,
|
155
158
|
join(concat([",", line]), path.call(print, "body", 0)),
|
156
|
-
opts
|
159
|
+
getTrailingComma(opts) ? ifBreak(",", "") : ""
|
157
160
|
])
|
158
161
|
),
|
159
162
|
softline,
|
data/src/nodes/calls.js
CHANGED
@@ -6,12 +6,11 @@ const {
|
|
6
6
|
indent,
|
7
7
|
softline
|
8
8
|
} = require("../prettier");
|
9
|
-
const { concatBody, first, makeCall } = require("../utils");
|
9
|
+
const { concatBody, first, makeCall, noIndent } = require("../utils");
|
10
10
|
|
11
11
|
const toProc = require("../toProc");
|
12
12
|
|
13
13
|
const chained = ["call", "method_add_arg"];
|
14
|
-
const noIndent = ["array", "hash", "if", "method_add_block", "xstring_literal"];
|
15
14
|
|
16
15
|
function printCall(path, opts, print) {
|
17
16
|
const callNode = path.getValue();
|
@@ -21,9 +20,9 @@ function printCall(path, opts, print) {
|
|
21
20
|
const operatorDoc = makeCall(path, opts, print);
|
22
21
|
|
23
22
|
// You can call lambdas with a special syntax that looks like func.(*args).
|
24
|
-
// In this case, "call" is returned for the 3rd child node.
|
25
|
-
|
26
|
-
|
23
|
+
// In this case, "call" is returned for the 3rd child node. We don't alter
|
24
|
+
// call syntax so if `call` is implicit, we don't print it out.
|
25
|
+
const messageDoc = messageNode === "call" ? "" : path.call(print, "body", 2);
|
27
26
|
|
28
27
|
// For certain left sides of the call nodes, we want to attach directly to
|
29
28
|
// the } or end.
|
data/src/nodes/conditionals.js
CHANGED
@@ -81,7 +81,7 @@ const printTernary = (path, _opts, print) => {
|
|
81
81
|
// modifier form, we're guaranteed to not have an additional node, so we can
|
82
82
|
// just work with the predicate and the body.
|
83
83
|
function printSingle(keyword, modifier = false) {
|
84
|
-
return function printSingleWithKeyword(path, {
|
84
|
+
return function printSingleWithKeyword(path, { rubyModifier }, print) {
|
85
85
|
const [_predicateNode, statementsNode] = path.getValue().body;
|
86
86
|
const predicateDoc = path.call(print, "body", 0);
|
87
87
|
const statementsDoc = path.call(print, "body", 1);
|
@@ -97,7 +97,7 @@ function printSingle(keyword, modifier = false) {
|
|
97
97
|
// If we do not allow modifier form conditionals or there are comments
|
98
98
|
// inside of the body of the conditional, then we must print in the
|
99
99
|
// multiline form.
|
100
|
-
if (!
|
100
|
+
if (!rubyModifier || (!modifier && statementsNode.body[0].comments)) {
|
101
101
|
return concat([concat(multilineParts), breakParent]);
|
102
102
|
}
|
103
103
|
|
@@ -190,7 +190,7 @@ const canTernary = (path) => {
|
|
190
190
|
};
|
191
191
|
|
192
192
|
// A normalized print function for both `if` and `unless` nodes.
|
193
|
-
const printConditional = (keyword) => (path, {
|
193
|
+
const printConditional = (keyword) => (path, { rubyModifier }, print) => {
|
194
194
|
if (canTernary(path)) {
|
195
195
|
let ternaryParts = [path.call(print, "body", 0), " ? "].concat(
|
196
196
|
printTernaryClauses(
|
@@ -239,7 +239,7 @@ const printConditional = (keyword) => (path, { inlineConditionals }, print) => {
|
|
239
239
|
]);
|
240
240
|
}
|
241
241
|
|
242
|
-
return printSingle(keyword)(path, {
|
242
|
+
return printSingle(keyword)(path, { rubyModifier }, print);
|
243
243
|
};
|
244
244
|
|
245
245
|
module.exports = {
|
data/src/nodes/hashes.js
CHANGED
@@ -7,7 +7,8 @@ const {
|
|
7
7
|
join,
|
8
8
|
line
|
9
9
|
} = require("../prettier");
|
10
|
-
|
10
|
+
|
11
|
+
const { getTrailingComma, prefix, skipAssignIndent } = require("../utils");
|
11
12
|
|
12
13
|
// When attempting to convert a hash rocket into a hash label, you need to take
|
13
14
|
// care because only certain patterns are allowed. Ruby source says that they
|
@@ -24,24 +25,24 @@ function isValidHashLabel(symbolLiteral) {
|
|
24
25
|
return label.match(/^[_A-Za-z]/) && !label.endsWith("=");
|
25
26
|
}
|
26
27
|
|
27
|
-
function printHashKey(path, {
|
28
|
+
function printHashKey(path, { rubyHashLabel }, print) {
|
28
29
|
const labelNode = path.getValue().body[0];
|
29
30
|
const labelDoc = path.call(print, "body", 0);
|
30
31
|
|
31
32
|
switch (labelNode.type) {
|
32
33
|
case "@label":
|
33
|
-
if (
|
34
|
+
if (rubyHashLabel) {
|
34
35
|
return labelDoc;
|
35
36
|
}
|
36
37
|
return `:${labelDoc.slice(0, labelDoc.length - 1)} =>`;
|
37
38
|
case "symbol_literal": {
|
38
|
-
if (
|
39
|
+
if (rubyHashLabel && isValidHashLabel(labelNode)) {
|
39
40
|
return concat([path.call(print, "body", 0, "body", 0), ":"]);
|
40
41
|
}
|
41
42
|
return concat([labelDoc, " =>"]);
|
42
43
|
}
|
43
44
|
case "dyna_symbol":
|
44
|
-
if (
|
45
|
+
if (rubyHashLabel) {
|
45
46
|
return concat(labelDoc.parts.slice(1).concat(":"));
|
46
47
|
}
|
47
48
|
return concat([labelDoc, " =>"]);
|
@@ -98,7 +99,7 @@ function printHash(path, opts, print) {
|
|
98
99
|
concat([
|
99
100
|
line,
|
100
101
|
path.call(print, "body", 0),
|
101
|
-
opts
|
102
|
+
getTrailingComma(opts) ? ifBreak(",", "") : ""
|
102
103
|
])
|
103
104
|
),
|
104
105
|
line,
|
data/src/nodes/heredocs.js
CHANGED
@@ -2,7 +2,7 @@ const { concat, group, lineSuffix, join } = require("../prettier");
|
|
2
2
|
const { literalLineNoBreak } = require("../utils");
|
3
3
|
|
4
4
|
function printHeredoc(path, opts, print) {
|
5
|
-
const {
|
5
|
+
const { body, ending } = path.getValue();
|
6
6
|
|
7
7
|
const parts = body.map((part, index) => {
|
8
8
|
if (part.type !== "@tstring_content") {
|
@@ -21,7 +21,7 @@ function printHeredoc(path, opts, print) {
|
|
21
21
|
// possible, so we use a literalline without the break-parent.
|
22
22
|
return group(
|
23
23
|
concat([
|
24
|
-
beging,
|
24
|
+
path.call(print, "beging"),
|
25
25
|
lineSuffix(
|
26
26
|
group(concat([literalLineNoBreak].concat(parts).concat(ending)))
|
27
27
|
)
|
data/src/nodes/hooks.js
CHANGED
@@ -17,11 +17,13 @@ const { isEmptyStmts } = require("../utils");
|
|
17
17
|
// nodes contain one child which is a `stmts` node.
|
18
18
|
function printHook(name) {
|
19
19
|
return function printHookWithName(path, opts, print) {
|
20
|
-
const stmtsNode = path.getValue().body[
|
21
|
-
const printedStmts = path.call(print, "body",
|
20
|
+
const stmtsNode = path.getValue().body[1];
|
21
|
+
const printedStmts = path.call(print, "body", 1);
|
22
22
|
|
23
23
|
const parts = [
|
24
|
-
|
24
|
+
name,
|
25
|
+
" ",
|
26
|
+
path.call(print, "body", 0),
|
25
27
|
indent(concat([line, printedStmts])),
|
26
28
|
concat([line, "}"])
|
27
29
|
];
|
data/src/nodes/loops.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
const {
|
2
2
|
align,
|
3
|
+
breakParent,
|
3
4
|
concat,
|
4
5
|
group,
|
5
6
|
hardline,
|
@@ -11,7 +12,7 @@ const {
|
|
11
12
|
const { containsAssignment } = require("../utils");
|
12
13
|
const inlineEnsureParens = require("../utils/inlineEnsureParens");
|
13
14
|
|
14
|
-
const printLoop = (keyword, modifier) => (path, {
|
15
|
+
const printLoop = (keyword, modifier) => (path, { rubyModifier }, print) => {
|
15
16
|
const [_predicate, stmts] = path.getValue().body;
|
16
17
|
|
17
18
|
// If the only statement inside this while loop is a void statement, then we
|
@@ -66,8 +67,8 @@ const printLoop = (keyword, modifier) => (path, { inlineLoops }, print) => {
|
|
66
67
|
// an assignment (in which case we can't know for certain that that
|
67
68
|
// assignment doesn't impact the statements inside the loop) then we can't
|
68
69
|
// use the modifier form and we must use the block form.
|
69
|
-
if (!
|
70
|
-
return blockLoop;
|
70
|
+
if (!rubyModifier || containsAssignment(path.getValue().body[0])) {
|
71
|
+
return concat([breakParent, blockLoop]);
|
71
72
|
}
|
72
73
|
|
73
74
|
return group(ifBreak(blockLoop, inlineLoop));
|