prettier 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +22 -11
- data/package.json +2 -2
- data/src/haml/parser.js +2 -2
- data/src/parser/getNetcat.js +17 -10
- data/src/parser/netcat.js +0 -2
- data/src/parser/parseSync.js +17 -2
- data/src/parser/requestParse.js +3 -3
- data/src/plugin.js +6 -0
- data/src/rbs/parser.js +2 -2
- data/src/ruby/nodes/args.js +8 -1
- data/src/ruby/parser.js +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c23f6803729e7a50ce180a31626443c85d3a622b16b2c49d4d0b80e8a89eb99
|
4
|
+
data.tar.gz: ba8d7d3939ac37e7ed8bb4b2c5efa68c06ac2cb9b217bac839779ee0901f1321
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8bb12d0468a507b63049340ab4709ac4cf001f9cb2941a3f83b4e22d265158b12efcc24f2a6e342b0e20eee39d6125549be9b224e76472be2c34c286d82b1af
|
7
|
+
data.tar.gz: 1187d27608c659d69f8e7c2d966002f451a0e43245110506814fcc5c6d54e865ef2d382bc6a66fabf4818994d0f82eff3e1c02c9108492026d44314ce85c34d4
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,14 @@ 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.5.4] - 2021-03-17
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- [#835](https://github.com/prettier/plugin-ruby/issues/835) - valscion, kddeisz - Array splat operator should not get moved by leading comments.
|
14
|
+
- [#836](https://github.com/prettier/plugin-ruby/issues/836) - valscion, kddeisz - Array splat operator should not get moved by trailing comments.
|
15
|
+
- [#821](https://github.com/prettier/plugin-ruby/issues/821) - jscheid, kddeisz - Better error handling when using GNU netcat.
|
16
|
+
|
9
17
|
## [1.5.3] - 2021-02-28
|
10
18
|
|
11
19
|
### Changed
|
@@ -1085,7 +1093,9 @@ would previously result in `array[]`, but now prints properly.
|
|
1085
1093
|
|
1086
1094
|
- Initial release 🎉
|
1087
1095
|
|
1088
|
-
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.5.
|
1096
|
+
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.5.4...HEAD
|
1097
|
+
[1.5.4]: https://github.com/prettier/plugin-ruby/compare/v1.5.3...v1.5.4
|
1098
|
+
[1.5.3]: https://github.com/prettier/plugin-ruby/compare/v1.5.2...v1.5.3
|
1089
1099
|
[1.5.2]: https://github.com/prettier/plugin-ruby/compare/v1.5.1...v1.5.2
|
1090
1100
|
[1.5.1]: https://github.com/prettier/plugin-ruby/compare/v1.5.0...v1.5.1
|
1091
1101
|
[1.5.0]: https://github.com/prettier/plugin-ruby/compare/v1.4.0...v1.5.0
|
data/README.md
CHANGED
@@ -128,17 +128,19 @@ The `prettier` executable is now installed and ready for use:
|
|
128
128
|
|
129
129
|
Below are the options (from [`src/plugin.js`](src/plugin.js)) that `@prettier/plugin-ruby` currently supports:
|
130
130
|
|
131
|
-
| API Option
|
132
|
-
|
|
133
|
-
| `printWidth`
|
134
|
-
| `requirePragma`
|
135
|
-
| `rubyArrayLiteral`
|
136
|
-
| `rubyHashLabel`
|
137
|
-
| `rubyModifier`
|
138
|
-
| `
|
139
|
-
|
140
|
-
| `
|
141
|
-
| `
|
131
|
+
| API Option | CLI Option | Default | Description |
|
132
|
+
| ------------------- | ----------------------- | :-----: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
133
|
+
| `printWidth` | `--print-width` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)). |
|
134
|
+
| `requirePragma` | `--require-pragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)). |
|
135
|
+
| `rubyArrayLiteral` | `--ruby-array-literal` | `true` | When possible, favor the use of string and symbol array literals. |
|
136
|
+
| `rubyHashLabel` | `--ruby-hash-label` | `true` | When possible, uses the shortened hash key syntax, as opposed to hash rockets. |
|
137
|
+
| `rubyModifier` | `--ruby-modifier` | `true` | When it fits on one line, allows while and until statements to use the modifier form. |
|
138
|
+
| `rubyNetcatCommand` | `--ruby-netcat-command` | | The prefix of the command to execute to communicate between the node.js process and the Ruby process. (For example, `"nc -U"` or `"telnet -u"`) Normally you should not set this option. |
|
139
|
+
|
140
|
+
| `rubySingleQuote` | `--ruby-single-quote` | `true` | When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals. |
|
141
|
+
| `rubyToProc` | `--ruby-to-proc` | `false` | When possible, convert blocks to the more concise `Symbol#to_proc` syntax. |
|
142
|
+
| `tabWidth` | `--tab-width` | `2` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)). |
|
143
|
+
| `trailingComma` | `--trailing-comma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#trailing-comma)). `"es5"` is equivalent to `true`. |
|
142
144
|
|
143
145
|
Any of these can be added to your existing [prettier configuration
|
144
146
|
file](https://prettier.io/docs/en/configuration.html). For example:
|
@@ -163,11 +165,20 @@ with some of RuboCop's functionality.
|
|
163
165
|
Prettier provides a RuboCop configuration file to disable the rules which clash.
|
164
166
|
To enable, add the following config at the top of your project's `.rubocop.yml`:
|
165
167
|
|
168
|
+
#### Ruby gem
|
169
|
+
|
166
170
|
```yaml
|
167
171
|
inherit_gem:
|
168
172
|
prettier: rubocop.yml
|
169
173
|
```
|
170
174
|
|
175
|
+
#### `npm` package
|
176
|
+
|
177
|
+
```yaml
|
178
|
+
inherit_from:
|
179
|
+
- node_modules/@prettier/plugin-ruby/rubocop.yml
|
180
|
+
```
|
181
|
+
|
171
182
|
## Contributing
|
172
183
|
|
173
184
|
Check out our [contributing guide](CONTRIBUTING.md). Bug reports and pull requests are welcome on GitHub at https://github.com/prettier/plugin-ruby.
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prettier/plugin-ruby",
|
3
|
-
"version": "1.5.
|
3
|
+
"version": "1.5.4",
|
4
4
|
"description": "prettier plugin for the Ruby programming language",
|
5
5
|
"main": "src/plugin.js",
|
6
6
|
"scripts": {
|
@@ -22,7 +22,7 @@
|
|
22
22
|
"prettier": ">=1.10"
|
23
23
|
},
|
24
24
|
"devDependencies": {
|
25
|
-
"eslint": "^7.
|
25
|
+
"eslint": "^7.22.0",
|
26
26
|
"eslint-config-prettier": "^8.0.0",
|
27
27
|
"husky": "^5.0.9",
|
28
28
|
"jest": "^26.0.0",
|
data/src/haml/parser.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
const parseSync = require("../parser/parseSync");
|
2
2
|
|
3
|
-
const parse = (text, _parsers,
|
4
|
-
return parseSync("haml", text);
|
3
|
+
const parse = (text, _parsers, opts) => {
|
4
|
+
return parseSync("haml", text, opts);
|
5
5
|
};
|
6
6
|
|
7
7
|
const pragmaPattern = /^\s*-#\s*@(prettier|format)/;
|
data/src/parser/getNetcat.js
CHANGED
@@ -16,35 +16,42 @@ function hasCommand(name) {
|
|
16
16
|
|
17
17
|
// Finds an netcat-like adapter to use for sending data to a socket. We order
|
18
18
|
// these by likelihood of being found so we can avoid some shell-outs.
|
19
|
-
function
|
19
|
+
function getCommandAndArgs() {
|
20
20
|
if (hasCommand("nc")) {
|
21
|
-
return ["nc", "-U"];
|
21
|
+
return ["nc", ["-U"]];
|
22
22
|
}
|
23
23
|
|
24
24
|
if (hasCommand("telnet")) {
|
25
|
-
return ["telnet", "-u"];
|
25
|
+
return ["telnet", ["-u"]];
|
26
26
|
}
|
27
27
|
|
28
28
|
if (hasCommand("ncat")) {
|
29
|
-
return ["ncat", "-U"];
|
29
|
+
return ["ncat", ["-U"]];
|
30
30
|
}
|
31
31
|
|
32
32
|
if (hasCommand("socat")) {
|
33
|
-
return ["socat", "-"];
|
33
|
+
return ["socat", ["-"]];
|
34
34
|
}
|
35
35
|
|
36
|
-
return ["node", require.resolve("./netcat.js")];
|
36
|
+
return ["node", [require.resolve("./netcat.js")]];
|
37
37
|
}
|
38
38
|
|
39
39
|
let command;
|
40
|
-
let
|
40
|
+
let args;
|
41
41
|
|
42
|
-
function getNetcat() {
|
42
|
+
function getNetcat(opts) {
|
43
43
|
if (!command) {
|
44
|
-
|
44
|
+
if (opts.rubyNetcatCommand) {
|
45
|
+
const splits = opts.rubyNetcatCommand.split(" ");
|
46
|
+
|
47
|
+
command = splits[0];
|
48
|
+
args = splits.slice(1);
|
49
|
+
} else {
|
50
|
+
[command, args] = getCommandAndArgs();
|
51
|
+
}
|
45
52
|
}
|
46
53
|
|
47
|
-
return { command,
|
54
|
+
return { command, args };
|
48
55
|
}
|
49
56
|
|
50
57
|
module.exports = getNetcat;
|
data/src/parser/netcat.js
CHANGED
@@ -5,11 +5,9 @@
|
|
5
5
|
const { createConnection } = require("net");
|
6
6
|
|
7
7
|
const sock = process.argv[process.argv.length - 1];
|
8
|
-
|
9
8
|
const client = createConnection(sock, () => process.stdin.pipe(client));
|
10
9
|
|
11
10
|
client.on("data", (data) => process.stdout.write(data));
|
12
|
-
|
13
11
|
client.on("error", (error) => {
|
14
12
|
console.error(error);
|
15
13
|
});
|
data/src/parser/parseSync.js
CHANGED
@@ -4,9 +4,24 @@ const requestParse = require("./requestParse");
|
|
4
4
|
// like it) here since Prettier requires the results of `parse` to be
|
5
5
|
// synchronous and Node.js does not offer a mechanism for synchronous socket
|
6
6
|
// requests.
|
7
|
-
function parseSync(parser, source) {
|
8
|
-
const { stdout, stderr, status } = requestParse(parser, source);
|
7
|
+
function parseSync(parser, source, opts) {
|
8
|
+
const { stdout, stderr, status } = requestParse(parser, source, opts);
|
9
9
|
|
10
|
+
// We need special handling in case the user's version of nc doesn't support
|
11
|
+
// using unix sockets.
|
12
|
+
if (stderr.includes("invalid option -- U")) {
|
13
|
+
throw new Error(`
|
14
|
+
@prettier/plugin-ruby uses netcat to communicate over unix sockets between
|
15
|
+
the node.js process running prettier and an underlying Ruby process used
|
16
|
+
for parsing. Unfortunately the version of netcat that you have installed
|
17
|
+
(GNU netcat) does not support unix sockets. To solve this either uninstall
|
18
|
+
GNU netcat and use a different implementation, or change the value of the
|
19
|
+
rubyNetcatCommand option in your prettier configuration.
|
20
|
+
`);
|
21
|
+
}
|
22
|
+
|
23
|
+
// If we didn't receive anything over stdout or we have a bad exit status,
|
24
|
+
// then throw whatever we can.
|
10
25
|
if (stdout.length === 0 || (status !== null && status !== 0)) {
|
11
26
|
throw new Error(stderr || "An unknown error occurred");
|
12
27
|
}
|
data/src/parser/requestParse.js
CHANGED
@@ -54,11 +54,11 @@ function ensureParseServer() {
|
|
54
54
|
}
|
55
55
|
|
56
56
|
// Sends a request to the parse server to parse the given content.
|
57
|
-
function requestParse(parser, source) {
|
57
|
+
function requestParse(parser, source, opts) {
|
58
58
|
ensureParseServer();
|
59
59
|
|
60
|
-
const { command,
|
61
|
-
const { stdout, stderr, status } = spawnSync(command,
|
60
|
+
const { command, args } = getNetcat(opts);
|
61
|
+
const { stdout, stderr, status } = spawnSync(command, args.concat(sockfile), {
|
62
62
|
input: `${parser}|${source}`,
|
63
63
|
maxBuffer: 15 * 1024 * 1024
|
64
64
|
});
|
data/src/plugin.js
CHANGED
@@ -119,6 +119,12 @@ module.exports = {
|
|
119
119
|
description:
|
120
120
|
"When it fits on one line, allows if, unless, while, and until statements to use the modifier form."
|
121
121
|
},
|
122
|
+
rubyNetcatCommand: {
|
123
|
+
type: "string",
|
124
|
+
category: "Ruby",
|
125
|
+
description:
|
126
|
+
'The prefix of the command to execute to communicate between the node.js process and the Ruby process. (For example, "nc -U" or "telnet -u") Normally you should not set this option.'
|
127
|
+
},
|
122
128
|
rubySingleQuote: {
|
123
129
|
type: "boolean",
|
124
130
|
category: "Ruby",
|
data/src/rbs/parser.js
CHANGED
@@ -4,8 +4,8 @@ const parseSync = require("../parser/parseSync");
|
|
4
4
|
// to prettier a JavaScript object that is the equivalent AST that represents
|
5
5
|
// the code stored in that string. We accomplish this by spawning a new Ruby
|
6
6
|
// process of parser.rb and reading JSON off STDOUT.
|
7
|
-
function parse(text, _parsers,
|
8
|
-
return parseSync("rbs", text);
|
7
|
+
function parse(text, _parsers, opts) {
|
8
|
+
return parseSync("rbs", text, opts);
|
9
9
|
}
|
10
10
|
|
11
11
|
const pragmaPattern = /#\s*@(prettier|format)/;
|
data/src/ruby/nodes/args.js
CHANGED
@@ -147,9 +147,16 @@ function printArgsAddStar(path, opts, print) {
|
|
147
147
|
// *values
|
148
148
|
// ]
|
149
149
|
//
|
150
|
+
// or if we have an array like:
|
151
|
+
//
|
152
|
+
// [
|
153
|
+
// *values # comment
|
154
|
+
// ]
|
155
|
+
//
|
150
156
|
// then we need to make sure we don't accidentally prepend the operator
|
151
157
|
// before the comment.
|
152
|
-
|
158
|
+
const index = node.body[1].comments.filter(({ leading }) => leading).length;
|
159
|
+
docs[1].parts[index] = concat(["*", docs[1].parts[index]]);
|
153
160
|
} else {
|
154
161
|
// If we don't have any comments, we can just prepend the operator
|
155
162
|
docs[1] = concat(["*", docs[1]]);
|
data/src/ruby/parser.js
CHANGED
@@ -4,8 +4,8 @@ const parseSync = require("../parser/parseSync");
|
|
4
4
|
// to prettier a JavaScript object that is the equivalent AST that represents
|
5
5
|
// the code stored in that string. We accomplish this by spawning a new Ruby
|
6
6
|
// process of parser.rb and reading JSON off STDOUT.
|
7
|
-
function parse(text, _parsers,
|
8
|
-
return parseSync("ruby", text);
|
7
|
+
function parse(text, _parsers, opts) {
|
8
|
+
return parseSync("ruby", text, opts);
|
9
9
|
}
|
10
10
|
|
11
11
|
const pragmaPattern = /#\s*@(prettier|format)/;
|
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: 1.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|