prettier 3.0.0 → 3.1.2

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: edc974795ef0adb86312682bdedfa30cca29905f660b97334326494b8623144f
4
- data.tar.gz: 9dcdc7ecb78e7ee4fa333b45e9f2e4b5ea5df4615869ce6b172377bf21126560
3
+ metadata.gz: 69429c1f7b0cc5b82babb8463afcdacbb30026b0c9a77afcf8f6c4dbddd5b545
4
+ data.tar.gz: f81d934981c3086071371a9013184fbb19543dd7a86ca4258addd5870defbe73
5
5
  SHA512:
6
- metadata.gz: ed0166367d99fc0af3135d76c47dae06bcddd92eaf9a7d3d680726d403a2eed16f08af8fe410c527113bf00d1a0fe11b4c6743820e4c907b2de2707884655ef3
7
- data.tar.gz: c8fa9abb2ecf3561c913f9505f7d07c56e322c6f3031d44b9725c314bfb1576c0dc68c7c7e28f8a15f9d876c4307c0c90549e1db83a4c94b184e0a872413208d
6
+ metadata.gz: e6e612eb427b6c244c365b4595d1cefb0987e43255a541accd4843cadd4c73c0c5dd96268cf6ed8444afe2c2008e4792e3ad3155474d6ec20ffb880f65c23fb7
7
+ data.tar.gz: f825fb2f339e52c9c9dae9b287b5f21436fadaaea29ed0e93b14ee0ebb97bfaaac9aa1e16eaa2549b4a66e513c1007a3f48e1aa587efe6032568f77afd85d77f
data/CHANGELOG.md CHANGED
@@ -6,6 +6,24 @@ 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.1.2] - 2022-05-13
10
+
11
+ ### Changed
12
+
13
+ - [#1127](https://github.com/prettier/plugin-ruby/issues/1227) - mscrivo, kddnewton - Support passing the `printWidth` option.
14
+
15
+ ## [3.1.1] - 2022-05-12
16
+
17
+ ### Changed
18
+
19
+ - [#1125](https://github.com/prettier/plugin-ruby/pull/1225) - kddnewton - Update the bundled rubocop config to be in sync with Syntax Tree.
20
+
21
+ ## [3.1.0] - 2022-05-12
22
+
23
+ ### Added
24
+
25
+ - [#1224](https://github.com/prettier/plugin-ruby/pull/1224) - kddnewton - Support passing the `rubyPlugins` option to configure Syntax Tree.
26
+
9
27
  ## [3.0.0] - 2022-05-04
10
28
 
11
29
  ### Added
@@ -1225,7 +1243,10 @@ would previously result in `array[]`, but now prints properly.
1225
1243
 
1226
1244
  - Initial release 🎉
1227
1245
 
1228
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v3.0.0...HEAD
1246
+ [unreleased]: https://github.com/prettier/plugin-ruby/compare/v3.1.2...HEAD
1247
+ [3.1.2]: https://github.com/prettier/plugin-ruby/compare/v3.1.1...v3.1.2
1248
+ [3.1.1]: https://github.com/prettier/plugin-ruby/compare/v3.1.0...v3.1.1
1249
+ [3.1.0]: https://github.com/prettier/plugin-ruby/compare/v3.0.0...v3.1.0
1229
1250
  [3.0.0]: https://github.com/prettier/plugin-ruby/compare/v2.1.0...v3.0.0
1230
1251
  [2.1.0]: https://github.com/prettier/plugin-ruby/compare/v2.0.0...v2.1.0
1231
1252
  [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 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:
@@ -134,11 +134,12 @@ The `prettier` executable is now installed and ready for use:
134
134
 
135
135
  Below are the options (from [`src/plugin.js`](src/plugin.js)) that `@prettier/plugin-ruby` currently supports:
136
136
 
137
- | API Option | CLI Option | Default | Description |
138
- | --------------- | ------------------ | :-----: | --------------------------------------------------------------------------------------------------- |
139
- | `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
140
- | `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). |
141
- | `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
137
+ | API Option | CLI Option | Default | Description |
138
+ | --------------- | ------------------ | :-----: | --------------------------------------------------------------------------------------------------------------------------- |
139
+ | `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
140
+ | `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). |
141
+ | `rubyPlugins` | `--ruby-plugins` | `""` | The comma-separated list of plugins to require. See [Syntax Tree](https://github.com/ruby-syntax-tree/syntax_tree#plugins). |
142
+ | `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
142
143
 
143
144
  Any of these can be added to your existing [prettier configuration
144
145
  file](https://prettier.io/docs/en/configuration.html). For example:
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "3.0.0",
3
+ "version": "3.1.2",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/plugin.js",
6
6
  "scripts": {
@@ -22,9 +22,9 @@
22
22
  "prettier": ">=2.3.0"
23
23
  },
24
24
  "devDependencies": {
25
- "eslint": "^8.1.0",
25
+ "eslint": "^8.15.0",
26
26
  "eslint-config-prettier": "^8.0.0",
27
- "husky": "^7.0.0",
27
+ "husky": "^8.0.1",
28
28
  "jest": "^28.0.1",
29
29
  "pretty-quick": "^3.1.2"
30
30
  },
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
+ # Syntax Tree by default uses double quotes, so changing the configuration here
36
+ # to match that.
37
+ Style/StringLiterals:
38
+ EnforcedStyle: double_quotes
39
+
40
+ Style/StringLiteralsInInterpolation:
41
+ EnforcedStyle: double_quotes
42
+
43
+ Style/QuotedSymbols:
44
+ EnforcedStyle: double_quotes
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
+ # We don't support trailing commas in Syntax Tree by default, so just turning
56
+ # these off for now.
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
@@ -63,7 +63,7 @@ function getInfoFilepath() {
63
63
  // server with that filepath as an argument, then spawn another process that
64
64
  // will read that information in order to enable us to connect to it in the
65
65
  // spawnSync function.
66
- function spawnServer() {
66
+ function spawnServer(opts) {
67
67
  const tempDir = mkdtempSync(path.join(os.tmpdir(), "prettier-plugin-ruby-"));
68
68
  const filepath = getInfoFilepath();
69
69
 
@@ -114,11 +114,15 @@ function spawnServer() {
114
114
  };
115
115
  }
116
116
 
117
- const server = spawn("ruby", [serverRbPath, filepath], {
118
- env: Object.assign({}, process.env, { LANG: getLang() }),
119
- detached: true,
120
- stdio: "inherit"
121
- });
117
+ const server = spawn(
118
+ "ruby",
119
+ [serverRbPath, `--plugins=${opts.rubyPlugins}`, filepath],
120
+ {
121
+ env: Object.assign({}, process.env, { LANG: getLang() }),
122
+ detached: true,
123
+ stdio: "inherit"
124
+ }
125
+ );
122
126
 
123
127
  server.unref();
124
128
  process.on("exit", () => {
@@ -171,13 +175,13 @@ function runningInPnPZip() {
171
175
  // like it) here since Prettier requires the results of `parse` to be
172
176
  // synchronous and Node.js does not offer a mechanism for synchronous socket
173
177
  // requests.
174
- function parseSync(parser, source) {
178
+ function parseSync(parser, source, opts) {
175
179
  if (!parserArgs) {
176
- parserArgs = spawnServer();
180
+ parserArgs = spawnServer(opts);
177
181
  }
178
182
 
179
183
  const response = spawnSync(parserArgs.cmd, parserArgs.args, {
180
- input: `${parser}|${source}`,
184
+ input: `${parser}|${opts.printWidth}|${source}`,
181
185
  maxBuffer: 15 * 1024 * 1024
182
186
  });
183
187
 
data/src/plugin.js CHANGED
@@ -81,8 +81,8 @@ const plugin = {
81
81
  ],
82
82
  parsers: {
83
83
  ruby: {
84
- parse(text) {
85
- return parseSync("ruby", text);
84
+ parse(text, _parsers, opts) {
85
+ return parseSync("ruby", text, opts);
86
86
  },
87
87
  astFormat: "ruby",
88
88
  hasPragma(text) {
@@ -96,8 +96,8 @@ const plugin = {
96
96
  }
97
97
  },
98
98
  rbs: {
99
- parse(text) {
100
- return parseSync("rbs", text);
99
+ parse(text, _parsers, opts) {
100
+ return parseSync("rbs", text, opts);
101
101
  },
102
102
  astFormat: "rbs",
103
103
  hasPragma(text) {
@@ -111,8 +111,8 @@ const plugin = {
111
111
  }
112
112
  },
113
113
  haml: {
114
- parse(text) {
115
- return parseSync("haml", text);
114
+ parse(text, _parsers, opts) {
115
+ return parseSync("haml", text, opts);
116
116
  },
117
117
  astFormat: "haml",
118
118
  hasPragma(text) {
@@ -152,6 +152,15 @@ const plugin = {
152
152
  }
153
153
  }
154
154
  },
155
+ options: {
156
+ rubyPlugins: {
157
+ type: "string",
158
+ category: "Ruby",
159
+ default: "",
160
+ description: "The comma-separated list of plugins to require",
161
+ since: "3.1.0"
162
+ }
163
+ },
155
164
  defaultOptions: {
156
165
  printWidth: 80,
157
166
  tabWidth: 2
data/src/server.rb CHANGED
@@ -6,10 +6,16 @@ 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"
12
13
 
14
+ # First, require all of the plugins that the user specified.
15
+ ARGV.shift[/^--plugins=(.*)$/, 1]
16
+ .split(",")
17
+ .each { |plugin| require "syntax_tree/#{plugin}" }
18
+
13
19
  # Make sure we trap these signals to be sure we get the quit command coming from
14
20
  # the parent node process
15
21
  quit = false
@@ -68,7 +74,8 @@ listener =
68
74
 
69
75
  # Start up a new thread that will handle each successive connection.
70
76
  Thread.new(server.accept_nonblock) do |socket|
71
- parser, source = socket.read.force_encoding("UTF-8").split("|", 2)
77
+ parser, width, source =
78
+ socket.read.force_encoding("UTF-8").split("|", 3)
72
79
 
73
80
  source.each_line do |line|
74
81
  case line
@@ -85,16 +92,25 @@ listener =
85
92
  end
86
93
  end
87
94
 
95
+ maxwidth = width.to_i
88
96
  response =
89
97
  case parser
90
98
  when "ping"
91
99
  "pong"
92
100
  when "ruby"
93
- SyntaxTree.format(source)
101
+ formatter = SyntaxTree::Formatter.new(source, [], maxwidth)
102
+ SyntaxTree.parse(source).format(formatter)
103
+ formatter.flush
104
+ formatter.output.join
94
105
  when "rbs"
95
- SyntaxTree::RBS.format(source)
106
+ formatter = SyntaxTree::RBS::Formatter.new(source, [], maxwidth)
107
+ SyntaxTree::RBS.parse(source).format(formatter)
108
+ formatter.flush
109
+ formatter.output.join
96
110
  when "haml"
97
- SyntaxTree::Haml.format(source)
111
+ PrettierPrint.format(+"", maxwidth) do |q|
112
+ SyntaxTree::Haml.parse(source).format(q)
113
+ end
98
114
  end
99
115
 
100
116
  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.0.0
4
+ version: 3.1.2
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-05 00:00:00.000000000 Z
11
+ date: 2022-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: syntax_tree