prettier 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/package.json +4 -4
- data/rubocop.yml +3 -0
- data/src/haml/parser.rb +0 -2
- data/src/parser/parseSync.js +10 -15
- data/src/parser/server.rb +5 -0
- data/src/rbs/parser.rb +0 -2
- data/src/ruby/nodes/args.js +59 -18
- data/src/ruby/parser.rb +22 -0
- 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: 1247c9f95d56f0bd5171d119a1376dc155670f372dcf2d09d8c082f35d89903a
|
4
|
+
data.tar.gz: f85697402fa353f3355312e70b267b4e53b9edf9540fa2ace6ea31dbe84ddacb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd77c84b3f038ff3026814fd347602588d0bc5170c756873adb4dee7630aed45305f0e9353718e006b41eca8b10798a383e804a4f77993635e74a34b699a5522
|
7
|
+
data.tar.gz: 6836a386fccfbc80916b2abe99f23d4a44e1c52f859f7aaed7d8a3f8b27c104a3222c547860e09f198f4310988666e6f205751c1ae5f6afaed0950968338d459
|
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.3] - 2021-02-28
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- [#812](https://github.com/prettier/plugin-ruby/issues/812) - valscion, kddeisz - Splats and blocks within args that have comments attached should place their respective operators in the right place.
|
14
|
+
- [#816](https://github.com/prettier/plugin-ruby/pull/816) - valscion - Document RuboCop's Style/Lambda should be disabled
|
15
|
+
- [#814](https://github.com/prettier/plugin-ruby/issues/814) - jscheid, kddeisz - Provide better errors when the source location of the error is known.
|
16
|
+
|
9
17
|
## [1.5.2] - 2021-02-03
|
10
18
|
|
11
19
|
### Changed
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prettier/plugin-ruby",
|
3
|
-
"version": "1.5.
|
3
|
+
"version": "1.5.3",
|
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": ">=1.10"
|
23
23
|
},
|
24
24
|
"devDependencies": {
|
25
|
-
"eslint": "^7.
|
26
|
-
"eslint-config-prettier": "^
|
27
|
-
"husky": "^
|
25
|
+
"eslint": "^7.21.0",
|
26
|
+
"eslint-config-prettier": "^8.0.0",
|
27
|
+
"husky": "^5.0.9",
|
28
28
|
"jest": "^26.0.0",
|
29
29
|
"pretty-quick": "^3.1.0"
|
30
30
|
},
|
data/rubocop.yml
CHANGED
data/src/haml/parser.rb
CHANGED
data/src/parser/parseSync.js
CHANGED
@@ -5,26 +5,21 @@ const requestParse = require("./requestParse");
|
|
5
5
|
// synchronous and Node.js does not offer a mechanism for synchronous socket
|
6
6
|
// requests.
|
7
7
|
function parseSync(parser, source) {
|
8
|
-
const
|
8
|
+
const { stdout, stderr, status } = requestParse(parser, source);
|
9
9
|
|
10
|
-
if (
|
11
|
-
|
12
|
-
(response.status !== null && response.status !== 0)
|
13
|
-
) {
|
14
|
-
console.error("Could not parse response from server");
|
15
|
-
console.error(response);
|
16
|
-
|
17
|
-
throw new Error(response.stderr || "An unknown error occurred");
|
10
|
+
if (stdout.length === 0 || (status !== null && status !== 0)) {
|
11
|
+
throw new Error(stderr || "An unknown error occurred");
|
18
12
|
}
|
19
13
|
|
20
|
-
const parsed = JSON.parse(
|
14
|
+
const parsed = JSON.parse(stdout);
|
21
15
|
|
22
16
|
if (parsed.error) {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
const error = new Error(parsed.error);
|
18
|
+
if (parsed.loc) {
|
19
|
+
error.loc = parsed.loc;
|
20
|
+
}
|
21
|
+
|
22
|
+
throw error;
|
28
23
|
}
|
29
24
|
|
30
25
|
return parsed;
|
data/src/parser/server.rb
CHANGED
@@ -48,6 +48,11 @@ loop do
|
|
48
48
|
else
|
49
49
|
socket.write('{ "error": true }')
|
50
50
|
end
|
51
|
+
rescue Prettier::Parser::ParserError => error
|
52
|
+
loc = { start: { line: error.lineno, column: error.column } }
|
53
|
+
socket.write(JSON.fast_generate(error: error.message, loc: loc))
|
54
|
+
rescue StandardError => error
|
55
|
+
socket.write(JSON.fast_generate(error: error.message))
|
51
56
|
ensure
|
52
57
|
socket.close
|
53
58
|
end
|
data/src/rbs/parser.rb
CHANGED
data/src/ruby/nodes/args.js
CHANGED
@@ -106,25 +106,66 @@ function printArgs(path, { rubyToProc }, print) {
|
|
106
106
|
return args;
|
107
107
|
}
|
108
108
|
|
109
|
+
function printArgsAddBlock(path, opts, print) {
|
110
|
+
const node = path.getValue();
|
111
|
+
const parts = path.call(print, "body", 0);
|
112
|
+
|
113
|
+
if (node.body[1]) {
|
114
|
+
let blockDoc = path.call(print, "body", 1);
|
115
|
+
|
116
|
+
if (node.body[1].comments) {
|
117
|
+
// If we have a method call like:
|
118
|
+
//
|
119
|
+
// foo(
|
120
|
+
// # comment
|
121
|
+
// &block
|
122
|
+
// )
|
123
|
+
//
|
124
|
+
// then we need to make sure we don't accidentally prepend the operator
|
125
|
+
// before the comment.
|
126
|
+
blockDoc.parts[2] = concat(["&", blockDoc.parts[2]]);
|
127
|
+
} else {
|
128
|
+
// If we don't have any comments, we can just prepend the operator
|
129
|
+
blockDoc = concat(["&", blockDoc]);
|
130
|
+
}
|
131
|
+
|
132
|
+
parts.push(blockDoc);
|
133
|
+
}
|
134
|
+
|
135
|
+
return parts;
|
136
|
+
}
|
137
|
+
|
138
|
+
function printArgsAddStar(path, opts, print) {
|
139
|
+
const node = path.getValue();
|
140
|
+
const docs = path.map(print, "body");
|
141
|
+
|
142
|
+
if (node.body[1].comments) {
|
143
|
+
// If we have an array like:
|
144
|
+
//
|
145
|
+
// [
|
146
|
+
// # comment
|
147
|
+
// *values
|
148
|
+
// ]
|
149
|
+
//
|
150
|
+
// then we need to make sure we don't accidentally prepend the operator
|
151
|
+
// before the comment.
|
152
|
+
docs[1].parts[2] = concat(["*", docs[1].parts[2]]);
|
153
|
+
} else {
|
154
|
+
// If we don't have any comments, we can just prepend the operator
|
155
|
+
docs[1] = concat(["*", docs[1]]);
|
156
|
+
}
|
157
|
+
|
158
|
+
return docs[0].concat(docs[1]).concat(docs.slice(2));
|
159
|
+
}
|
160
|
+
|
161
|
+
function printBlockArg(path, opts, print) {
|
162
|
+
return concat(["&", path.call(print, "body", 0)]);
|
163
|
+
}
|
164
|
+
|
109
165
|
module.exports = {
|
110
166
|
arg_paren: printArgParen,
|
111
167
|
args: printArgs,
|
112
|
-
args_add_block:
|
113
|
-
|
114
|
-
|
115
|
-
if (path.getValue().body[1]) {
|
116
|
-
parts.push(concat(["&", path.call(print, "body", 1)]));
|
117
|
-
}
|
118
|
-
|
119
|
-
return parts;
|
120
|
-
},
|
121
|
-
args_add_star: (path, opts, print) => {
|
122
|
-
const printed = path.map(print, "body");
|
123
|
-
const parts = printed[0]
|
124
|
-
.concat([concat(["*", printed[1]])])
|
125
|
-
.concat(printed.slice(2));
|
126
|
-
|
127
|
-
return parts;
|
128
|
-
},
|
129
|
-
blockarg: (path, opts, print) => concat(["&", path.call(print, "body", 0)])
|
168
|
+
args_add_block: printArgsAddBlock,
|
169
|
+
args_add_star: printArgsAddStar,
|
170
|
+
blockarg: printBlockArg
|
130
171
|
};
|
data/src/ruby/parser.rb
CHANGED
@@ -1729,6 +1729,28 @@ class Prettier::Parser < Ripper
|
|
1729
1729
|
)
|
1730
1730
|
end
|
1731
1731
|
|
1732
|
+
# A special parser error so that we can get nice syntax displays on the error
|
1733
|
+
# message when prettier prints out the results.
|
1734
|
+
class ParserError < StandardError
|
1735
|
+
attr_reader :lineno, :column
|
1736
|
+
|
1737
|
+
def initialize(error, lineno, column)
|
1738
|
+
super(error)
|
1739
|
+
@lineno = lineno
|
1740
|
+
@column = column
|
1741
|
+
end
|
1742
|
+
end
|
1743
|
+
|
1744
|
+
# If we encounter a parse error, just immediately bail out so that our runner
|
1745
|
+
# can catch it.
|
1746
|
+
def on_parse_error(error, *)
|
1747
|
+
raise ParserError.new(error, lineno, column)
|
1748
|
+
end
|
1749
|
+
alias on_alias_error on_parse_error
|
1750
|
+
alias on_assign_error on_parse_error
|
1751
|
+
alias on_class_name_error on_parse_error
|
1752
|
+
alias on_param_error on_parse_error
|
1753
|
+
|
1732
1754
|
# The program node is the very top of the AST. Here we'll attach all of
|
1733
1755
|
# the comments that we've gathered up over the course of parsing the
|
1734
1756
|
# source string. We'll also attach on the __END__ content if there was
|
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.3
|
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-02-
|
11
|
+
date: 2021-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|