prettier 0.21.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +112 -7
- data/CONTRIBUTING.md +4 -4
- data/README.md +18 -14
- data/package.json +9 -6
- data/src/embed.js +27 -8
- data/src/nodes.js +5 -2
- data/src/nodes/alias.js +29 -31
- data/src/nodes/aref.js +26 -26
- data/src/nodes/args.js +55 -47
- data/src/nodes/arrays.js +132 -106
- data/src/nodes/assign.js +32 -32
- data/src/nodes/blocks.js +8 -3
- data/src/nodes/calls.js +163 -60
- data/src/nodes/case.js +11 -7
- data/src/nodes/class.js +74 -0
- data/src/nodes/commands.js +36 -31
- data/src/nodes/conditionals.js +44 -30
- data/src/nodes/constants.js +39 -21
- data/src/nodes/flow.js +11 -1
- data/src/nodes/hashes.js +90 -109
- data/src/nodes/heredocs.js +34 -0
- data/src/nodes/hooks.js +21 -22
- data/src/nodes/ints.js +27 -20
- data/src/nodes/lambdas.js +14 -27
- data/src/nodes/loops.js +10 -5
- data/src/nodes/massign.js +87 -65
- data/src/nodes/methods.js +48 -73
- data/src/nodes/operators.js +70 -39
- data/src/nodes/params.js +26 -16
- data/src/nodes/patterns.js +108 -33
- data/src/nodes/regexp.js +45 -14
- data/src/nodes/rescue.js +72 -59
- data/src/nodes/statements.js +86 -44
- data/src/nodes/strings.js +95 -85
- data/src/nodes/super.js +35 -0
- data/src/nodes/undef.js +42 -0
- data/src/parser.js +86 -0
- data/src/parser.rb +2400 -621
- data/src/printer.js +90 -0
- data/src/ruby.js +19 -41
- data/src/toProc.js +4 -4
- data/src/utils.js +24 -88
- data/src/utils/literalLineNoBreak.js +7 -0
- data/src/utils/printEmptyCollection.js +42 -0
- metadata +12 -49
- data/src/nodes/scopes.js +0 -61
- data/src/parse.js +0 -37
- data/src/print.js +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b3f385a13ce2aae0cef657abc5d33e5d3d2fbfb59edf1fb39193ded2828cf87
|
4
|
+
data.tar.gz: 1049cb733eb60e3221a7df64110f5841f39288f8e91cb589f08cc1c23a0ddfbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef14696b55d0dd1a544bba5fd45d88e3ab322ab9d2ae34d89b4b6bf84748ac35100022d5e050ed4ef0e5cf5ad93049c1782243cda27e4bae5b7dc87a2f951614
|
7
|
+
data.tar.gz: 1bedee0f2b091bc7b7b10ceb645d183271dcea847f8b843c79cd6db5ebf078bb94d7d91fd255127f77c71eb9edd185dcfa166ffe9c442f315f64beb9ba57f4ee
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,100 @@ 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.1] - 2020-12-12
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- [@steobrien], [@kddeisz] - Ensure leading comments in empty array and hash literals do not duplicate.
|
14
|
+
|
15
|
+
## [1.0.0] - 2020-12-11
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- [@kddeisz] - Do not unescape double quotes in a single quote string.
|
20
|
+
- [@kddeisz] - Only force braces on regexp for spaces and equals if it's inside a command or command_call.
|
21
|
+
- [@kddeisz] - Leave Sorbet type annotations in place.
|
22
|
+
- [@kddeisz] - Don't group hash contents, just allow them to break with their parent node.
|
23
|
+
- [@kddeisz] - Honor the UTF-8 lang passed in through ENV vars.
|
24
|
+
|
25
|
+
## [1.0.0-rc2] - 2020-12-10
|
26
|
+
|
27
|
+
### Changed
|
28
|
+
|
29
|
+
- [@kddeisz] - Print hashes with consistent keys (e.g., if one key cannot be a hash label, use all hash rockets).
|
30
|
+
- [@kddeisz] - Respect using `o` or not using `o` for octal numbers.
|
31
|
+
- [@kddeisz] - Ensure `when` clauses with multiple predicates that can be split into multiple lines are split correctly.
|
32
|
+
- [@kddeisz] - Ensure hash literal is split correctly when only its contents would fit on one line.
|
33
|
+
- [@kddeisz] - Simplify `toProc` checks by not calling if the option is disabled.
|
34
|
+
- [@johncsnyder], [@kddeisz] - Add `method_add_block` to the potential like of method calls that can be chained.
|
35
|
+
- [@kddeisz] - Add the `rubyArrayLiteral` option for disabling automatically turning into array literals.
|
36
|
+
|
37
|
+
## [1.0.0-rc1] - 2020-12-09
|
38
|
+
|
39
|
+
### Changed
|
40
|
+
|
41
|
+
- [@kddeisz] - Rename options to prep for v1.0 release.
|
42
|
+
- `addTrailingCommas` -> `trailingComma`, `"es5"` means `true`
|
43
|
+
- `inlineConditionals` and `inlineLoops` -> `rubyModifier`
|
44
|
+
- `preferHashLabels` -> `rubyHashLabel`
|
45
|
+
- `preferSingleQuotes` -> `rubySingleQuote`
|
46
|
+
- `toProcTransform` -> `rubyToProc`
|
47
|
+
- [@andyw8], [@kddeisz] - Fix for Ruby `2.5.1` dyna_symbols. Turns out they were previously incorrectly reported as `xstring` nodes.
|
48
|
+
- [@andyw8], [@kddeisz] - Fix for plain `rescue` nodes with only comments in the body.
|
49
|
+
- [@andyw8], [@kddeisz] - Move declaration-type comments up to the line in the original source, as in:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
def foo # :nodoc:
|
53
|
+
bar
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
The comment in the above example should stay in place.
|
58
|
+
|
59
|
+
- [@janklimo] - Respect special call syntax, e.g., `a.(1, 2, 3)` should remain the same.
|
60
|
+
- [@kddeisz] - Fix up a bug with `ensure` being used in a `bodystmt` and not a `begin`.
|
61
|
+
- [@kddeisz] - Fix up a bug with negative ranges, e.g., `-4..-3`.
|
62
|
+
- [@kddeisz] - Fix up a bug with operator aliases, e.g., `alias << push`.
|
63
|
+
- [@kddeisz] - Fix up a bug with calls and unary nodes, e.g., `!!foo&.bar`.
|
64
|
+
- [@kddeisz] - Fix up a bug with multiple rescue clauses and comments, e.g.,
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
begin
|
68
|
+
|
69
|
+
rescue Foo, Bar
|
70
|
+
# comment
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
- [@kddeisz] - Handle string literals that start with `%Q`.
|
75
|
+
- [@kddeisz] - Handle question method methods in the predicate of an if with a comment in the body.
|
76
|
+
- [@kddeisz] - Fix bare `break` with comments immediately after.
|
77
|
+
- [@kddeisz] - Fix for heredocs with comments immediately after the declaration.
|
78
|
+
- [@kddeisz] - Fix for comments when you're defining a method whose name overlaps with a keyword.
|
79
|
+
- [@kddeisz] - Don't automatically indent inside interpolated expressions from within a heredoc.
|
80
|
+
- [@kddeisz] - Don't convert into string literal arrays if the elements have brackets.
|
81
|
+
- [@kddeisz] - Ensure you break the parent when there is an assignment in the predicate of a loop.
|
82
|
+
- [@kddeisz] - Fix up a bug with keyword aliases, e.g., `alias in within`.
|
83
|
+
- [@kddeisz] - Force using braces for regex if a regex starts with a blank space.
|
84
|
+
- [@kddeisz] - Force using braces for regex if a regex starts with an equals sign.
|
85
|
+
- [@kddeisz] - Fix up a bug with constant aliases, e.g., `alias in IN`.
|
86
|
+
- [@andyw8], [@kddeisz] - Ensure `rescue` comments stay on the same line as their declaration.
|
87
|
+
|
88
|
+
# [0.22.0] - 2020-12-08
|
89
|
+
|
90
|
+
### Changed
|
91
|
+
|
92
|
+
- [@flyerhzm] - Print method chains by one indentation.
|
93
|
+
- [@mmcnl], [@kddeisz] - Handle heredocs and blocks being passed to the same method.
|
94
|
+
- [@johncsnyder], [@kddeisz] - Ensure correct formatting when breaking up conditionals with `inlineConditionals: false`.
|
95
|
+
- [@Rsullivan00] - Ensure that when ternaries as command arguments get broken into multiple lines we add the necessary parentheses.
|
96
|
+
- [@jbielick] - Maintain parse order during if/unless modifier expressions
|
97
|
+
- [@flyerhzm] - Slight prettifying of wrapped args if doc length is under a certain value.
|
98
|
+
- [@github0013], [@kddeisz] - Ensure `not` keeps parentheses if they are being used.
|
99
|
+
- [@jbielick] - Print heredocs consistently.
|
100
|
+
- [@kddeisz] - Completely revamp the way we handle comments.
|
101
|
+
- [@kddeisz] - Support `hshptn` and the remaining missing pattern matching syntax.
|
102
|
+
|
9
103
|
## [0.21.0] - 2020-12-02
|
10
104
|
|
11
105
|
### Changed
|
@@ -174,7 +268,8 @@ will now be printed as:
|
|
174
268
|
```ruby
|
175
269
|
Config::Download.new(
|
176
270
|
'prettier',
|
177
|
-
filename: 'prettier.yml',
|
271
|
+
filename: 'prettier.yml',
|
272
|
+
url: 'https://raw.githubusercontent.com/...'
|
178
273
|
).perform
|
179
274
|
```
|
180
275
|
|
@@ -862,7 +957,12 @@ would previously result in `array[]`, but now prints properly.
|
|
862
957
|
|
863
958
|
- Initial release 🎉
|
864
959
|
|
865
|
-
[unreleased]: https://github.com/prettier/plugin-ruby/compare/
|
960
|
+
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.0.1...HEAD
|
961
|
+
[1.0.1]: https://github.com/prettier/plugin-ruby/compare/v1.0.0...v1.0.1
|
962
|
+
[1.0.0]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc2...v1.0.0
|
963
|
+
[1.0.0-rc2]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc1...v1.0.0-rc2
|
964
|
+
[1.0.0-rc1]: https://github.com/prettier/plugin-ruby/compare/v0.22.0...v1.0.0-rc1
|
965
|
+
[0.22.0]: https://github.com/prettier/plugin-ruby/compare/v0.21.0...v0.22.0
|
866
966
|
[0.21.0]: https://github.com/prettier/plugin-ruby/compare/v0.20.1...v0.21.0
|
867
967
|
[0.20.1]: https://github.com/prettier/plugin-ruby/compare/v0.20.0...v0.20.1
|
868
968
|
[0.20.0]: https://github.com/prettier/plugin-ruby/compare/v0.19.1...v0.20.0
|
@@ -914,6 +1014,7 @@ would previously result in `array[]`, but now prints properly.
|
|
914
1014
|
[@alanfoster]: https://github.com/AlanFoster
|
915
1015
|
[@alse]: https://github.com/alse
|
916
1016
|
[@andrewraycode]: https://github.com/AndrewRayCode
|
1017
|
+
[@andyw8]: https://github.com/andyw8
|
917
1018
|
[@ashfurrow]: https://github.com/ashfurrow
|
918
1019
|
[@awinograd]: https://github.com/awinograd
|
919
1020
|
[@bugthing]: https://github.com/bugthing
|
@@ -921,12 +1022,13 @@ would previously result in `array[]`, but now prints properly.
|
|
921
1022
|
[@christoomey]: https://github.com/christoomey
|
922
1023
|
[@cldevs]: https://github.com/cldevs
|
923
1024
|
[@codingitwrong]: https://github.com/CodingItWrong
|
1025
|
+
[@coiti]: https://github.com/coiti
|
924
1026
|
[@deecewan]: https://github.com/deecewan
|
925
1027
|
[@dudeofawesome]: https://github.com/dudeofawesome
|
926
1028
|
[@eins78]: https://github.com/eins78
|
927
|
-
[@ftes]: https://github.com/ftes
|
928
1029
|
[@flyerhzm]: https://github.com/flyerhzm
|
929
1030
|
[@fruetel]: https://github.com/Fruetel
|
1031
|
+
[@ftes]: https://github.com/ftes
|
930
1032
|
[@gin0606]: https://github.com/gin0606
|
931
1033
|
[@github0013]: https://github.com/github0013
|
932
1034
|
[@glejeune]: https://github.com/glejeune
|
@@ -935,7 +1037,9 @@ would previously result in `array[]`, but now prints properly.
|
|
935
1037
|
[@jakeprime]: https://github.com/jakeprime
|
936
1038
|
[@jamescostian]: https://github.com/jamescostian
|
937
1039
|
[@janklimo]: https://github.com/janklimo
|
1040
|
+
[@jbielick]: https://github.com/jbielick
|
938
1041
|
[@joeyjoejoejr]: https://github.com/joeyjoejoejr
|
1042
|
+
[@johncsnyder]: https://github.com/johncsnyder
|
939
1043
|
[@johnschoeman]: https://github.com/johnschoeman
|
940
1044
|
[@joshuakgoldberg]: https://github.com/JoshuaKGoldberg
|
941
1045
|
[@jpickwell]: https://github.com/jpickwell
|
@@ -950,17 +1054,18 @@ would previously result in `array[]`, but now prints properly.
|
|
950
1054
|
[@matt-wratt]: https://github.com/matt-wratt
|
951
1055
|
[@meleyal]: https://github.com/meleyal
|
952
1056
|
[@mmainz]: https://github.com/mmainz
|
1057
|
+
[@mmcnl]: https://github.com/mmcnl
|
953
1058
|
[@noahtheduke]: https://github.com/NoahTheDuke
|
954
1059
|
[@overload119]: https://github.com/Overload119
|
955
1060
|
[@petevk]: https://github.com/petevk
|
956
1061
|
[@pje]: https://github.com/pje
|
957
1062
|
[@rosskinsella]: https://github.com/RossKinsella
|
1063
|
+
[@rsullivan00]: https://github.com/Rsullivan00
|
1064
|
+
[@ryan-hunter-pc]: https://github.com/ryan-hunter-pc
|
958
1065
|
[@shaydavidson]: https://github.com/ShayDavidson
|
1066
|
+
[@steobrien]: https://github.com/steobrien
|
1067
|
+
[@sviccari]: https://github.com/SViccari
|
959
1068
|
[@tobyndockerill]: https://github.com/tobyndockerill
|
960
1069
|
[@uri]: https://github.com/uri
|
961
1070
|
[@xipgroc]: https://github.com/xipgroc
|
962
1071
|
[@yuki24]: https://github.com/yuki24
|
963
|
-
[@rsullivan00]: https://github.com/Rsullivan00
|
964
|
-
[@steobrien]: https://github.com/steobrien
|
965
|
-
[@jbielick]: https://github.com/jbielick
|
966
|
-
[@coiti]: https://github.com/coiti
|
data/CONTRIBUTING.md
CHANGED
@@ -22,7 +22,7 @@ In order to get printed, the code goes through a couple of transformations. The
|
|
22
22
|
|
23
23
|
### Text to AST
|
24
24
|
|
25
|
-
When the prettier process first spins up, it examines which files it's going to print and selects an appropriate plugin for each one. Once selected, it runs that plugin's `parse` function, seen [here](src/
|
25
|
+
When the prettier process first spins up, it examines which files it's going to print and selects an appropriate plugin for each one. Once selected, it runs that plugin's `parse` function, seen [here](src/parser.js). For the case of the Ruby plugin, that entails spawning a Ruby process that runs [parser.rb](src/parser.rb) with the input code preloaded on stdin.
|
26
26
|
|
27
27
|
`parser.rb` will read the text off of stdin and then feed it to a new `Ripper` instance, which is a Ruby standard library recursive-descent parser. Briefly, the way that `Ripper` works is by tokenizing the input and then matching those tokens against a grammar to form s-expressions. To extend `Ripper`, you overwrite the methods that control how those s-expressions are formed, e.g., to modify the s-expression that is formed when `Ripper` encounters a string literal, you would override the `#on_string_literal` method. Below is an example for seeing that in action.
|
28
28
|
|
@@ -71,7 +71,7 @@ Now that the text has been transformed into an AST that we can work with, `parse
|
|
71
71
|
|
72
72
|
### AST to Doc
|
73
73
|
|
74
|
-
Once prettier has a working AST, it will take it and call the selected plugin's [`
|
74
|
+
Once prettier has a working AST, it will take it and call the selected plugin's [`printNode` function](src/printer.js), whose purpose is to convert that AST into prettier's intermediate representation called Docs. It does this by handing the print function a `FastPath` object that keeps track of the state of the printing as it goes, and allows accessing various parts of the AST quickly.
|
75
75
|
|
76
76
|
Effectively, it walks the AST in the reverse direction from the way `Ripper` built it (top-down instead of bottom-up). The first node that gets passed into the `print` function is the `program` node as that's always on top. Then it is the `program` node's responsibility to recursively call print on its child nodes as it best sees fit.
|
77
77
|
|
@@ -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
|
|
@@ -168,8 +168,8 @@ While developing, we've built a couple of small utilities for debugging the `pre
|
|
168
168
|
|
169
169
|
- `bin/lex [file|source]` - outputs the tokens as ripper sees them
|
170
170
|
- `bin/sexp [file|source]` - outputs the AST that ripper builds before it gets passed back to `prettier`
|
171
|
+
- `bin/pragma [file]` - runs the `hasPragma` function against the given input file
|
171
172
|
- `bin/print [file|source]` - outputs the printed source of a Ruby file after running it through `prettier`
|
172
|
-
- `bin/has-pragma [file]` - runs the `hasPragma` function against the given input file
|
173
173
|
|
174
174
|
## Testing
|
175
175
|
|
data/README.md
CHANGED
@@ -122,31 +122,31 @@ 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
|
-
| `
|
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
|
+
| `rubyArrayLiteral` | `--ruby-array-literal` | `true` | When possible, favor the use of string and symbol array literals. |
|
130
|
+
| `rubyHashLabel` | `--ruby-hash-label` | `true` | When possible, uses the shortened hash key syntax, as opposed to hash rockets. |
|
131
|
+
| `rubyModifier` | `--ruby-modifier` | `true` | When it fits on one line, allows while and until statements to use the modifier form. |
|
132
|
+
| `rubySingleQuote` | `--ruby-single-quote` | `true` | When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals. |
|
133
|
+
| `rubyToProc` | `--ruby-to-proc` | `false` | When possible, convert blocks to the more concise `Symbol#to_proc` syntax. |
|
134
|
+
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
|
135
|
+
| `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
136
|
|
137
137
|
Any of these can be added to your existing [prettier configuration
|
138
138
|
file](https://prettier.io/docs/en/configuration.html). For example:
|
139
139
|
|
140
140
|
```json
|
141
141
|
{
|
142
|
-
"
|
142
|
+
"rubySingleQuote": false
|
143
143
|
}
|
144
144
|
```
|
145
145
|
|
146
146
|
Or, they can be passed to `prettier` as arguments:
|
147
147
|
|
148
148
|
```bash
|
149
|
-
prettier --
|
149
|
+
prettier --ruby-single-quote false --write '**/*.rb'
|
150
150
|
```
|
151
151
|
|
152
152
|
## Contributing
|
@@ -181,7 +181,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
181
181
|
</tr>
|
182
182
|
<tr>
|
183
183
|
<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>
|
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> <a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Aandyw8" title="Bug reports">🐛</a></td>
|
185
185
|
<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
186
|
<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
187
|
<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>
|
@@ -224,6 +224,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
224
224
|
<td align="center"><a href="https://joshbielick.com/"><img src="https://avatars2.githubusercontent.com/u/1413330?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Josh Bielick</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Ajbielick" title="Bug reports">🐛</a> <a href="https://github.com/prettier/plugin-ruby/commits?author=jbielick" title="Code">💻</a></td>
|
225
225
|
<td align="center"><a href="https://github.com/coiti"><img src="https://avatars3.githubusercontent.com/u/27384706?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Román Coitiño</b></sub></a><br /><a href="https://github.com/prettier/plugin-ruby/issues?q=author%3Acoiti" title="Bug reports">🐛</a></td>
|
226
226
|
</tr>
|
227
|
+
<tr>
|
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
|
+
<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
|
+
</tr>
|
227
231
|
</table>
|
228
232
|
|
229
233
|
<!-- markdownlint-restore -->
|
data/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prettier/plugin-ruby",
|
3
|
-
"version": "0.
|
3
|
+
"version": "1.0.1",
|
4
4
|
"description": "prettier plugin for the Ruby programming language",
|
5
5
|
"main": "src/ruby.js",
|
6
6
|
"scripts": {
|
7
|
+
"check-format": "prettier --check '**/*'",
|
7
8
|
"lint": "eslint --cache .",
|
8
|
-
"print": "prettier --plugin=.",
|
9
9
|
"test": "jest"
|
10
10
|
},
|
11
11
|
"repository": {
|
@@ -24,10 +24,10 @@
|
|
24
24
|
"devDependencies": {
|
25
25
|
"all-contributors-cli": "^6.14.1",
|
26
26
|
"eslint": "^7.8.1",
|
27
|
-
"eslint-config-prettier": "^
|
28
|
-
"husky": "^4.
|
27
|
+
"eslint-config-prettier": "^7.0.0",
|
28
|
+
"husky": "^4.3.5",
|
29
29
|
"jest": "^26.0.0",
|
30
|
-
"pretty-quick": "^3.
|
30
|
+
"pretty-quick": "^3.1.0"
|
31
31
|
},
|
32
32
|
"eslintConfig": {
|
33
33
|
"extends": [
|
@@ -61,6 +61,9 @@
|
|
61
61
|
}
|
62
62
|
},
|
63
63
|
"prettier": {
|
64
|
-
"trailingComma": "none"
|
64
|
+
"trailingComma": "none",
|
65
|
+
"plugins": [
|
66
|
+
"."
|
67
|
+
]
|
65
68
|
}
|
66
69
|
}
|
data/src/embed.js
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
const {
|
2
2
|
concat,
|
3
|
+
group,
|
3
4
|
indent,
|
4
|
-
|
5
|
+
lineSuffix,
|
5
6
|
mapDoc,
|
6
7
|
markAsRoot,
|
7
8
|
stripTrailingHardline
|
8
9
|
} = require("./prettier");
|
9
10
|
|
11
|
+
const { literalLineNoBreak } = require("./utils");
|
12
|
+
|
10
13
|
const parsers = {
|
11
14
|
css: "css",
|
12
15
|
javascript: "babel",
|
@@ -23,12 +26,12 @@ const replaceNewlines = (doc) =>
|
|
23
26
|
? concat(
|
24
27
|
currentDoc
|
25
28
|
.split(/(\n)/g)
|
26
|
-
.map((v, i) => (i % 2 === 0 ? v :
|
29
|
+
.map((v, i) => (i % 2 === 0 ? v : literalLineNoBreak))
|
27
30
|
)
|
28
31
|
: currentDoc
|
29
32
|
);
|
30
33
|
|
31
|
-
const embed = (path,
|
34
|
+
const embed = (path, print, textToDoc, _opts) => {
|
32
35
|
const node = path.getValue();
|
33
36
|
|
34
37
|
// Currently we only support embedded formatting on heredoc nodes
|
@@ -44,7 +47,7 @@ const embed = (path, _print, textToDoc, _opts) => {
|
|
44
47
|
|
45
48
|
// Next, find the parser associated with this heredoc (if there is one). For
|
46
49
|
// example, if you use <<~CSS, we'd hook it up to the css parser.
|
47
|
-
const parser = parsers[beging.slice(3).toLowerCase()];
|
50
|
+
const parser = parsers[beging.body.slice(3).toLowerCase()];
|
48
51
|
if (!parser) {
|
49
52
|
return null;
|
50
53
|
}
|
@@ -53,19 +56,35 @@ const embed = (path, _print, textToDoc, _opts) => {
|
|
53
56
|
// into the embedded parser. Get back the doc node.
|
54
57
|
const content = body.map((part) => part.body).join("");
|
55
58
|
const formatted = concat([
|
56
|
-
|
59
|
+
literalLineNoBreak,
|
57
60
|
replaceNewlines(stripTrailingHardline(textToDoc(content, { parser })))
|
58
61
|
]);
|
59
62
|
|
60
63
|
// If we're using a squiggly heredoc, then we can properly handle indentation
|
61
64
|
// ourselves.
|
62
|
-
if (beging[2] === "~") {
|
63
|
-
return concat([
|
65
|
+
if (beging.body[2] === "~") {
|
66
|
+
return concat([
|
67
|
+
path.call(print, "beging"),
|
68
|
+
lineSuffix(
|
69
|
+
group(
|
70
|
+
concat([
|
71
|
+
indent(markAsRoot(formatted)),
|
72
|
+
literalLineNoBreak,
|
73
|
+
ending.trim()
|
74
|
+
])
|
75
|
+
)
|
76
|
+
)
|
77
|
+
]);
|
64
78
|
}
|
65
79
|
|
66
80
|
// Otherwise, we need to just assume it's formatted correctly and return the
|
67
81
|
// content as it is.
|
68
|
-
return markAsRoot(
|
82
|
+
return markAsRoot(
|
83
|
+
concat([
|
84
|
+
path.call(print, "beging"),
|
85
|
+
lineSuffix(group(concat([formatted, literalLineNoBreak, ending.trim()])))
|
86
|
+
])
|
87
|
+
);
|
69
88
|
};
|
70
89
|
|
71
90
|
module.exports = embed;
|
data/src/nodes.js
CHANGED
@@ -8,11 +8,13 @@ module.exports = Object.assign(
|
|
8
8
|
require("./nodes/blocks"),
|
9
9
|
require("./nodes/calls"),
|
10
10
|
require("./nodes/case"),
|
11
|
+
require("./nodes/class"),
|
11
12
|
require("./nodes/commands"),
|
12
13
|
require("./nodes/conditionals"),
|
13
14
|
require("./nodes/constants"),
|
14
15
|
require("./nodes/flow"),
|
15
16
|
require("./nodes/hashes"),
|
17
|
+
require("./nodes/heredocs"),
|
16
18
|
require("./nodes/hooks"),
|
17
19
|
require("./nodes/ints"),
|
18
20
|
require("./nodes/lambdas"),
|
@@ -25,7 +27,8 @@ module.exports = Object.assign(
|
|
25
27
|
require("./nodes/regexp"),
|
26
28
|
require("./nodes/rescue"),
|
27
29
|
require("./nodes/return"),
|
28
|
-
require("./nodes/scopes"),
|
29
30
|
require("./nodes/statements"),
|
30
|
-
require("./nodes/strings")
|
31
|
+
require("./nodes/strings"),
|
32
|
+
require("./nodes/super"),
|
33
|
+
require("./nodes/undef")
|
31
34
|
);
|
data/src/nodes/alias.js
CHANGED
@@ -7,49 +7,47 @@ const {
|
|
7
7
|
line
|
8
8
|
} = require("../prettier");
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
function printAliasArgument(path, _opts, print, argIndex) {
|
10
|
+
// In general, return the printed doc of the argument at the provided index.
|
11
|
+
// Special handling is given for symbol literals that are not bare words, as we
|
12
|
+
// convert those into bare words by just pulling out the ident node.
|
13
|
+
function printAliasArgument(path, print, argIndex) {
|
15
14
|
const node = path.getValue().body[argIndex];
|
16
15
|
|
17
|
-
if (node.type === "symbol_literal"
|
16
|
+
if (node.type === "symbol_literal") {
|
18
17
|
// If we're going to descend into the symbol literal to grab out the ident
|
19
18
|
// node, then we need to make sure we copy over any comments as well,
|
20
19
|
// otherwise we could accidentally skip printing them.
|
21
20
|
if (node.comments) {
|
22
21
|
node.comments.forEach((comment) => {
|
23
|
-
addTrailingComment(node.body[0]
|
22
|
+
addTrailingComment(node.body[0], comment);
|
24
23
|
});
|
25
24
|
}
|
26
25
|
|
27
|
-
return path.call(print, "body", argIndex, "body", 0
|
26
|
+
return path.call(print, "body", argIndex, "body", 0);
|
28
27
|
}
|
29
28
|
|
30
29
|
return path.call(print, "body", argIndex);
|
31
30
|
}
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
*/
|
32
|
+
// The `alias` keyword is used to make a method respond to another name as well
|
33
|
+
// as the current one. For example, to get the method `foo` to also respond to
|
34
|
+
// `bar`, you would:
|
35
|
+
//
|
36
|
+
// alias bar foo
|
37
|
+
//
|
38
|
+
// Now, in the current context you can call `bar` and it will execute the `foo`
|
39
|
+
// method.
|
40
|
+
//
|
41
|
+
// When you're aliasing two methods, you can either provide bare words (like the
|
42
|
+
// example above) or you can provide symbols (note that this includes dynamic
|
43
|
+
// symbols like :"foo-#{bar}-baz"). In general, to be consistent with the ruby
|
44
|
+
// style guide, we prefer bare words:
|
45
|
+
//
|
46
|
+
// https://github.com/rubocop-hq/ruby-style-guide#alias-method-lexically
|
47
|
+
//
|
48
|
+
// The `alias` node contains two children. The left and right align with the
|
49
|
+
// arguments passed to the keyword. So, for the above example the left would be
|
50
|
+
// the symbol literal `bar` and the right could be the symbol literal `foo`.
|
53
51
|
function printAlias(path, opts, print) {
|
54
52
|
const keyword = "alias ";
|
55
53
|
|
@@ -57,14 +55,14 @@ function printAlias(path, opts, print) {
|
|
57
55
|
// If the left child has any comments, then we need to explicitly break this
|
58
56
|
// into two lines
|
59
57
|
path.getValue().body[0].comments ? hardline : line,
|
60
|
-
printAliasArgument(path,
|
58
|
+
printAliasArgument(path, print, 1)
|
61
59
|
]);
|
62
60
|
|
63
61
|
return group(
|
64
62
|
concat([
|
65
63
|
keyword,
|
66
|
-
printAliasArgument(path,
|
67
|
-
group(align(keyword, rightSide))
|
64
|
+
printAliasArgument(path, print, 0),
|
65
|
+
group(align(keyword.length, rightSide))
|
68
66
|
])
|
69
67
|
);
|
70
68
|
}
|