prettier 1.5.2 → 1.5.3

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: 97cf5963c684d5bf17079800c59b79fb15f787c89c1b1d7bd315c3851307737f
4
- data.tar.gz: 721e04eaa93f654d873e2b972b718b3d1db41d7acca278b8eec743aa92daf755
3
+ metadata.gz: 1247c9f95d56f0bd5171d119a1376dc155670f372dcf2d09d8c082f35d89903a
4
+ data.tar.gz: f85697402fa353f3355312e70b267b4e53b9edf9540fa2ace6ea31dbe84ddacb
5
5
  SHA512:
6
- metadata.gz: fe8997d3c57f9ed1d6cc23d198555c51d234dd856d0e3803879fb4a92809204fcb5d8b70e0a02421e902d9fd4d33e34e02e7e6ccd778caef203ce3aa7b6c6037
7
- data.tar.gz: 91656de653ca7b90469dfbc3e6363259d3e9977693e649846d0bc4fd39e0585798f985334b1895790efbb9613f39ba35dce3193aecb59844d0f419d0da2c5bf0
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.2",
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.8.1",
26
- "eslint-config-prettier": "^7.0.0",
27
- "husky": "^4.3.5",
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
@@ -24,3 +24,6 @@ Style/TrailingCommaInArrayLiteral: # trailingComma
24
24
 
25
25
  Style/TrailingCommaInHashLiteral: # trailingComma
26
26
  Enabled: false
27
+
28
+ Style/Lambda:
29
+ Enabled: false
data/src/haml/parser.rb CHANGED
@@ -131,8 +131,6 @@ module Prettier
131
131
  class HAMLParser
132
132
  def self.parse(source)
133
133
  Haml::Parser.new({}).call(source).as_json
134
- rescue StandardError
135
- false
136
134
  end
137
135
  end
138
136
  end
@@ -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 response = requestParse(parser, source);
8
+ const { stdout, stderr, status } = requestParse(parser, source);
9
9
 
10
- if (
11
- response.stdout.length === 0 ||
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(response.stdout);
14
+ const parsed = JSON.parse(stdout);
21
15
 
22
16
  if (parsed.error) {
23
- throw new Error(
24
- `@prettier/plugin-ruby encountered an error when attempting to parse \
25
- the ruby source. This usually means there was a syntax error in the \
26
- file in question. You can verify by running \`ruby -i [path/to/file]\`.`
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
@@ -87,8 +87,6 @@ module Prettier
87
87
  class RBSParser
88
88
  def self.parse(text)
89
89
  { declarations: RBS::Parser.parse_signature(text) }
90
- rescue StandardError
91
- false
92
90
  end
93
91
  end
94
92
  end
@@ -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: (path, opts, print) => {
113
- const parts = path.call(print, "body", 0);
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.2
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-03 00:00:00.000000000 Z
11
+ date: 2021-02-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: