prettier 1.2.2 → 1.2.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 +14 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +1 -1
- data/package.json +2 -2
- data/src/{ruby.js → plugin.js} +2 -2
- data/src/{embed.js → ruby/embed.js} +2 -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 -3
- data/src/{nodes → ruby/nodes}/blocks.js +3 -3
- data/src/{nodes → ruby/nodes}/calls.js +8 -4
- data/src/{nodes → ruby/nodes}/case.js +1 -1
- data/src/{nodes → ruby/nodes}/class.js +1 -1
- data/src/ruby/nodes/commands.js +126 -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/{nodes → ruby/nodes}/hooks.js +2 -2
- 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 +6 -3
- data/src/{nodes → ruby/nodes}/operators.js +2 -2
- data/src/{nodes → ruby/nodes}/params.js +9 -2
- data/src/{nodes → ruby/nodes}/patterns.js +8 -1
- data/src/{nodes → ruby/nodes}/regexp.js +2 -2
- data/src/{nodes → ruby/nodes}/rescue.js +2 -2
- data/src/{nodes → ruby/nodes}/return.js +21 -6
- data/src/{nodes → ruby/nodes}/statements.js +1 -1
- data/src/{nodes → ruby/nodes}/strings.js +1 -1
- 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} +2 -2
- data/src/{parser.rb → ruby/parser.rb} +258 -312
- data/src/{printer.js → ruby/printer.js} +1 -1
- data/src/{toProc.js → ruby/toProc.js} +0 -0
- 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 +11 -0
- data/src/utils/noIndent.js +10 -0
- data/src/utils/skipAssignIndent.js +10 -0
- metadata +47 -40
- data/src/nodes/commands.js +0 -91
File without changes
|
data/src/utils.js
CHANGED
@@ -1,95 +1,12 @@
|
|
1
|
-
const { concat } = require("./prettier");
|
2
|
-
const isEmptyStmts = require("./utils/isEmptyStmts");
|
3
|
-
const literalLineNoBreak = require("./utils/literalLineNoBreak");
|
4
|
-
const printEmptyCollection = require("./utils/printEmptyCollection");
|
5
|
-
|
6
|
-
// If the node is a type of assignment or if the node is a paren and nested
|
7
|
-
// inside that paren is a node that is a type of assignment.
|
8
|
-
const containsAssignment = (node) =>
|
9
|
-
node &&
|
10
|
-
(["assign", "massign", "opassign"].includes(node.type) ||
|
11
|
-
(Array.isArray(node.body) && node.body.some(containsAssignment)));
|
12
|
-
|
13
|
-
const 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
|
-
const empty = () => "";
|
30
|
-
|
31
|
-
const first = (path, opts, print) => path.call(print, "body", 0);
|
32
|
-
|
33
|
-
const getTrailingComma = (opts) => ["all", "es5"].includes(opts.trailingComma);
|
34
|
-
|
35
|
-
const hasAncestor = (path, types) => {
|
36
|
-
let parent = 0;
|
37
|
-
let parentNode = path.getParentNode();
|
38
|
-
|
39
|
-
while (parentNode) {
|
40
|
-
if (types.includes(parentNode.type)) {
|
41
|
-
return true;
|
42
|
-
}
|
43
|
-
|
44
|
-
parent += 1;
|
45
|
-
parentNode = path.getParentNode(parent);
|
46
|
-
}
|
47
|
-
|
48
|
-
return false;
|
49
|
-
};
|
50
|
-
|
51
|
-
const literal = (value) => () => value;
|
52
|
-
|
53
|
-
const makeCall = (path, opts, print) => {
|
54
|
-
const operation = path.getValue().body[1];
|
55
|
-
|
56
|
-
if ([".", "&."].includes(operation)) {
|
57
|
-
return operation;
|
58
|
-
}
|
59
|
-
|
60
|
-
return operation === "::" ? "." : path.call(print, "body", 1);
|
61
|
-
};
|
62
|
-
|
63
|
-
const noIndent = [
|
64
|
-
"array",
|
65
|
-
"hash",
|
66
|
-
"heredoc",
|
67
|
-
"if",
|
68
|
-
"method_add_block",
|
69
|
-
"xstring_literal"
|
70
|
-
];
|
71
|
-
|
72
|
-
const prefix = (value) => (path, opts, print) =>
|
73
|
-
concat([value, path.call(print, "body", 0)]);
|
74
|
-
|
75
|
-
const skippable = ["array", "hash", "heredoc", "lambda", "regexp_literal"];
|
76
|
-
const skipAssignIndent = (node) =>
|
77
|
-
skippable.includes(node.type) ||
|
78
|
-
(node.type === "call" && skipAssignIndent(node.body[0]));
|
79
|
-
|
80
1
|
module.exports = {
|
81
|
-
containsAssignment,
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
noIndent,
|
92
|
-
prefix,
|
93
|
-
printEmptyCollection,
|
94
|
-
skipAssignIndent
|
2
|
+
containsAssignment: require("./utils/containsAssignment"),
|
3
|
+
getTrailingComma: require("./utils/getTrailingComma"),
|
4
|
+
isEmptyStmts: require("./utils/isEmptyStmts"),
|
5
|
+
hasAncestor: require("./utils/hasAncestor"),
|
6
|
+
literal: require("./utils/literal"),
|
7
|
+
literalLineNoBreak: require("./utils/literalLineNoBreak"),
|
8
|
+
makeCall: require("./utils/makeCall"),
|
9
|
+
noIndent: require("./utils/noIndent"),
|
10
|
+
printEmptyCollection: require("./utils/printEmptyCollection"),
|
11
|
+
skipAssignIndent: require("./utils/skipAssignIndent")
|
95
12
|
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
// If the node is a type of assignment or if the node is a paren and nested
|
2
|
+
// inside that paren is a node that is a type of assignment.
|
3
|
+
function containsAssignment(node) {
|
4
|
+
return (
|
5
|
+
node &&
|
6
|
+
(["assign", "massign", "opassign"].includes(node.type) ||
|
7
|
+
(Array.isArray(node.body) && node.body.some(containsAssignment)))
|
8
|
+
);
|
9
|
+
}
|
10
|
+
|
11
|
+
module.exports = containsAssignment;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
function hasAncestor(path, types) {
|
2
|
+
let parent = 0;
|
3
|
+
let parentNode = path.getParentNode();
|
4
|
+
|
5
|
+
while (parentNode) {
|
6
|
+
if (types.includes(parentNode.type)) {
|
7
|
+
return true;
|
8
|
+
}
|
9
|
+
|
10
|
+
parent += 1;
|
11
|
+
parentNode = path.getParentNode(parent);
|
12
|
+
}
|
13
|
+
|
14
|
+
return false;
|
15
|
+
}
|
16
|
+
|
17
|
+
module.exports = hasAncestor;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
const skippable = ["array", "hash", "heredoc", "lambda", "regexp_literal"];
|
2
|
+
|
3
|
+
function skipAssignIndent(node) {
|
4
|
+
return (
|
5
|
+
skippable.includes(node.type) ||
|
6
|
+
(node.type === "call" && skipAssignIndent(node.body[0]))
|
7
|
+
);
|
8
|
+
}
|
9
|
+
|
10
|
+
module.exports = skipAssignIndent;
|
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.2.
|
4
|
+
version: 1.2.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-01-
|
11
|
+
date: 2021-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -30,50 +30,57 @@ files:
|
|
30
30
|
- node_modules/prettier/index.js
|
31
31
|
- node_modules/prettier/third-party.js
|
32
32
|
- package.json
|
33
|
-
- src/
|
34
|
-
- src/nodes.js
|
35
|
-
- src/nodes/alias.js
|
36
|
-
- src/nodes/aref.js
|
37
|
-
- src/nodes/args.js
|
38
|
-
- src/nodes/arrays.js
|
39
|
-
- src/nodes/assign.js
|
40
|
-
- src/nodes/blocks.js
|
41
|
-
- src/nodes/calls.js
|
42
|
-
- src/nodes/case.js
|
43
|
-
- src/nodes/class.js
|
44
|
-
- src/nodes/commands.js
|
45
|
-
- src/nodes/conditionals.js
|
46
|
-
- src/nodes/constants.js
|
47
|
-
- src/nodes/flow.js
|
48
|
-
- src/nodes/hashes.js
|
49
|
-
- src/nodes/heredocs.js
|
50
|
-
- src/nodes/hooks.js
|
51
|
-
- src/nodes/ints.js
|
52
|
-
- src/nodes/lambdas.js
|
53
|
-
- src/nodes/loops.js
|
54
|
-
- src/nodes/massign.js
|
55
|
-
- src/nodes/methods.js
|
56
|
-
- src/nodes/operators.js
|
57
|
-
- src/nodes/params.js
|
58
|
-
- src/nodes/patterns.js
|
59
|
-
- src/nodes/regexp.js
|
60
|
-
- src/nodes/rescue.js
|
61
|
-
- src/nodes/return.js
|
62
|
-
- src/nodes/statements.js
|
63
|
-
- src/nodes/strings.js
|
64
|
-
- src/nodes/super.js
|
65
|
-
- src/nodes/undef.js
|
66
|
-
- src/parser.js
|
67
|
-
- src/parser.rb
|
33
|
+
- src/plugin.js
|
68
34
|
- src/prettier.js
|
69
|
-
- src/
|
70
|
-
- src/ruby.js
|
71
|
-
- src/
|
35
|
+
- src/ruby/embed.js
|
36
|
+
- src/ruby/nodes.js
|
37
|
+
- src/ruby/nodes/alias.js
|
38
|
+
- src/ruby/nodes/aref.js
|
39
|
+
- src/ruby/nodes/args.js
|
40
|
+
- src/ruby/nodes/arrays.js
|
41
|
+
- src/ruby/nodes/assign.js
|
42
|
+
- src/ruby/nodes/blocks.js
|
43
|
+
- src/ruby/nodes/calls.js
|
44
|
+
- src/ruby/nodes/case.js
|
45
|
+
- src/ruby/nodes/class.js
|
46
|
+
- src/ruby/nodes/commands.js
|
47
|
+
- src/ruby/nodes/conditionals.js
|
48
|
+
- src/ruby/nodes/constants.js
|
49
|
+
- src/ruby/nodes/flow.js
|
50
|
+
- src/ruby/nodes/hashes.js
|
51
|
+
- src/ruby/nodes/heredocs.js
|
52
|
+
- src/ruby/nodes/hooks.js
|
53
|
+
- src/ruby/nodes/ints.js
|
54
|
+
- src/ruby/nodes/lambdas.js
|
55
|
+
- src/ruby/nodes/loops.js
|
56
|
+
- src/ruby/nodes/massign.js
|
57
|
+
- src/ruby/nodes/methods.js
|
58
|
+
- src/ruby/nodes/operators.js
|
59
|
+
- src/ruby/nodes/params.js
|
60
|
+
- src/ruby/nodes/patterns.js
|
61
|
+
- src/ruby/nodes/regexp.js
|
62
|
+
- src/ruby/nodes/rescue.js
|
63
|
+
- src/ruby/nodes/return.js
|
64
|
+
- src/ruby/nodes/statements.js
|
65
|
+
- src/ruby/nodes/strings.js
|
66
|
+
- src/ruby/nodes/super.js
|
67
|
+
- src/ruby/nodes/undef.js
|
68
|
+
- src/ruby/parser.js
|
69
|
+
- src/ruby/parser.rb
|
70
|
+
- src/ruby/printer.js
|
71
|
+
- src/ruby/toProc.js
|
72
72
|
- src/utils.js
|
73
|
+
- src/utils/containsAssignment.js
|
74
|
+
- src/utils/getTrailingComma.js
|
75
|
+
- src/utils/hasAncestor.js
|
73
76
|
- src/utils/inlineEnsureParens.js
|
74
77
|
- src/utils/isEmptyStmts.js
|
78
|
+
- src/utils/literal.js
|
75
79
|
- src/utils/literalLineNoBreak.js
|
80
|
+
- src/utils/makeCall.js
|
81
|
+
- src/utils/noIndent.js
|
76
82
|
- src/utils/printEmptyCollection.js
|
83
|
+
- src/utils/skipAssignIndent.js
|
77
84
|
homepage: https://github.com/prettier/plugin-ruby#readme
|
78
85
|
licenses:
|
79
86
|
- MIT
|
data/src/nodes/commands.js
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
const {
|
2
|
-
align,
|
3
|
-
concat,
|
4
|
-
group,
|
5
|
-
ifBreak,
|
6
|
-
indent,
|
7
|
-
join,
|
8
|
-
line,
|
9
|
-
softline
|
10
|
-
} = require("../prettier");
|
11
|
-
const { docLength, makeCall } = require("../utils");
|
12
|
-
|
13
|
-
const hasDef = (node) =>
|
14
|
-
node.body[1].type === "args_add_block" &&
|
15
|
-
node.body[1].body[0].type === "args" &&
|
16
|
-
node.body[1].body[0].body[0] &&
|
17
|
-
["def", "defs"].includes(node.body[1].body[0].body[0].type);
|
18
|
-
|
19
|
-
// Very special handling case for rspec matchers. In general with rspec matchers
|
20
|
-
// you expect to see something like:
|
21
|
-
//
|
22
|
-
// expect(foo).to receive(:bar).with(
|
23
|
-
// 'one',
|
24
|
-
// 'two',
|
25
|
-
// 'three',
|
26
|
-
// 'four',
|
27
|
-
// 'five'
|
28
|
-
// )
|
29
|
-
//
|
30
|
-
// In this case the arguments are aligned to the left side as opposed to being
|
31
|
-
// aligned with the `receive` call.
|
32
|
-
const skipArgsAlign = (path) =>
|
33
|
-
["to", "not_to"].includes(path.getValue().body[2].body);
|
34
|
-
|
35
|
-
// If there is a ternary argument to a command and it's going to get broken
|
36
|
-
// into multiple lines, then we're going to have to use parentheses around the
|
37
|
-
// command in order to make sure operator precedence doesn't get messed up.
|
38
|
-
const hasTernaryArg = (path) =>
|
39
|
-
path.getValue().body[1].body[0].body.some((node) => node.type === "ifop");
|
40
|
-
|
41
|
-
module.exports = {
|
42
|
-
command: (path, opts, print) => {
|
43
|
-
const command = path.call(print, "body", 0);
|
44
|
-
const joinedArgs = join(concat([",", line]), path.call(print, "body", 1));
|
45
|
-
|
46
|
-
const hasTernary = hasTernaryArg(path);
|
47
|
-
let breakArgs;
|
48
|
-
|
49
|
-
if (hasTernary) {
|
50
|
-
breakArgs = indent(concat([softline, joinedArgs]));
|
51
|
-
} else if (hasDef(path.getValue())) {
|
52
|
-
breakArgs = joinedArgs;
|
53
|
-
} else {
|
54
|
-
breakArgs = align(command.length + 1, joinedArgs);
|
55
|
-
}
|
56
|
-
|
57
|
-
return group(
|
58
|
-
ifBreak(
|
59
|
-
concat([
|
60
|
-
command,
|
61
|
-
hasTernary ? "(" : " ",
|
62
|
-
breakArgs,
|
63
|
-
hasTernary ? concat([softline, ")"]) : ""
|
64
|
-
]),
|
65
|
-
concat([command, " ", joinedArgs])
|
66
|
-
)
|
67
|
-
);
|
68
|
-
},
|
69
|
-
command_call: (path, opts, print) => {
|
70
|
-
const parts = [
|
71
|
-
path.call(print, "body", 0),
|
72
|
-
makeCall(path, opts, print),
|
73
|
-
path.call(print, "body", 2)
|
74
|
-
];
|
75
|
-
|
76
|
-
if (!path.getValue().body[3]) {
|
77
|
-
return concat(parts);
|
78
|
-
}
|
79
|
-
|
80
|
-
parts.push(" ");
|
81
|
-
|
82
|
-
const joinedArgs = join(concat([",", line]), path.call(print, "body", 3));
|
83
|
-
const breakArgs = skipArgsAlign(path)
|
84
|
-
? joinedArgs
|
85
|
-
: align(docLength(concat(parts)), joinedArgs);
|
86
|
-
|
87
|
-
return group(
|
88
|
-
ifBreak(concat(parts.concat(breakArgs)), concat(parts.concat(joinedArgs)))
|
89
|
-
);
|
90
|
-
}
|
91
|
-
};
|