prettier 1.3.0 → 1.5.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.
data/src/ruby/printer.js CHANGED
@@ -38,7 +38,8 @@ const noComments = [
38
38
  "args_add_star",
39
39
  "mlhs",
40
40
  "mlhs_add_post",
41
- "mlhs_add_star"
41
+ "mlhs_add_star",
42
+ "mlhs_paren"
42
43
  ];
43
44
 
44
45
  // Certain nodes are used more for organizational purposed than for actually
@@ -54,8 +55,6 @@ function getCommentChildNodes(node) {
54
55
  switch (node.type) {
55
56
  case "heredoc":
56
57
  return [node.beging];
57
- case "rescue":
58
- return [].concat(node.body[0]).concat(node.body.slice(1));
59
58
  case "aryptn":
60
59
  return [node.body[0]]
61
60
  .concat(node.body[1])
@@ -99,8 +98,12 @@ function getCommentChildNodes(node) {
99
98
 
100
99
  return parts;
101
100
  }
102
- default:
103
- return node.body;
101
+ default: {
102
+ if (Array.isArray(node.body)) {
103
+ return node.body.filter((child) => child && typeof child === "object");
104
+ }
105
+ return [];
106
+ }
104
107
  }
105
108
  }
106
109
 
data/src/utils.js CHANGED
@@ -1,10 +1,11 @@
1
1
  module.exports = {
2
2
  containsAssignment: require("./utils/containsAssignment"),
3
3
  getTrailingComma: require("./utils/getTrailingComma"),
4
+ isEmptyBodyStmt: require("./utils/isEmptyBodyStmt"),
4
5
  isEmptyStmts: require("./utils/isEmptyStmts"),
5
6
  hasAncestor: require("./utils/hasAncestor"),
6
7
  literal: require("./utils/literal"),
7
- literalLineNoBreak: require("./utils/literalLineNoBreak"),
8
+ literallineWithoutBreakParent: require("./utils/literallineWithoutBreakParent"),
8
9
  makeCall: require("./utils/makeCall"),
9
10
  noIndent: require("./utils/noIndent"),
10
11
  printEmptyCollection: require("./utils/printEmptyCollection"),
@@ -1,4 +1,11 @@
1
- const needsParens = ["args", "assign", "assoc_new", "massign", "opassign"];
1
+ const needsParens = [
2
+ "args",
3
+ "assign",
4
+ "assoc_new",
5
+ "call",
6
+ "massign",
7
+ "opassign"
8
+ ];
2
9
 
3
10
  // If you have a modifier statement (for instance an inline if statement or an
4
11
  // inline while loop) there are times when you need to wrap the entire statement
@@ -0,0 +1,7 @@
1
+ const isEmptyStmts = require("./isEmptyStmts");
2
+
3
+ function isEmptyBodyStmt(node) {
4
+ return isEmptyStmts(node.body[0]) && !node.body.slice(1).some(Boolean);
5
+ }
6
+
7
+ module.exports = isEmptyBodyStmt;
@@ -1,7 +1,11 @@
1
- const isEmptyStmts = (node) =>
2
- node &&
3
- node.type === "stmts" &&
4
- node.body.length === 1 &&
5
- node.body[0].type === "void_stmt";
1
+ function isEmptyStmts(node) {
2
+ return (
3
+ node &&
4
+ node.type === "stmts" &&
5
+ node.body.length === 1 &&
6
+ node.body[0].type === "void_stmt" &&
7
+ !node.body[0].comments
8
+ );
9
+ }
6
10
 
7
11
  module.exports = isEmptyStmts;
@@ -0,0 +1,7 @@
1
+ const literallineWithoutBreakParent = {
2
+ type: "line",
3
+ hard: true,
4
+ literal: true
5
+ };
6
+
7
+ module.exports = literallineWithoutBreakParent;
@@ -1,5 +1,11 @@
1
1
  const { concat, group, hardline, indent, join, line } = require("../prettier");
2
2
 
3
+ function containedWithin(node) {
4
+ return function containedWithinNode(comment) {
5
+ return comment.sc >= node.sc && comment.ec <= node.ec;
6
+ };
7
+ }
8
+
3
9
  // Empty collections are array or hash literals that do not contain any
4
10
  // contents. They can, however, have comments inside the body. You can solve
5
11
  // this by having a child node inside the array that gets the comments attached
@@ -7,11 +13,12 @@ const { concat, group, hardline, indent, join, line } = require("../prettier");
7
13
  // print out the non-leading comments here.
8
14
  function printEmptyCollection(path, opts, startToken, endToken) {
9
15
  const node = path.getValue();
16
+ const containedWithinNode = containedWithin(node);
10
17
 
11
18
  // If there are no comments or only leading comments, then we can just print
12
19
  // out the start and end token and be done, as there are no comments inside
13
20
  // the body of this node.
14
- if (!node.comments || !node.comments.some((comment) => !comment.leading)) {
21
+ if (!node.comments || !node.comments.some(containedWithinNode)) {
15
22
  return `${startToken}${endToken}`;
16
23
  }
17
24
 
@@ -21,7 +28,7 @@ function printEmptyCollection(path, opts, startToken, endToken) {
21
28
  const printComment = (commentPath) => {
22
29
  const comment = commentPath.getValue();
23
30
 
24
- if (!comment.leading) {
31
+ if (containedWithinNode(comment)) {
25
32
  comment.printed = true;
26
33
  comments.push(opts.printer.printComment(commentPath));
27
34
  }
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.3.0
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-01-05 00:00:00.000000000 Z
11
+ date: 2021-02-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -44,6 +44,12 @@ files:
44
44
  - src/haml/parser.js
45
45
  - src/haml/parser.rb
46
46
  - src/haml/printer.js
47
+ - src/parser/getLang.js
48
+ - src/parser/getNetcat.js
49
+ - src/parser/netcat.js
50
+ - src/parser/parseSync.js
51
+ - src/parser/requestParse.js
52
+ - src/parser/server.rb
47
53
  - src/plugin.js
48
54
  - src/prettier.js
49
55
  - src/rbs/parser.js
@@ -91,9 +97,10 @@ files:
91
97
  - src/utils/getTrailingComma.js
92
98
  - src/utils/hasAncestor.js
93
99
  - src/utils/inlineEnsureParens.js
100
+ - src/utils/isEmptyBodyStmt.js
94
101
  - src/utils/isEmptyStmts.js
95
102
  - src/utils/literal.js
96
- - src/utils/literalLineNoBreak.js
103
+ - src/utils/literallineWithoutBreakParent.js
97
104
  - src/utils/makeCall.js
98
105
  - src/utils/noIndent.js
99
106
  - src/utils/printEmptyCollection.js
@@ -117,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
124
  - !ruby/object:Gem::Version
118
125
  version: '0'
119
126
  requirements: []
120
- rubygems_version: 3.0.3
127
+ rubygems_version: 3.2.3
121
128
  signing_key:
122
129
  specification_version: 4
123
130
  summary: prettier plugin for the Ruby programming language
@@ -1,7 +0,0 @@
1
- const literalLineNoBreak = {
2
- type: "line",
3
- hard: true,
4
- literal: true
5
- };
6
-
7
- module.exports = literalLineNoBreak;