prettier 1.0.0.pre.rc2 → 1.0.0
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 +14 -2
- data/package.json +8 -5
- data/src/nodes/calls.js +31 -2
- data/src/nodes/hashes.js +25 -35
- data/src/nodes/regexp.js +10 -3
- data/src/nodes/strings.js +1 -1
- data/src/parser.js +27 -12
- data/src/parser.rb +20 -7
- metadata +6 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1738251faac58ab78438da2dcf568a86708d1ccb651d7ec593f0e3c3efc5075a
|
4
|
+
data.tar.gz: 91666c89e8846d9a908883339238dfec94816adb14c8949fe9232590e493c48b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7df78d09da53ada78d9d9a0d3421e279bc0f1593aaff7a099ef397deea85f4fdde3a044ef91bb88f8f5d6a4f91d52d303e912e60f84b946c35528c0c6f139e1
|
7
|
+
data.tar.gz: 95e810fa06b71063a010f8e3e3dd3cf7302e2cf1b3573f8da4b7e7fed9288ecaf4d75cbd6429c4b04dbc31728dc879cf1605c8c104fc130bdbfc30583c837e5b
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,16 @@ 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.0.0] - 2020-12-11
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- [@kddeisz] - Do not unescape double quotes in a single quote string.
|
14
|
+
- [@kddeisz] - Only force braces on regexp for spaces and equals if it's inside a command or command_call.
|
15
|
+
- [@kddeisz] - Leave Sorbet type annotations in place.
|
16
|
+
- [@kddeisz] - Don't group hash contents, just allow them to break with their parent node.
|
17
|
+
- [@kddeisz] - Honor the UTF-8 lang passed in through ENV vars.
|
18
|
+
|
9
19
|
## [1.0.0-rc2] - 2020-12-10
|
10
20
|
|
11
21
|
### Changed
|
@@ -252,7 +262,8 @@ will now be printed as:
|
|
252
262
|
```ruby
|
253
263
|
Config::Download.new(
|
254
264
|
'prettier',
|
255
|
-
filename: 'prettier.yml',
|
265
|
+
filename: 'prettier.yml',
|
266
|
+
url: 'https://raw.githubusercontent.com/...'
|
256
267
|
).perform
|
257
268
|
```
|
258
269
|
|
@@ -940,7 +951,8 @@ would previously result in `array[]`, but now prints properly.
|
|
940
951
|
|
941
952
|
- Initial release 🎉
|
942
953
|
|
943
|
-
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.0.0
|
954
|
+
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.0.0...HEAD
|
955
|
+
[1.0.0]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc2...v1.0.0
|
944
956
|
[1.0.0-rc2]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc1...v1.0.0-rc2
|
945
957
|
[1.0.0-rc1]: https://github.com/prettier/plugin-ruby/compare/v0.22.0...v1.0.0-rc1
|
946
958
|
[0.22.0]: https://github.com/prettier/plugin-ruby/compare/v0.21.0...v0.22.0
|
data/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prettier/plugin-ruby",
|
3
|
-
"version": "1.0.0
|
3
|
+
"version": "1.0.0",
|
4
4
|
"description": "prettier plugin for the Ruby programming language",
|
5
5
|
"main": "src/ruby.js",
|
6
6
|
"scripts": {
|
7
|
+
"check-format": "prettier --check '**/*'",
|
7
8
|
"lint": "eslint --cache .",
|
8
|
-
"print": "prettier --plugin=.",
|
9
9
|
"test": "jest"
|
10
10
|
},
|
11
11
|
"repository": {
|
@@ -25,9 +25,9 @@
|
|
25
25
|
"all-contributors-cli": "^6.14.1",
|
26
26
|
"eslint": "^7.8.1",
|
27
27
|
"eslint-config-prettier": "^7.0.0",
|
28
|
-
"husky": "^
|
28
|
+
"husky": "^4.3.5",
|
29
29
|
"jest": "^26.0.0",
|
30
|
-
"pretty-quick": "^3.
|
30
|
+
"pretty-quick": "^3.1.0"
|
31
31
|
},
|
32
32
|
"eslintConfig": {
|
33
33
|
"extends": [
|
@@ -61,6 +61,9 @@
|
|
61
61
|
}
|
62
62
|
},
|
63
63
|
"prettier": {
|
64
|
-
"trailingComma": "none"
|
64
|
+
"trailingComma": "none",
|
65
|
+
"plugins": [
|
66
|
+
"."
|
67
|
+
]
|
65
68
|
}
|
66
69
|
}
|
data/src/nodes/calls.js
CHANGED
@@ -100,15 +100,44 @@ function printMethodAddArg(path, opts, print) {
|
|
100
100
|
return concat([methodDoc, argsDoc]);
|
101
101
|
}
|
102
102
|
|
103
|
-
|
103
|
+
// Sorbet type annotations look like the following:
|
104
|
+
//
|
105
|
+
// {method_add_block
|
106
|
+
// [{method_add_arg
|
107
|
+
// [{fcall
|
108
|
+
// [{@ident "sig"}]},
|
109
|
+
// {args []}]},
|
110
|
+
// {brace_block [nil, {stmts}]}}]}
|
111
|
+
//
|
112
|
+
function isSorbetTypeAnnotation(node) {
|
113
|
+
const [callNode, blockNode] = node.body;
|
114
|
+
|
115
|
+
return (
|
116
|
+
callNode.type === "method_add_arg" &&
|
117
|
+
callNode.body[0].type === "fcall" &&
|
118
|
+
callNode.body[0].body[0].body === "sig" &&
|
119
|
+
callNode.body[1].type === "args" &&
|
120
|
+
callNode.body[1].body.length === 0 &&
|
121
|
+
blockNode.type === "brace_block"
|
122
|
+
);
|
123
|
+
}
|
124
|
+
|
125
|
+
function printMethodAddBlock(path, opts, print) {
|
104
126
|
const node = path.getValue();
|
105
127
|
|
106
128
|
const [callNode, blockNode] = node.body;
|
107
129
|
const [callDoc, blockDoc] = path.map(print, "body");
|
108
130
|
|
131
|
+
// Very special handling here for sorbet type annotations. They look like Ruby
|
132
|
+
// code, but they're not actually Ruby code, so we're not going to mess with
|
133
|
+
// them at all.
|
134
|
+
if (isSorbetTypeAnnotation(node)) {
|
135
|
+
return opts.originalText.slice(opts.locStart(node), opts.locEnd(node));
|
136
|
+
}
|
137
|
+
|
109
138
|
// Don't bother trying to do any kind of fancy toProc transform if the option
|
110
139
|
// is disabled.
|
111
|
-
if (rubyToProc) {
|
140
|
+
if (opts.rubyToProc) {
|
112
141
|
const proc = toProc(path, blockNode);
|
113
142
|
|
114
143
|
if (proc && callNode.type === "call") {
|
data/src/nodes/hashes.js
CHANGED
@@ -93,32 +93,7 @@ function printHashContents(path, opts, print) {
|
|
93
93
|
? printHashKeyLabel
|
94
94
|
: printHashKeyRocket;
|
95
95
|
|
96
|
-
|
97
|
-
|
98
|
-
// If we're inside a hash literal, then we want to add the braces at this
|
99
|
-
// level so that the grouping is correct. Otherwise you could end up with
|
100
|
-
// opening and closing braces being split up, but the contents not being split
|
101
|
-
// correctly.
|
102
|
-
if (path.getParentNode().type === "hash") {
|
103
|
-
return group(
|
104
|
-
concat([
|
105
|
-
"{",
|
106
|
-
indent(
|
107
|
-
concat([
|
108
|
-
line,
|
109
|
-
contents,
|
110
|
-
getTrailingComma(opts) ? ifBreak(",", "") : ""
|
111
|
-
])
|
112
|
-
),
|
113
|
-
line,
|
114
|
-
"}"
|
115
|
-
])
|
116
|
-
);
|
117
|
-
}
|
118
|
-
|
119
|
-
// Otherwise, we're inside a bare_assoc_hash, so we don't want to print
|
120
|
-
// braces at all.
|
121
|
-
return group(contents);
|
96
|
+
return join(concat([",", line]), path.map(print, "body"));
|
122
97
|
}
|
123
98
|
|
124
99
|
function printEmptyHashWithComments(path, opts) {
|
@@ -129,14 +104,16 @@ function printEmptyHashWithComments(path, opts) {
|
|
129
104
|
return opts.printer.printComment(commentPath);
|
130
105
|
};
|
131
106
|
|
132
|
-
return
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
107
|
+
return group(
|
108
|
+
concat([
|
109
|
+
"{",
|
110
|
+
indent(
|
111
|
+
concat([hardline, join(hardline, path.map(printComment, "comments"))])
|
112
|
+
),
|
113
|
+
line,
|
114
|
+
"}"
|
115
|
+
])
|
116
|
+
);
|
140
117
|
}
|
141
118
|
|
142
119
|
function printHash(path, opts, print) {
|
@@ -149,7 +126,20 @@ function printHash(path, opts, print) {
|
|
149
126
|
return hashNode.comments ? printEmptyHashWithComments(path, opts) : "{}";
|
150
127
|
}
|
151
128
|
|
152
|
-
return
|
129
|
+
return group(
|
130
|
+
concat([
|
131
|
+
"{",
|
132
|
+
indent(
|
133
|
+
concat([
|
134
|
+
line,
|
135
|
+
path.call(print, "body", 0),
|
136
|
+
getTrailingComma(opts) ? ifBreak(",", "") : ""
|
137
|
+
])
|
138
|
+
),
|
139
|
+
line,
|
140
|
+
"}"
|
141
|
+
])
|
142
|
+
);
|
153
143
|
}
|
154
144
|
|
155
145
|
module.exports = {
|
data/src/nodes/regexp.js
CHANGED
@@ -1,16 +1,23 @@
|
|
1
1
|
const { concat } = require("../prettier");
|
2
|
+
const { hasAncestor } = require("../utils");
|
2
3
|
|
3
4
|
function isStringContent(node) {
|
4
5
|
return node.type === "@tstring_content";
|
5
6
|
}
|
6
7
|
|
7
|
-
function shouldUseBraces(
|
8
|
+
function shouldUseBraces(path) {
|
9
|
+
const node = path.getValue();
|
8
10
|
const first = node.body[0];
|
9
11
|
|
10
12
|
// If the first part of this regex is plain string content and we have a
|
11
13
|
// space or an =, then we want to use braces because otherwise we could end up
|
12
14
|
// with an ambiguous operator, e.g. foo / bar/ or foo /=bar/
|
13
|
-
if (
|
15
|
+
if (
|
16
|
+
first &&
|
17
|
+
isStringContent(first) &&
|
18
|
+
[" ", "="].includes(first.body[0]) &&
|
19
|
+
hasAncestor(path, ["command", "command_call"])
|
20
|
+
) {
|
14
21
|
return true;
|
15
22
|
}
|
16
23
|
|
@@ -28,7 +35,7 @@ function shouldUseBraces(node) {
|
|
28
35
|
// itself. In that case we switch over to using %r with braces.
|
29
36
|
function printRegexpLiteral(path, opts, print) {
|
30
37
|
const node = path.getValue();
|
31
|
-
const useBraces = shouldUseBraces(
|
38
|
+
const useBraces = shouldUseBraces(path);
|
32
39
|
|
33
40
|
const parts = [useBraces ? "%r{" : "/"]
|
34
41
|
.concat(path.map(print, "body"))
|
data/src/nodes/strings.js
CHANGED
@@ -32,7 +32,7 @@ function isSingleQuotable(node) {
|
|
32
32
|
const quotePattern = new RegExp("\\\\([\\s\\S])|(['\"])", "g");
|
33
33
|
|
34
34
|
function normalizeQuotes(content, enclosingQuote, originalQuote) {
|
35
|
-
const replaceOther =
|
35
|
+
const replaceOther = originalQuote === '"';
|
36
36
|
const otherQuote = enclosingQuote === '"' ? "'" : '"';
|
37
37
|
|
38
38
|
// Escape and unescape single and double quotes as needed to be able to
|
data/src/parser.js
CHANGED
@@ -3,18 +3,33 @@ const path = require("path");
|
|
3
3
|
|
4
4
|
// In order to properly parse ruby code, we need to tell the ruby process to
|
5
5
|
// parse using UTF-8. Unfortunately, the way that you accomplish this looks
|
6
|
-
// differently depending on your platform.
|
7
|
-
|
8
|
-
|
9
|
-
const
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
// differently depending on your platform.
|
7
|
+
const LANG = (() => {
|
8
|
+
const { env, platform } = process;
|
9
|
+
const envValue = env.LC_ALL || env.LC_CTYPE || env.LANG;
|
10
|
+
|
11
|
+
// If an env var is set for the locale that already includes UTF-8 in the
|
12
|
+
// name, then assume we can go with that.
|
13
|
+
if (envValue && envValue.includes("UTF-8")) {
|
14
|
+
return envValue;
|
15
|
+
}
|
16
|
+
|
17
|
+
// Otherwise, we're going to guess which encoding to use based on the system.
|
18
|
+
// This is probably not the best approach in the world, as you could be on
|
19
|
+
// linux and not have C.UTF-8, but in that case you're probably passing an env
|
20
|
+
// var for it. This object below represents all of the possible values of
|
21
|
+
// process.platform per:
|
22
|
+
// https://nodejs.org/api/process.html#process_process_platform
|
23
|
+
return {
|
24
|
+
aix: "C.UTF-8",
|
25
|
+
darwin: "en_US.UTF-8",
|
26
|
+
freebsd: "C.UTF-8",
|
27
|
+
linux: "C.UTF-8",
|
28
|
+
openbsd: "C.UTF-8",
|
29
|
+
sunos: "C.UTF-8",
|
30
|
+
win32: ".UTF-8"
|
31
|
+
}[platform];
|
32
|
+
})();
|
18
33
|
|
19
34
|
// This function is responsible for taking an input string of text and returning
|
20
35
|
// to prettier a JavaScript object that is the equivalent AST that represents
|
data/src/parser.rb
CHANGED
@@ -314,7 +314,9 @@ class Prettier::Parser < Ripper
|
|
314
314
|
arg.merge(type: :args, body: [arg])
|
315
315
|
else
|
316
316
|
args.merge!(
|
317
|
-
body: args[:body] << arg,
|
317
|
+
body: args[:body] << arg,
|
318
|
+
end: arg[:end],
|
319
|
+
char_end: arg[:char_end]
|
318
320
|
)
|
319
321
|
end
|
320
322
|
end
|
@@ -1186,7 +1188,8 @@ class Prettier::Parser < Ripper
|
|
1186
1188
|
# Here we're going to expand out the location information for the assocs
|
1187
1189
|
# node so that it can grab up any remaining comments inside the hash.
|
1188
1190
|
assoclist_from_args.merge!(
|
1189
|
-
char_start: beging[:char_end],
|
1191
|
+
char_start: beging[:char_end],
|
1192
|
+
char_end: ending[:char_start]
|
1190
1193
|
)
|
1191
1194
|
end
|
1192
1195
|
|
@@ -1448,7 +1451,9 @@ class Prettier::Parser < Ripper
|
|
1448
1451
|
part.merge(type: :mlhs, body: [part])
|
1449
1452
|
else
|
1450
1453
|
mlhs.merge!(
|
1451
|
-
body: mlhs[:body] << part,
|
1454
|
+
body: mlhs[:body] << part,
|
1455
|
+
end: part[:end],
|
1456
|
+
char_end: part[:char_end]
|
1452
1457
|
)
|
1453
1458
|
end
|
1454
1459
|
end
|
@@ -1551,7 +1556,9 @@ class Prettier::Parser < Ripper
|
|
1551
1556
|
part.merge(type: :mrhs, body: [part])
|
1552
1557
|
else
|
1553
1558
|
mrhs.merge!(
|
1554
|
-
body: mrhs[:body] << part,
|
1559
|
+
body: mrhs[:body] << part,
|
1560
|
+
end: part[:end],
|
1561
|
+
char_end: part[:char_end]
|
1555
1562
|
)
|
1556
1563
|
end
|
1557
1564
|
end
|
@@ -1960,7 +1967,9 @@ class Prettier::Parser < Ripper
|
|
1960
1967
|
# piece of the string.
|
1961
1968
|
def on_string_add(string, piece)
|
1962
1969
|
string.merge!(
|
1963
|
-
body: string[:body] << piece,
|
1970
|
+
body: string[:body] << piece,
|
1971
|
+
end: piece[:end],
|
1972
|
+
char_end: piece[:char_end]
|
1964
1973
|
)
|
1965
1974
|
end
|
1966
1975
|
|
@@ -2417,7 +2426,9 @@ class Prettier::Parser < Ripper
|
|
2417
2426
|
piece.merge(type: :word, body: [piece])
|
2418
2427
|
else
|
2419
2428
|
word.merge!(
|
2420
|
-
body: word[:body] << piece,
|
2429
|
+
body: word[:body] << piece,
|
2430
|
+
end: piece[:end],
|
2431
|
+
char_end: piece[:char_end]
|
2421
2432
|
)
|
2422
2433
|
end
|
2423
2434
|
end
|
@@ -2498,7 +2509,9 @@ class Prettier::Parser < Ripper
|
|
2498
2509
|
else
|
2499
2510
|
ending = find_scanner_event(:@tstring_end)
|
2500
2511
|
xstring.merge!(
|
2501
|
-
type: :xstring_literal,
|
2512
|
+
type: :xstring_literal,
|
2513
|
+
end: ending[:end],
|
2514
|
+
char_end: ending[:char_end]
|
2502
2515
|
)
|
2503
2516
|
end
|
2504
2517
|
end
|
metadata
CHANGED
@@ -1,57 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prettier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: minitest
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '5.13'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '5.13'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '13.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '13.0'
|
11
|
+
date: 2020-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
55
13
|
description:
|
56
14
|
email:
|
57
15
|
executables:
|
@@ -130,11 +88,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
88
|
version: '0'
|
131
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
90
|
requirements:
|
133
|
-
- - "
|
91
|
+
- - ">="
|
134
92
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
93
|
+
version: '0'
|
136
94
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.1.4
|
138
96
|
signing_key:
|
139
97
|
specification_version: 4
|
140
98
|
summary: prettier plugin for the Ruby programming language
|