prettier 1.2.4 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +351 -361
  3. data/README.md +11 -96
  4. data/node_modules/prettier/index.js +54 -54
  5. data/package.json +1 -2
  6. data/src/haml/embed.js +87 -0
  7. data/src/haml/nodes/comment.js +27 -0
  8. data/src/haml/nodes/doctype.js +34 -0
  9. data/src/haml/nodes/filter.js +16 -0
  10. data/src/haml/nodes/hamlComment.js +21 -0
  11. data/src/haml/nodes/plain.js +6 -0
  12. data/src/haml/nodes/root.js +8 -0
  13. data/src/haml/nodes/script.js +33 -0
  14. data/src/haml/nodes/silentScript.js +59 -0
  15. data/src/haml/nodes/tag.js +193 -0
  16. data/src/haml/parser.js +22 -0
  17. data/src/haml/parser.rb +138 -0
  18. data/src/haml/printer.js +28 -0
  19. data/src/parser/getLang.js +32 -0
  20. data/src/parser/getNetcat.js +50 -0
  21. data/src/parser/netcat.js +15 -0
  22. data/src/parser/parseSync.js +33 -0
  23. data/src/parser/requestParse.js +74 -0
  24. data/src/parser/server.rb +61 -0
  25. data/src/plugin.js +26 -4
  26. data/src/rbs/parser.js +39 -0
  27. data/src/rbs/parser.rb +94 -0
  28. data/src/rbs/printer.js +605 -0
  29. data/src/ruby/embed.js +54 -8
  30. data/src/ruby/nodes/args.js +20 -6
  31. data/src/ruby/nodes/arrays.js +36 -33
  32. data/src/ruby/nodes/calls.js +12 -43
  33. data/src/ruby/nodes/class.js +17 -27
  34. data/src/ruby/nodes/commands.js +8 -3
  35. data/src/ruby/nodes/conditionals.js +1 -1
  36. data/src/ruby/nodes/hashes.js +28 -14
  37. data/src/ruby/nodes/loops.js +4 -10
  38. data/src/ruby/nodes/methods.js +4 -11
  39. data/src/ruby/nodes/rescue.js +32 -25
  40. data/src/ruby/nodes/statements.js +6 -5
  41. data/src/ruby/nodes/strings.js +7 -6
  42. data/src/ruby/parser.js +2 -50
  43. data/src/ruby/parser.rb +113 -43
  44. data/src/ruby/printer.js +8 -5
  45. data/src/utils.js +1 -0
  46. data/src/utils/inlineEnsureParens.js +8 -1
  47. data/src/utils/isEmptyBodyStmt.js +7 -0
  48. data/src/utils/isEmptyStmts.js +9 -5
  49. data/src/utils/noIndent.js +1 -0
  50. data/src/utils/printEmptyCollection.js +9 -2
  51. metadata +25 -2
@@ -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
 
@@ -1,6 +1,7 @@
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"),
@@ -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;
@@ -4,6 +4,7 @@ const noIndent = [
4
4
  "heredoc",
5
5
  "if",
6
6
  "method_add_block",
7
+ "unless",
7
8
  "xstring_literal"
8
9
  ];
9
10
 
@@ -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.2.4
4
+ version: 1.5.1
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-03 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -31,8 +31,30 @@ files:
31
31
  - node_modules/prettier/third-party.js
32
32
  - package.json
33
33
  - rubocop.yml
34
+ - src/haml/embed.js
35
+ - src/haml/nodes/comment.js
36
+ - src/haml/nodes/doctype.js
37
+ - src/haml/nodes/filter.js
38
+ - src/haml/nodes/hamlComment.js
39
+ - src/haml/nodes/plain.js
40
+ - src/haml/nodes/root.js
41
+ - src/haml/nodes/script.js
42
+ - src/haml/nodes/silentScript.js
43
+ - src/haml/nodes/tag.js
44
+ - src/haml/parser.js
45
+ - src/haml/parser.rb
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
34
53
  - src/plugin.js
35
54
  - src/prettier.js
55
+ - src/rbs/parser.js
56
+ - src/rbs/parser.rb
57
+ - src/rbs/printer.js
36
58
  - src/ruby/embed.js
37
59
  - src/ruby/nodes.js
38
60
  - src/ruby/nodes/alias.js
@@ -75,6 +97,7 @@ files:
75
97
  - src/utils/getTrailingComma.js
76
98
  - src/utils/hasAncestor.js
77
99
  - src/utils/inlineEnsureParens.js
100
+ - src/utils/isEmptyBodyStmt.js
78
101
  - src/utils/isEmptyStmts.js
79
102
  - src/utils/literal.js
80
103
  - src/utils/literalLineNoBreak.js