prettier 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f4a11b3b694651795ea82803d2b9efaafc70bc811409eeba50a76d48aff55bd
4
- data.tar.gz: '0039c5cd3d89db3dbff1e0b5c4cfb2f307838f77faec7c6a9c3d23781f22bb4a'
3
+ metadata.gz: 1a60ee62443799f6fdd3380700b4091b75e1f50658e01cad2cdf1ade440917f4
4
+ data.tar.gz: 4c95bb8ae2916d965e12cc376aa2c8df0ce985420e78edc45554c6412a4e3469
5
5
  SHA512:
6
- metadata.gz: 73dfee52bf2aaa09c15c6dc23f167ecf20ef983b368a0bac4ad3fb8d193044bb4109469a0eae06c93909ee0a5aef6e926035c083efe4fec9c696a2286efe3470
7
- data.tar.gz: 02bded0e2c06e9153a16391671886f695f433c0a035b00116dc9e4fdae01a309b66d8f9147431491e81979e135c1abe6e796bf5e4c0005ebd00579d85ca9df0c
6
+ metadata.gz: f449363349b3476457419d8374dd1127ac8bcfb7faf2afa1f20eb49b21968c2cd5301ad26731bde90e8de64f5604534f375ffcf7ef60bdb21b0fb3f95c160439
7
+ data.tar.gz: 27fde34295c91d167f693d5ab4c8e67c639d9302854a7ef2423552b978a9611615b94fa07b3dae6d20c611fc7bc9764820570555a88faf61450235c467ee757e
data/CHANGELOG.md CHANGED
@@ -6,6 +6,30 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.2.0] - 2022-07-22
10
+
11
+ ### Added
12
+
13
+ - [#1250](https://github.com/prettier/plugin-ruby/issues/1250) - alexf101, kddnewton - Respect the `tabWidth` option.
14
+
15
+ ### Changed
16
+
17
+ - [#1255](https://github.com/prettier/plugin-ruby/pull/1255) - soberstadt - The rake task now runs check if write is false.
18
+ - [#1237](https://github.com/prettier/plugin-ruby/issues/1237) - boris-petrov - Disable the style rules associated with quotes.
19
+ - [#1248](https://github.com/prettier/plugin-ruby/pull/1248) - mhssmnn - Fix process waiting on STDIN.
20
+
21
+ ## [3.1.2] - 2022-05-13
22
+
23
+ ### Changed
24
+
25
+ - [#1127](https://github.com/prettier/plugin-ruby/issues/1227) - mscrivo, kddnewton - Support passing the `printWidth` option.
26
+
27
+ ## [3.1.1] - 2022-05-12
28
+
29
+ ### Changed
30
+
31
+ - [#1125](https://github.com/prettier/plugin-ruby/pull/1225) - kddnewton - Update the bundled rubocop config to be in sync with Syntax Tree.
32
+
9
33
  ## [3.1.0] - 2022-05-12
10
34
 
11
35
  ### Added
@@ -1231,7 +1255,10 @@ would previously result in `array[]`, but now prints properly.
1231
1255
 
1232
1256
  - Initial release 🎉
1233
1257
 
1234
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v3.0.0...HEAD
1258
+ [unreleased]: https://github.com/prettier/plugin-ruby/compare/v3.1.2...HEAD
1259
+ [3.1.2]: https://github.com/prettier/plugin-ruby/compare/v3.1.1...v3.1.2
1260
+ [3.1.1]: https://github.com/prettier/plugin-ruby/compare/v3.1.0...v3.1.1
1261
+ [3.1.0]: https://github.com/prettier/plugin-ruby/compare/v3.0.0...v3.1.0
1235
1262
  [3.0.0]: https://github.com/prettier/plugin-ruby/compare/v2.1.0...v3.0.0
1236
1263
  [2.1.0]: https://github.com/prettier/plugin-ruby/compare/v2.0.0...v2.1.0
1237
1264
  [2.0.0]: https://github.com/prettier/plugin-ruby/compare/v2.0.0-rc4...v2.0.0
data/README.md CHANGED
@@ -68,7 +68,7 @@ end
68
68
 
69
69
  ## Getting started
70
70
 
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.
71
+ To run `prettier` with the Ruby plugin, you're going to need [`ruby`](https://www.ruby-lang.org/en/documentation/installation/) (version `2.7.3` 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
72
 
73
73
  Note that currently the editor integrations work best with the `npm` package, as most of the major editor plugins expect a `node_modules` directory. You can get them to work with the Ruby gem, but it requires manually configuring the paths.
74
74
 
@@ -121,7 +121,7 @@ yarn add --dev prettier @prettier/plugin-ruby
121
121
  You'll also need to add the necessary Ruby dependencies. You can do this by running:
122
122
 
123
123
  ```bash
124
- gem install bundler syntax_tree syntax_tree-haml syntax_tree-rbs
124
+ gem install bundler prettier_print syntax_tree syntax_tree-haml syntax_tree-rbs
125
125
  ```
126
126
 
127
127
  The `prettier` executable is now installed and ready for use:
@@ -49,7 +49,7 @@ module Prettier
49
49
  end
50
50
 
51
51
  def run_task
52
- Prettier.run([("--write" if write), source_files].compact)
52
+ Prettier.run([write ? "--write" : "--check", source_files].compact)
53
53
  exit($?.exitstatus) if $?&.exited?
54
54
  end
55
55
  end
data/lib/prettier.rb CHANGED
@@ -11,9 +11,10 @@ module Prettier
11
11
  def self.run(args)
12
12
  quoted = args.map { |arg| arg.start_with?("-") ? arg : "\"#{arg}\"" }
13
13
  command = "node #{BINARY} --plugin \"#{PLUGIN}\" #{quoted.join(" ")}"
14
+ opts = STDIN.tty? ? {} : { stdin_data: STDIN }
14
15
 
15
16
  stdout, stderr, status =
16
- Open3.capture3({ "RBPRETTIER" => "1" }, command, stdin_data: STDIN)
17
+ Open3.capture3({ "RBPRETTIER" => "1" }, command, opts)
17
18
  STDOUT.puts(stdout)
18
19
 
19
20
  # If we completed successfully, then just exit out.
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/plugin.js",
6
6
  "scripts": {
data/rubocop.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  # Disabling all Layout/* rules, as they're unnecessary when the user is using
2
- # prettier to handle all of the formatting.
3
-
2
+ # Syntax Tree to handle all of the formatting.
4
3
  Layout:
5
4
  Enabled: false
6
5
 
@@ -16,6 +15,16 @@ Layout/LineLength:
16
15
  Style/MultilineIfModifier:
17
16
  Enabled: false
18
17
 
18
+ # Syntax Tree will expand empty methods to put the end keyword on the subsequent
19
+ # line to reduce git diff noise.
20
+ Style/EmptyMethod:
21
+ EnforcedStyle: expanded
22
+
23
+ # lambdas that are constructed with the lambda method call cannot be safely
24
+ # turned into lambda literals without removing a method call.
25
+ Style/Lambda:
26
+ Enabled: false
27
+
19
28
  # When method chains with multiple blocks are chained together, rubocop will let
20
29
  # them pass if they're using braces but not if they're using do and end
21
30
  # keywords. Because we will break individual blocks down to using keywords if
@@ -23,12 +32,28 @@ Style/MultilineIfModifier:
23
32
  Style/MultilineBlockChain:
24
33
  Enabled: false
25
34
 
35
+ # Disable the single- vs double-quotes rules as these depend on whether the user
36
+ # has added or not `plugin/single_quotes` for `syntax_tree`
37
+ Style/StringLiterals:
38
+ Enabled: false
39
+
40
+ Style/StringLiteralsInInterpolation:
41
+ Enabled: false
42
+
43
+ Style/QuotedSymbols:
44
+ Enabled: false
45
+
46
+ # We let users have a little more freedom with symbol and words arrays. If the
47
+ # user only has an individual item like ["value"] then we don't bother
48
+ # converting it because it ends up being just noise.
26
49
  Style/SymbolArray:
27
50
  Enabled: false
28
51
 
29
52
  Style/WordArray:
30
53
  Enabled: false
31
54
 
55
+ # Disable the trailing-comma rules as these depend on whether the user has added
56
+ # or not `plugin/trailing_comma` for `syntax_tree`
32
57
  Style/TrailingCommaInArguments:
33
58
  Enabled: false
34
59
 
@@ -37,8 +62,3 @@ Style/TrailingCommaInArrayLiteral:
37
62
 
38
63
  Style/TrailingCommaInHashLiteral:
39
64
  Enabled: false
40
-
41
- # lambdas that are constructed with the lambda method call cannot be safely
42
- # turned into lambda literals without removing a method call.
43
- Style/Lambda:
44
- Enabled: false
data/src/parseSync.js CHANGED
@@ -181,7 +181,7 @@ function parseSync(parser, source, opts) {
181
181
  }
182
182
 
183
183
  const response = spawnSync(parserArgs.cmd, parserArgs.args, {
184
- input: `${parser}|${source}`,
184
+ input: `${parser}|${opts.printWidth}|${opts.tabWidth}|${source}`,
185
185
  maxBuffer: 15 * 1024 * 1024
186
186
  });
187
187
 
data/src/server.rb CHANGED
@@ -6,6 +6,7 @@ require "json"
6
6
  require "fileutils"
7
7
  require "open3"
8
8
 
9
+ require "prettier_print"
9
10
  require "syntax_tree"
10
11
  require "syntax_tree/haml"
11
12
  require "syntax_tree/rbs"
@@ -73,7 +74,8 @@ listener =
73
74
 
74
75
  # Start up a new thread that will handle each successive connection.
75
76
  Thread.new(server.accept_nonblock) do |socket|
76
- parser, source = socket.read.force_encoding("UTF-8").split("|", 2)
77
+ parser, maxwidth_string, tabwidth_string, source =
78
+ socket.read.force_encoding("UTF-8").split("|", 4)
77
79
 
78
80
  source.each_line do |line|
79
81
  case line
@@ -90,16 +92,40 @@ listener =
90
92
  end
91
93
  end
92
94
 
95
+ # At the moment, we're not going to support odd tabwidths. It's going to
96
+ # have to be a multiple of 2, because of the way that the prettyprint
97
+ # gem functions. So we're going to just use integer division here.
98
+ scalar = tabwidth_string.to_i / 2
99
+ genspace = ->(n) { " " * n * scalar }
100
+
101
+ maxwidth = maxwidth_string.to_i
93
102
  response =
94
103
  case parser
95
104
  when "ping"
96
105
  "pong"
97
106
  when "ruby"
98
- SyntaxTree.format(source)
107
+ formatter =
108
+ SyntaxTree::Formatter.new(source, [], maxwidth, "\n", &genspace)
109
+ SyntaxTree.parse(source).format(formatter)
110
+ formatter.flush
111
+ formatter.output.join
99
112
  when "rbs"
100
- SyntaxTree::RBS.format(source)
113
+ formatter =
114
+ SyntaxTree::RBS::Formatter.new(
115
+ source,
116
+ [],
117
+ maxwidth,
118
+ "\n",
119
+ &genspace
120
+ )
121
+ SyntaxTree::RBS.parse(source).format(formatter)
122
+ formatter.flush
123
+ formatter.output.join
101
124
  when "haml"
102
- SyntaxTree::Haml.format(source)
125
+ formatter = PrettierPrint.new(+"", maxwidth, "\n", &genspace)
126
+ SyntaxTree::Haml.parse(source).format(formatter)
127
+ formatter.flush
128
+ formatter.output
103
129
  end
104
130
 
105
131
  if response
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prettier
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-12 00:00:00.000000000 Z
11
+ date: 2022-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: syntax_tree
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.1
19
+ version: 2.7.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.1
26
+ version: 2.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: syntax_tree-haml
29
29
  requirement: !ruby/object:Gem::Requirement