prettier 1.2.0 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +61 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +12 -88
- data/lib/prettier.rb +2 -2
- data/node_modules/prettier/index.js +54 -54
- data/package.json +2 -3
- data/rubocop.yml +26 -0
- data/src/{ruby.js → plugin.js} +2 -2
- data/src/prettier.js +1 -0
- data/src/{embed.js → ruby/embed.js} +6 -2
- data/src/{nodes.js → ruby/nodes.js} +0 -0
- data/src/{nodes → ruby/nodes}/alias.js +1 -1
- data/src/{nodes → ruby/nodes}/aref.js +8 -1
- data/src/{nodes → ruby/nodes}/args.js +2 -2
- data/src/{nodes → ruby/nodes}/arrays.js +2 -3
- data/src/{nodes → ruby/nodes}/assign.js +7 -7
- data/src/ruby/nodes/blocks.js +90 -0
- data/src/{nodes → ruby/nodes}/calls.js +18 -11
- data/src/ruby/nodes/case.js +65 -0
- data/src/{nodes → ruby/nodes}/class.js +1 -1
- data/src/ruby/nodes/commands.js +131 -0
- data/src/{nodes → ruby/nodes}/conditionals.js +3 -3
- data/src/{nodes → ruby/nodes}/constants.js +2 -2
- data/src/{nodes → ruby/nodes}/flow.js +2 -2
- data/src/{nodes → ruby/nodes}/hashes.js +32 -10
- data/src/{nodes → ruby/nodes}/heredocs.js +2 -2
- data/src/ruby/nodes/hooks.js +34 -0
- data/src/{nodes → ruby/nodes}/ints.js +0 -0
- data/src/{nodes → ruby/nodes}/lambdas.js +2 -2
- data/src/{nodes → ruby/nodes}/loops.js +10 -7
- data/src/{nodes → ruby/nodes}/massign.js +8 -1
- data/src/{nodes → ruby/nodes}/methods.js +24 -7
- data/src/{nodes → ruby/nodes}/operators.js +2 -2
- data/src/{nodes → ruby/nodes}/params.js +31 -16
- data/src/{nodes → ruby/nodes}/patterns.js +39 -17
- data/src/{nodes → ruby/nodes}/regexp.js +2 -2
- data/src/{nodes → ruby/nodes}/rescue.js +2 -2
- data/src/ruby/nodes/return.js +94 -0
- data/src/{nodes → ruby/nodes}/statements.js +6 -9
- data/src/{nodes → ruby/nodes}/strings.js +27 -36
- data/src/{nodes → ruby/nodes}/super.js +2 -2
- data/src/{nodes → ruby/nodes}/undef.js +1 -1
- data/src/{parser.js → ruby/parser.js} +4 -3
- data/src/{parser.rb → ruby/parser.rb} +462 -508
- data/src/{printer.js → ruby/printer.js} +33 -1
- data/src/{toProc.js → ruby/toProc.js} +4 -8
- data/src/utils.js +10 -93
- data/src/utils/containsAssignment.js +11 -0
- data/src/utils/getTrailingComma.js +5 -0
- data/src/utils/hasAncestor.js +17 -0
- data/src/utils/literal.js +7 -0
- data/src/utils/makeCall.js +14 -0
- data/src/utils/noIndent.js +11 -0
- data/src/utils/skipAssignIndent.js +10 -0
- metadata +49 -41
- data/src/nodes/blocks.js +0 -85
- data/src/nodes/case.js +0 -61
- data/src/nodes/commands.js +0 -91
- data/src/nodes/hooks.js +0 -44
- data/src/nodes/return.js +0 -72
data/package.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prettier/plugin-ruby",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.5",
|
4
4
|
"description": "prettier plugin for the Ruby programming language",
|
5
|
-
"main": "src/
|
5
|
+
"main": "src/plugin.js",
|
6
6
|
"scripts": {
|
7
7
|
"check-format": "prettier --check '**/*'",
|
8
8
|
"lint": "eslint --cache .",
|
@@ -22,7 +22,6 @@
|
|
22
22
|
"prettier": ">=1.10"
|
23
23
|
},
|
24
24
|
"devDependencies": {
|
25
|
-
"all-contributors-cli": "^6.14.1",
|
26
25
|
"eslint": "^7.8.1",
|
27
26
|
"eslint-config-prettier": "^7.0.0",
|
28
27
|
"husky": "^4.3.5",
|
data/rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Disabling all Layout/* rules, as they're unnecessary when the user is using
|
2
|
+
# prettier to handle all of the formatting.
|
3
|
+
|
4
|
+
Layout:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
# Disabling all of the following options because they could conflict with a
|
8
|
+
# prettier configuration setting.
|
9
|
+
|
10
|
+
Style/MultilineIfModifier: # rubyModifier
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/SymbolArray: # rubyArrayLiteral
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/WordArray: # rubyArrayLiteral
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/TrailingCommaInArguments: # trailingComma
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/TrailingCommaInArrayLiteral: # trailingComma
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/TrailingCommaInHashLiteral: # trailingComma
|
26
|
+
Enabled: false
|
data/src/{ruby.js → plugin.js}
RENAMED
data/src/prettier.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
// If `RBPRETTIER` is set, then this is being run from the `Prettier::run` ruby
|
2
2
|
// method. In that case, we need to pull `prettier` from the node_modules
|
3
3
|
// directly, as it's been shipped with the gem.
|
4
|
+
/* istanbul ignore next */
|
4
5
|
const source = process.env.RBPRETTIER ? "../node_modules/prettier" : "prettier";
|
5
6
|
|
6
7
|
const prettier = require(source);
|
@@ -6,9 +6,9 @@ const {
|
|
6
6
|
mapDoc,
|
7
7
|
markAsRoot,
|
8
8
|
stripTrailingHardline
|
9
|
-
} = require("
|
9
|
+
} = require("../prettier");
|
10
10
|
|
11
|
-
const { literalLineNoBreak } = require("
|
11
|
+
const { literalLineNoBreak } = require("../utils");
|
12
12
|
|
13
13
|
const parsers = {
|
14
14
|
css: "css",
|
@@ -20,6 +20,10 @@ const parsers = {
|
|
20
20
|
scss: "scss"
|
21
21
|
};
|
22
22
|
|
23
|
+
// This function is in here because it handles embedded parser values. I don't
|
24
|
+
// have a test that exercises it because I'm not sure for which parser it is
|
25
|
+
// necessary, but since it's in prettier core I'm keeping it here.
|
26
|
+
/* istanbul ignore next */
|
23
27
|
const replaceNewlines = (doc) =>
|
24
28
|
mapDoc(doc, (currentDoc) =>
|
25
29
|
typeof currentDoc === "string" && currentDoc.includes("\n")
|
File without changes
|
@@ -1,4 +1,11 @@
|
|
1
|
-
const {
|
1
|
+
const {
|
2
|
+
concat,
|
3
|
+
group,
|
4
|
+
indent,
|
5
|
+
join,
|
6
|
+
line,
|
7
|
+
softline
|
8
|
+
} = require("../../prettier");
|
2
9
|
|
3
10
|
// `aref` nodes are when you're pulling a value out of a collection at a
|
4
11
|
// specific index. Put another way, it's any time you're calling the method
|
@@ -6,10 +6,10 @@ const {
|
|
6
6
|
join,
|
7
7
|
line,
|
8
8
|
softline
|
9
|
-
} = require("
|
9
|
+
} = require("../../prettier");
|
10
|
+
const { getTrailingComma } = require("../../utils");
|
10
11
|
|
11
12
|
const toProc = require("../toProc");
|
12
|
-
const { getTrailingComma } = require("../utils");
|
13
13
|
|
14
14
|
function printArgParen(path, opts, print) {
|
15
15
|
const argsNode = path.getValue().body[0];
|
@@ -6,9 +6,8 @@ const {
|
|
6
6
|
join,
|
7
7
|
line,
|
8
8
|
softline
|
9
|
-
} = require("
|
10
|
-
|
11
|
-
const { getTrailingComma, printEmptyCollection } = require("../utils");
|
9
|
+
} = require("../../prettier");
|
10
|
+
const { getTrailingComma, printEmptyCollection } = require("../../utils");
|
12
11
|
|
13
12
|
// Checks that every argument within this args node is a string_literal node
|
14
13
|
// that has no spaces or interpolations. This means we're dealing with an array
|
@@ -1,5 +1,5 @@
|
|
1
|
-
const { concat, group, indent, join, line } = require("
|
2
|
-
const {
|
1
|
+
const { concat, group, indent, join, line } = require("../../prettier");
|
2
|
+
const { skipAssignIndent } = require("../../utils");
|
3
3
|
|
4
4
|
function printAssign(path, opts, print) {
|
5
5
|
const [_targetNode, valueNode] = path.getValue().body;
|
@@ -32,16 +32,16 @@ function printOpAssign(path, opts, print) {
|
|
32
32
|
}
|
33
33
|
|
34
34
|
function printVarField(path, opts, print) {
|
35
|
-
|
36
|
-
|
37
|
-
}
|
35
|
+
return path.getValue().body ? path.call(print, "body", 0) : "";
|
36
|
+
}
|
38
37
|
|
39
|
-
|
38
|
+
function printVarRef(path, opts, print) {
|
39
|
+
return path.call(print, "body", 0);
|
40
40
|
}
|
41
41
|
|
42
42
|
module.exports = {
|
43
43
|
assign: printAssign,
|
44
44
|
opassign: printOpAssign,
|
45
45
|
var_field: printVarField,
|
46
|
-
var_ref:
|
46
|
+
var_ref: printVarRef
|
47
47
|
};
|
@@ -0,0 +1,90 @@
|
|
1
|
+
const {
|
2
|
+
breakParent,
|
3
|
+
concat,
|
4
|
+
group,
|
5
|
+
ifBreak,
|
6
|
+
indent,
|
7
|
+
join,
|
8
|
+
removeLines,
|
9
|
+
softline
|
10
|
+
} = require("../../prettier");
|
11
|
+
const { hasAncestor } = require("../../utils");
|
12
|
+
|
13
|
+
function printBlockVar(path, opts, print) {
|
14
|
+
const parts = ["|", removeLines(path.call(print, "body", 0))];
|
15
|
+
|
16
|
+
// The second part of this node is a list of optional block-local variables
|
17
|
+
if (path.getValue().body[1]) {
|
18
|
+
parts.push("; ", join(", ", path.map(print, "body", 1)));
|
19
|
+
}
|
20
|
+
|
21
|
+
parts.push("| ");
|
22
|
+
return concat(parts);
|
23
|
+
}
|
24
|
+
|
25
|
+
function printBlock(braces) {
|
26
|
+
return function printBlockWithBraces(path, opts, print) {
|
27
|
+
const [variables, statements] = path.getValue().body;
|
28
|
+
const stmts =
|
29
|
+
statements.type === "stmts" ? statements.body : statements.body[0].body;
|
30
|
+
|
31
|
+
let doBlockBody = "";
|
32
|
+
if (
|
33
|
+
stmts.length !== 1 ||
|
34
|
+
stmts[0].type !== "void_stmt" ||
|
35
|
+
stmts[0].comments
|
36
|
+
) {
|
37
|
+
doBlockBody = indent(concat([softline, path.call(print, "body", 1)]));
|
38
|
+
}
|
39
|
+
|
40
|
+
// If this block is nested underneath a command or command_call node, then
|
41
|
+
// we can't use `do...end` because that will get associated with the parent
|
42
|
+
// node as opposed to the current node (because of the difference in
|
43
|
+
// operator precedence). Instead, we still use a multi-line format but
|
44
|
+
// switch to using braces instead.
|
45
|
+
const useBraces = braces && hasAncestor(path, ["command", "command_call"]);
|
46
|
+
|
47
|
+
const doBlock = concat([
|
48
|
+
useBraces ? " {" : " do",
|
49
|
+
variables ? concat([" ", path.call(print, "body", 0)]) : "",
|
50
|
+
doBlockBody,
|
51
|
+
concat([softline, useBraces ? "}" : "end"])
|
52
|
+
]);
|
53
|
+
|
54
|
+
// We can hit this next pattern if within the block the only statement is a
|
55
|
+
// comment.
|
56
|
+
if (
|
57
|
+
stmts.length === 1 &&
|
58
|
+
stmts[0].type === "void_stmt" &&
|
59
|
+
stmts[0].comments
|
60
|
+
) {
|
61
|
+
return concat([breakParent, doBlock]);
|
62
|
+
}
|
63
|
+
|
64
|
+
const blockReceiver = path.getParentNode().body[0];
|
65
|
+
|
66
|
+
// If the parent node is a command node, then there are no parentheses
|
67
|
+
// around the arguments to that command, so we need to break the block
|
68
|
+
if (["command", "command_call"].includes(blockReceiver.type)) {
|
69
|
+
return concat([breakParent, doBlock]);
|
70
|
+
}
|
71
|
+
|
72
|
+
const hasBody = stmts.some(({ type }) => type !== "void_stmt");
|
73
|
+
const braceBlock = concat([
|
74
|
+
" {",
|
75
|
+
hasBody || variables ? " " : "",
|
76
|
+
variables ? path.call(print, "body", 0) : "",
|
77
|
+
path.call(print, "body", 1),
|
78
|
+
hasBody ? " " : "",
|
79
|
+
"}"
|
80
|
+
]);
|
81
|
+
|
82
|
+
return group(ifBreak(doBlock, braceBlock));
|
83
|
+
};
|
84
|
+
}
|
85
|
+
|
86
|
+
module.exports = {
|
87
|
+
block_var: printBlockVar,
|
88
|
+
brace_block: printBlock(true),
|
89
|
+
do_block: printBlock(false)
|
90
|
+
};
|
@@ -5,8 +5,8 @@ const {
|
|
5
5
|
ifBreak,
|
6
6
|
indent,
|
7
7
|
softline
|
8
|
-
} = require("
|
9
|
-
const {
|
8
|
+
} = require("../../prettier");
|
9
|
+
const { makeCall, noIndent } = require("../../utils");
|
10
10
|
|
11
11
|
const toProc = require("../toProc");
|
12
12
|
|
@@ -24,6 +24,12 @@ function printCall(path, opts, print) {
|
|
24
24
|
// call syntax so if `call` is implicit, we don't print it out.
|
25
25
|
const messageDoc = messageNode === "call" ? "" : path.call(print, "body", 2);
|
26
26
|
|
27
|
+
// For certain left sides of the call nodes, we want to attach directly to
|
28
|
+
// the } or end.
|
29
|
+
if (noIndent.includes(receiverNode.type)) {
|
30
|
+
return concat([receiverDoc, operatorDoc, messageDoc]);
|
31
|
+
}
|
32
|
+
|
27
33
|
// The right side of the call node, as in everything including the operator
|
28
34
|
// and beyond.
|
29
35
|
const rightSideDoc = concat([
|
@@ -41,6 +47,7 @@ function printCall(path, opts, print) {
|
|
41
47
|
parentNode.chain = (node.chain || 0) + 1;
|
42
48
|
parentNode.callChain = (node.callChain || 0) + 1;
|
43
49
|
parentNode.breakDoc = (node.breakDoc || [receiverDoc]).concat(rightSideDoc);
|
50
|
+
parentNode.firstReceiverType = node.firstReceiverType || receiverNode.type;
|
44
51
|
}
|
45
52
|
|
46
53
|
// If we're at the top of a chain, then we're going to print out a nice
|
@@ -52,12 +59,6 @@ function printCall(path, opts, print) {
|
|
52
59
|
);
|
53
60
|
}
|
54
61
|
|
55
|
-
// For certain left sides of the call nodes, we want to attach directly to
|
56
|
-
// the } or end.
|
57
|
-
if (noIndent.includes(receiverNode.type)) {
|
58
|
-
return concat([receiverDoc, operatorDoc, messageDoc]);
|
59
|
-
}
|
60
|
-
|
61
62
|
return group(concat([receiverDoc, group(indent(rightSideDoc))]));
|
62
63
|
}
|
63
64
|
|
@@ -105,6 +106,7 @@ function printMethodAddArg(path, opts, print) {
|
|
105
106
|
if (chained.includes(parentNode.type)) {
|
106
107
|
parentNode.chain = (node.chain || 0) + 1;
|
107
108
|
parentNode.breakDoc = (node.breakDoc || [methodDoc]).concat(argsDoc);
|
109
|
+
parentNode.firstReceiverType = node.firstReceiverType;
|
108
110
|
}
|
109
111
|
|
110
112
|
// If we're at the top of a chain, then we're going to print out a nice
|
@@ -152,7 +154,7 @@ function isSorbetTypeAnnotation(node) {
|
|
152
154
|
callNode.body[0].body[0].body === "sig" &&
|
153
155
|
callNode.body[1].type === "args" &&
|
154
156
|
callNode.body[1].body.length === 0 &&
|
155
|
-
blockNode
|
157
|
+
blockNode
|
156
158
|
);
|
157
159
|
}
|
158
160
|
|
@@ -198,6 +200,7 @@ function printMethodAddBlock(path, opts, print) {
|
|
198
200
|
if (chained.includes(parentNode.type)) {
|
199
201
|
parentNode.chain = (node.chain || 0) + 1;
|
200
202
|
parentNode.breakDoc = (node.breakDoc || [callDoc]).concat(blockDoc);
|
203
|
+
parentNode.firstReceiverType = node.firstReceiverType;
|
201
204
|
}
|
202
205
|
|
203
206
|
// If we're at the top of a chain, then we're going to print out a nice
|
@@ -212,10 +215,14 @@ function printMethodAddBlock(path, opts, print) {
|
|
212
215
|
return concat([callDoc, blockDoc]);
|
213
216
|
}
|
214
217
|
|
218
|
+
function printCallContainer(path, opts, print) {
|
219
|
+
return path.call(print, "body", 0);
|
220
|
+
}
|
221
|
+
|
215
222
|
module.exports = {
|
216
223
|
call: printCall,
|
217
|
-
fcall:
|
224
|
+
fcall: printCallContainer,
|
218
225
|
method_add_arg: printMethodAddArg,
|
219
226
|
method_add_block: printMethodAddBlock,
|
220
|
-
vcall:
|
227
|
+
vcall: printCallContainer
|
221
228
|
};
|
@@ -0,0 +1,65 @@
|
|
1
|
+
const {
|
2
|
+
align,
|
3
|
+
concat,
|
4
|
+
fill,
|
5
|
+
group,
|
6
|
+
hardline,
|
7
|
+
indent,
|
8
|
+
line
|
9
|
+
} = require("../../prettier");
|
10
|
+
|
11
|
+
function printCase(path, opts, print) {
|
12
|
+
const statement = ["case"];
|
13
|
+
|
14
|
+
// You don't need to explicitly have something to test against in a case
|
15
|
+
// statement (without it it effectively becomes an if/elsif chain).
|
16
|
+
if (path.getValue().body[0]) {
|
17
|
+
statement.push(" ", path.call(print, "body", 0));
|
18
|
+
}
|
19
|
+
|
20
|
+
return concat(
|
21
|
+
statement.concat([hardline, path.call(print, "body", 1), hardline, "end"])
|
22
|
+
);
|
23
|
+
}
|
24
|
+
|
25
|
+
function printWhen(path, opts, print) {
|
26
|
+
const [_preds, _stmts, addition] = path.getValue().body;
|
27
|
+
|
28
|
+
// The `fill` builder command expects an array of docs alternating with
|
29
|
+
// line breaks. This is so it can loop through and determine where to break.
|
30
|
+
const preds = fill(
|
31
|
+
path.call(print, "body", 0).reduce((accum, pred, index) => {
|
32
|
+
if (index === 0) {
|
33
|
+
return [pred];
|
34
|
+
}
|
35
|
+
|
36
|
+
// Pull off the last element and make it concat with a comma so that
|
37
|
+
// we can maintain alternating lines and docs.
|
38
|
+
return accum
|
39
|
+
.slice(0, -1)
|
40
|
+
.concat([concat([accum[accum.length - 1], ","]), line, pred]);
|
41
|
+
}, null)
|
42
|
+
);
|
43
|
+
|
44
|
+
const stmts = path.call(print, "body", 1);
|
45
|
+
const parts = [concat(["when ", align("when ".length, preds)])];
|
46
|
+
|
47
|
+
// It's possible in a when to just have empty void statements, in which case
|
48
|
+
// we would skip adding the body.
|
49
|
+
if (!stmts.parts.every((part) => !part)) {
|
50
|
+
parts.push(indent(concat([hardline, stmts])));
|
51
|
+
}
|
52
|
+
|
53
|
+
// This is the next clause on the case statement, either another `when` or
|
54
|
+
// an `else` clause.
|
55
|
+
if (addition) {
|
56
|
+
parts.push(hardline, path.call(print, "body", 2));
|
57
|
+
}
|
58
|
+
|
59
|
+
return group(concat(parts));
|
60
|
+
}
|
61
|
+
|
62
|
+
module.exports = {
|
63
|
+
case: printCase,
|
64
|
+
when: printWhen
|
65
|
+
};
|
@@ -0,0 +1,131 @@
|
|
1
|
+
const {
|
2
|
+
align,
|
3
|
+
concat,
|
4
|
+
group,
|
5
|
+
ifBreak,
|
6
|
+
indent,
|
7
|
+
join,
|
8
|
+
line,
|
9
|
+
softline
|
10
|
+
} = require("../../prettier");
|
11
|
+
const { makeCall } = require("../../utils");
|
12
|
+
|
13
|
+
function docLength(doc) {
|
14
|
+
if (doc.length) {
|
15
|
+
return doc.length;
|
16
|
+
}
|
17
|
+
|
18
|
+
if (doc.parts) {
|
19
|
+
return doc.parts.reduce((sum, child) => sum + docLength(child), 0);
|
20
|
+
}
|
21
|
+
|
22
|
+
if (doc.contents) {
|
23
|
+
return docLength(doc.contents);
|
24
|
+
}
|
25
|
+
|
26
|
+
return 0;
|
27
|
+
}
|
28
|
+
|
29
|
+
function hasDef(node) {
|
30
|
+
return (
|
31
|
+
node.body[1].type === "args_add_block" &&
|
32
|
+
node.body[1].body[0].type === "args" &&
|
33
|
+
node.body[1].body[0].body[0] &&
|
34
|
+
["def", "defs"].includes(node.body[1].body[0].body[0].type)
|
35
|
+
);
|
36
|
+
}
|
37
|
+
|
38
|
+
// Very special handling case for rspec matchers. In general with rspec matchers
|
39
|
+
// you expect to see something like:
|
40
|
+
//
|
41
|
+
// expect(foo).to receive(:bar).with(
|
42
|
+
// 'one',
|
43
|
+
// 'two',
|
44
|
+
// 'three',
|
45
|
+
// 'four',
|
46
|
+
// 'five'
|
47
|
+
// )
|
48
|
+
//
|
49
|
+
// In this case the arguments are aligned to the left side as opposed to being
|
50
|
+
// aligned with the `receive` call.
|
51
|
+
function skipArgsAlign(path) {
|
52
|
+
return ["to", "not_to"].includes(path.getValue().body[2].body);
|
53
|
+
}
|
54
|
+
|
55
|
+
// If there is a ternary argument to a command and it's going to get broken
|
56
|
+
// into multiple lines, then we're going to have to use parentheses around the
|
57
|
+
// command in order to make sure operator precedence doesn't get messed up.
|
58
|
+
function hasTernaryArg(node) {
|
59
|
+
return node.body[0].body.some((child) => child.type === "ifop");
|
60
|
+
}
|
61
|
+
|
62
|
+
function printCommand(path, opts, print) {
|
63
|
+
const node = path.getValue();
|
64
|
+
|
65
|
+
const command = path.call(print, "body", 0);
|
66
|
+
const joinedArgs = join(concat([",", line]), path.call(print, "body", 1));
|
67
|
+
|
68
|
+
const hasTernary = hasTernaryArg(node.body[1]);
|
69
|
+
let breakArgs;
|
70
|
+
|
71
|
+
if (hasTernary) {
|
72
|
+
breakArgs = indent(concat([softline, joinedArgs]));
|
73
|
+
} else if (hasDef(path.getValue())) {
|
74
|
+
breakArgs = joinedArgs;
|
75
|
+
} else {
|
76
|
+
breakArgs = align(command.length + 1, joinedArgs);
|
77
|
+
}
|
78
|
+
|
79
|
+
return group(
|
80
|
+
ifBreak(
|
81
|
+
concat([
|
82
|
+
command,
|
83
|
+
hasTernary ? "(" : " ",
|
84
|
+
breakArgs,
|
85
|
+
hasTernary ? concat([softline, ")"]) : ""
|
86
|
+
]),
|
87
|
+
concat([command, " ", joinedArgs])
|
88
|
+
)
|
89
|
+
);
|
90
|
+
}
|
91
|
+
|
92
|
+
function printCommandCall(path, opts, print) {
|
93
|
+
const node = path.getValue();
|
94
|
+
const parts = [
|
95
|
+
path.call(print, "body", 0),
|
96
|
+
makeCall(path, opts, print),
|
97
|
+
path.call(print, "body", 2)
|
98
|
+
];
|
99
|
+
|
100
|
+
if (!node.body[3]) {
|
101
|
+
return concat(parts);
|
102
|
+
}
|
103
|
+
|
104
|
+
const argDocs = join(concat([",", line]), path.call(print, "body", 3));
|
105
|
+
let breakDoc;
|
106
|
+
|
107
|
+
if (hasTernaryArg(node.body[3])) {
|
108
|
+
breakDoc = parts.concat(
|
109
|
+
"(",
|
110
|
+
indent(concat([softline, argDocs])),
|
111
|
+
softline,
|
112
|
+
")"
|
113
|
+
);
|
114
|
+
parts.push(" ");
|
115
|
+
} else if (skipArgsAlign(path)) {
|
116
|
+
parts.push(" ");
|
117
|
+
breakDoc = parts.concat(argDocs);
|
118
|
+
} else {
|
119
|
+
parts.push(" ");
|
120
|
+
breakDoc = parts.concat(align(docLength(concat(parts)), argDocs));
|
121
|
+
}
|
122
|
+
|
123
|
+
const joinedDoc = parts.concat(argDocs);
|
124
|
+
|
125
|
+
return group(ifBreak(concat(breakDoc), concat(joinedDoc)));
|
126
|
+
}
|
127
|
+
|
128
|
+
module.exports = {
|
129
|
+
command: printCommand,
|
130
|
+
command_call: printCommandCall
|
131
|
+
};
|