prettier 0.22.0 → 1.1.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 +115 -8
- data/CONTRIBUTING.md +1 -1
- data/README.md +17 -14
- data/node_modules/prettier/index.js +54 -54
- data/package.json +10 -5
- data/src/embed.js +11 -7
- data/src/nodes/args.js +59 -79
- data/src/nodes/arrays.js +38 -50
- data/src/nodes/assign.js +2 -2
- data/src/nodes/calls.js +132 -50
- data/src/nodes/case.js +11 -7
- data/src/nodes/conditionals.js +4 -4
- data/src/nodes/hashes.js +59 -51
- data/src/nodes/heredocs.js +2 -2
- data/src/nodes/hooks.js +5 -3
- data/src/nodes/ints.js +0 -6
- data/src/nodes/lambdas.js +6 -22
- data/src/nodes/loops.js +67 -66
- data/src/nodes/methods.js +2 -0
- data/src/nodes/operators.js +24 -13
- data/src/nodes/params.js +15 -3
- data/src/nodes/regexp.js +38 -9
- data/src/nodes/rescue.js +2 -2
- data/src/nodes/statements.js +65 -45
- data/src/nodes/strings.js +12 -11
- data/src/parser.js +27 -12
- data/src/parser.rb +190 -54
- data/src/printer.js +16 -1
- data/src/ruby.js +15 -21
- data/src/toProc.js +2 -2
- data/src/utils.js +15 -3
- data/src/utils/printEmptyCollection.js +42 -0
- metadata +5 -46
data/src/printer.js
CHANGED
@@ -20,6 +20,18 @@ function printNode(path, opts, print) {
|
|
20
20
|
throw new Error(`Unsupported node encountered: ${type}\n${ast}`);
|
21
21
|
}
|
22
22
|
|
23
|
+
// This is an escape-hatch to ignore nodes in the tree. If you have a comment
|
24
|
+
// that includes this pattern, then the entire node will be ignored and just the
|
25
|
+
// original source will be printed out.
|
26
|
+
function hasPrettierIgnore(path) {
|
27
|
+
const node = path.getValue();
|
28
|
+
|
29
|
+
return (
|
30
|
+
node.comments &&
|
31
|
+
node.comments.some((comment) => comment.value.includes("prettier-ignore"))
|
32
|
+
);
|
33
|
+
}
|
34
|
+
|
23
35
|
const noComments = [
|
24
36
|
"args",
|
25
37
|
"args_add_block",
|
@@ -40,8 +52,10 @@ function canAttachComment(node) {
|
|
40
52
|
// where it needs to attach the comments.
|
41
53
|
function getCommentChildNodes(node) {
|
42
54
|
switch (node.type) {
|
55
|
+
case "heredoc":
|
56
|
+
return [node.beging];
|
43
57
|
case "rescue":
|
44
|
-
return node.body[0].concat(node.body.slice(1));
|
58
|
+
return [].concat(node.body[0]).concat(node.body.slice(1));
|
45
59
|
case "aryptn":
|
46
60
|
return [node.body[0]]
|
47
61
|
.concat(node.body[1])
|
@@ -81,6 +95,7 @@ function isBlockComment(comment) {
|
|
81
95
|
module.exports = {
|
82
96
|
embed,
|
83
97
|
print: printNode,
|
98
|
+
hasPrettierIgnore,
|
84
99
|
canAttachComment,
|
85
100
|
getCommentChildNodes,
|
86
101
|
printComment,
|
data/src/ruby.js
CHANGED
@@ -76,44 +76,37 @@ module.exports = {
|
|
76
76
|
ruby: printer
|
77
77
|
},
|
78
78
|
options: {
|
79
|
-
|
79
|
+
rubyArrayLiteral: {
|
80
80
|
type: "boolean",
|
81
|
-
category: "
|
82
|
-
default: false,
|
83
|
-
description:
|
84
|
-
"Adds a trailing comma to array literals, hash literals, and method calls."
|
85
|
-
},
|
86
|
-
inlineConditionals: {
|
87
|
-
type: "boolean",
|
88
|
-
category: "Global",
|
81
|
+
category: "Ruby",
|
89
82
|
default: true,
|
90
83
|
description:
|
91
|
-
"When
|
84
|
+
"When possible, favor the use of string and symbol array literals."
|
92
85
|
},
|
93
|
-
|
86
|
+
rubyHashLabel: {
|
94
87
|
type: "boolean",
|
95
|
-
category: "
|
88
|
+
category: "Ruby",
|
96
89
|
default: true,
|
97
90
|
description:
|
98
|
-
"When
|
91
|
+
"When possible, uses the shortened hash key syntax, as opposed to hash rockets."
|
99
92
|
},
|
100
|
-
|
93
|
+
rubyModifier: {
|
101
94
|
type: "boolean",
|
102
|
-
category: "
|
95
|
+
category: "Ruby",
|
103
96
|
default: true,
|
104
97
|
description:
|
105
|
-
"When
|
98
|
+
"When it fits on one line, allows if, unless, while, and until statements to use the modifier form."
|
106
99
|
},
|
107
|
-
|
100
|
+
rubySingleQuote: {
|
108
101
|
type: "boolean",
|
109
|
-
category: "
|
102
|
+
category: "Ruby",
|
110
103
|
default: true,
|
111
104
|
description:
|
112
105
|
"When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals."
|
113
106
|
},
|
114
|
-
|
107
|
+
rubyToProc: {
|
115
108
|
type: "boolean",
|
116
|
-
category: "
|
109
|
+
category: "Ruby",
|
117
110
|
default: false,
|
118
111
|
description:
|
119
112
|
"When possible, convert blocks to the more concise Symbol#to_proc syntax."
|
@@ -121,6 +114,7 @@ module.exports = {
|
|
121
114
|
},
|
122
115
|
defaultOptions: {
|
123
116
|
printWidth: 80,
|
124
|
-
tabWidth: 2
|
117
|
+
tabWidth: 2,
|
118
|
+
trailingComma: "none"
|
125
119
|
}
|
126
120
|
};
|
data/src/toProc.js
CHANGED
@@ -11,8 +11,8 @@ const isCall = (node) => ["::", "."].includes(node) || node.type === "@period";
|
|
11
11
|
// [1, 2, 3].map(&:to_s)
|
12
12
|
//
|
13
13
|
// This works with `do` blocks as well.
|
14
|
-
const toProc = (path,
|
15
|
-
if (!node
|
14
|
+
const toProc = (path, node) => {
|
15
|
+
if (!node) {
|
16
16
|
return null;
|
17
17
|
}
|
18
18
|
|
data/src/utils.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
const { concat } = require("./prettier");
|
2
2
|
const isEmptyStmts = require("./utils/isEmptyStmts");
|
3
3
|
const literalLineNoBreak = require("./utils/literalLineNoBreak");
|
4
|
-
|
5
|
-
const concatBody = (path, opts, print) => concat(path.map(print, "body"));
|
4
|
+
const printEmptyCollection = require("./utils/printEmptyCollection");
|
6
5
|
|
7
6
|
// If the node is a type of assignment or if the node is a paren and nested
|
8
7
|
// inside that paren is a node that is a type of assignment.
|
@@ -31,6 +30,8 @@ const empty = () => "";
|
|
31
30
|
|
32
31
|
const first = (path, opts, print) => path.call(print, "body", 0);
|
33
32
|
|
33
|
+
const getTrailingComma = (opts) => ["all", "es5"].includes(opts.trailingComma);
|
34
|
+
|
34
35
|
const hasAncestor = (path, types) => {
|
35
36
|
let parent = 0;
|
36
37
|
let parentNode = path.getParentNode();
|
@@ -59,6 +60,15 @@ const makeCall = (path, opts, print) => {
|
|
59
60
|
return operation === "::" ? "." : path.call(print, "body", 1);
|
60
61
|
};
|
61
62
|
|
63
|
+
const noIndent = [
|
64
|
+
"array",
|
65
|
+
"hash",
|
66
|
+
"heredoc",
|
67
|
+
"if",
|
68
|
+
"method_add_block",
|
69
|
+
"xstring_literal"
|
70
|
+
];
|
71
|
+
|
62
72
|
const prefix = (value) => (path, opts, print) =>
|
63
73
|
concat([value, path.call(print, "body", 0)]);
|
64
74
|
|
@@ -68,16 +78,18 @@ const skipAssignIndent = (node) =>
|
|
68
78
|
(node.type === "call" && skipAssignIndent(node.body[0]));
|
69
79
|
|
70
80
|
module.exports = {
|
71
|
-
concatBody,
|
72
81
|
containsAssignment,
|
73
82
|
docLength,
|
74
83
|
empty,
|
75
84
|
first,
|
85
|
+
getTrailingComma,
|
76
86
|
hasAncestor,
|
77
87
|
isEmptyStmts,
|
78
88
|
literal,
|
79
89
|
literalLineNoBreak,
|
80
90
|
makeCall,
|
91
|
+
noIndent,
|
81
92
|
prefix,
|
93
|
+
printEmptyCollection,
|
82
94
|
skipAssignIndent
|
83
95
|
};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
const { concat, group, hardline, indent, join, line } = require("../prettier");
|
2
|
+
|
3
|
+
// Empty collections are array or hash literals that do not contain any
|
4
|
+
// contents. They can, however, have comments inside the body. You can solve
|
5
|
+
// this by having a child node inside the array that gets the comments attached
|
6
|
+
// to it, but that requires modifying the parser. Instead, we can just manually
|
7
|
+
// print out the non-leading comments here.
|
8
|
+
function printEmptyCollection(path, opts, startToken, endToken) {
|
9
|
+
const node = path.getValue();
|
10
|
+
|
11
|
+
// If there are no comments or only leading comments, then we can just print
|
12
|
+
// out the start and end token and be done, as there are no comments inside
|
13
|
+
// the body of this node.
|
14
|
+
if (!node.comments || !node.comments.some((comment) => !comment.leading)) {
|
15
|
+
return `${startToken}${endToken}`;
|
16
|
+
}
|
17
|
+
|
18
|
+
const comments = [];
|
19
|
+
|
20
|
+
// For each comment, go through its path and print it out manually.
|
21
|
+
const printComment = (commentPath) => {
|
22
|
+
const comment = commentPath.getValue();
|
23
|
+
|
24
|
+
if (!comment.leading) {
|
25
|
+
comment.printed = true;
|
26
|
+
comments.push(opts.printer.printComment(commentPath));
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
path.each(printComment, "comments");
|
31
|
+
|
32
|
+
return group(
|
33
|
+
concat([
|
34
|
+
startToken,
|
35
|
+
indent(concat([hardline, join(hardline, comments)])),
|
36
|
+
line,
|
37
|
+
endToken
|
38
|
+
])
|
39
|
+
);
|
40
|
+
}
|
41
|
+
|
42
|
+
module.exports = printEmptyCollection;
|
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:
|
4
|
+
version: 1.1.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-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
55
13
|
description:
|
56
14
|
email:
|
57
15
|
executables:
|
@@ -115,6 +73,7 @@ files:
|
|
115
73
|
- src/utils/inlineEnsureParens.js
|
116
74
|
- src/utils/isEmptyStmts.js
|
117
75
|
- src/utils/literalLineNoBreak.js
|
76
|
+
- src/utils/printEmptyCollection.js
|
118
77
|
homepage: https://github.com/prettier/plugin-ruby#readme
|
119
78
|
licenses:
|
120
79
|
- MIT
|
@@ -134,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
93
|
- !ruby/object:Gem::Version
|
135
94
|
version: '0'
|
136
95
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.1.4
|
138
97
|
signing_key:
|
139
98
|
specification_version: 4
|
140
99
|
summary: prettier plugin for the Ruby programming language
|