prettier 1.2.3 → 1.5.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +349 -358
  3. data/README.md +21 -93
  4. data/node_modules/prettier/index.js +54 -54
  5. data/package.json +1 -2
  6. data/rubocop.yml +26 -0
  7. data/src/haml/embed.js +87 -0
  8. data/src/haml/nodes/comment.js +27 -0
  9. data/src/haml/nodes/doctype.js +34 -0
  10. data/src/haml/nodes/filter.js +16 -0
  11. data/src/haml/nodes/hamlComment.js +21 -0
  12. data/src/haml/nodes/plain.js +6 -0
  13. data/src/haml/nodes/root.js +8 -0
  14. data/src/haml/nodes/script.js +33 -0
  15. data/src/haml/nodes/silentScript.js +59 -0
  16. data/src/haml/nodes/tag.js +193 -0
  17. data/src/haml/parser.js +22 -0
  18. data/src/haml/parser.rb +138 -0
  19. data/src/haml/printer.js +28 -0
  20. data/src/parser/getLang.js +32 -0
  21. data/src/parser/getNetcat.js +50 -0
  22. data/src/parser/netcat.js +15 -0
  23. data/src/parser/parseSync.js +33 -0
  24. data/src/parser/requestParse.js +74 -0
  25. data/src/parser/server.rb +61 -0
  26. data/src/plugin.js +26 -4
  27. data/src/prettier.js +1 -0
  28. data/src/rbs/parser.js +39 -0
  29. data/src/rbs/parser.rb +94 -0
  30. data/src/rbs/printer.js +605 -0
  31. data/src/ruby/embed.js +58 -8
  32. data/src/ruby/nodes/args.js +20 -6
  33. data/src/ruby/nodes/blocks.js +64 -59
  34. data/src/ruby/nodes/calls.js +12 -43
  35. data/src/ruby/nodes/class.js +17 -27
  36. data/src/ruby/nodes/commands.js +7 -2
  37. data/src/ruby/nodes/conditionals.js +1 -1
  38. data/src/ruby/nodes/hashes.js +28 -14
  39. data/src/ruby/nodes/hooks.js +9 -19
  40. data/src/ruby/nodes/loops.js +4 -10
  41. data/src/ruby/nodes/methods.js +8 -17
  42. data/src/ruby/nodes/params.js +22 -14
  43. data/src/ruby/nodes/patterns.js +9 -5
  44. data/src/ruby/nodes/rescue.js +32 -25
  45. data/src/ruby/nodes/return.js +0 -4
  46. data/src/ruby/nodes/statements.js +11 -13
  47. data/src/ruby/nodes/strings.js +27 -35
  48. data/src/ruby/parser.js +2 -49
  49. data/src/ruby/parser.rb +256 -232
  50. data/src/ruby/printer.js +0 -2
  51. data/src/ruby/toProc.js +4 -8
  52. data/src/utils.js +1 -0
  53. data/src/utils/isEmptyBodyStmt.js +7 -0
  54. data/src/utils/isEmptyStmts.js +9 -5
  55. data/src/utils/makeCall.js +3 -0
  56. data/src/utils/noIndent.js +1 -0
  57. data/src/utils/printEmptyCollection.js +9 -2
  58. metadata +26 -2
@@ -54,8 +54,6 @@ function getCommentChildNodes(node) {
54
54
  switch (node.type) {
55
55
  case "heredoc":
56
56
  return [node.beging];
57
- case "rescue":
58
- return [].concat(node.body[0]).concat(node.body.slice(1));
59
57
  case "aryptn":
60
58
  return [node.body[0]]
61
59
  .concat(node.body[1])
@@ -12,15 +12,11 @@ const isCall = (node) => ["::", "."].includes(node) || node.type === "@period";
12
12
  //
13
13
  // This works with `do` blocks as well.
14
14
  const toProc = (path, node) => {
15
- if (!node) {
16
- return null;
17
- }
18
-
19
15
  const [variables, blockContents] = node.body;
20
16
 
21
17
  // Ensure that there are variables being passed to this block.
22
18
  const params = variables && variables.body[0];
23
- if (!params || params.type !== "params") {
19
+ if (!params) {
24
20
  return null;
25
21
  }
26
22
 
@@ -39,7 +35,7 @@ const toProc = (path, node) => {
39
35
  if (blockContents.type === "bodystmt") {
40
36
  // We’re in a `do` block
41
37
  const blockStatements = blockContents.body[0];
42
- const rescueElseEnsure = blockStatements.body.slice(1);
38
+ const rescueElseEnsure = blockContents.body.slice(1);
43
39
 
44
40
  // You can’t use the to_proc shortcut if you’re rescuing
45
41
  if (rescueElseEnsure.some(Boolean)) {
@@ -84,7 +80,7 @@ const toProc = (path, node) => {
84
80
 
85
81
  if (path.getValue().type === "method_add_block") {
86
82
  assocNode = path.getParentNode();
87
- } else if (path.getValue().type === "args") {
83
+ } else {
88
84
  assocNode = path.getParentNode(2);
89
85
  }
90
86
 
@@ -97,7 +93,7 @@ const toProc = (path, node) => {
97
93
 
98
94
  if (
99
95
  key.type === "symbol_literal" &&
100
- ["if", "unless"].includes(key.body[0].body[0].body)
96
+ ["if", "unless"].includes(key.body[0].body)
101
97
  ) {
102
98
  return null;
103
99
  }
@@ -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"),
@@ -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;
@@ -1,6 +1,9 @@
1
1
  function makeCall(path, opts, print) {
2
2
  const operation = path.getValue().body[1];
3
3
 
4
+ // Ignoring the next block for coverage information because it's only relevant
5
+ // in Ruby 2.5 and below.
6
+ /* istanbul ignore next */
4
7
  if ([".", "&."].includes(operation)) {
5
8
  return operation;
6
9
  }
@@ -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.3
4
+ version: 1.5.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: 2021-01-03 00:00:00.000000000 Z
11
+ date: 2021-01-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -30,8 +30,31 @@ files:
30
30
  - node_modules/prettier/index.js
31
31
  - node_modules/prettier/third-party.js
32
32
  - package.json
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
33
53
  - src/plugin.js
34
54
  - src/prettier.js
55
+ - src/rbs/parser.js
56
+ - src/rbs/parser.rb
57
+ - src/rbs/printer.js
35
58
  - src/ruby/embed.js
36
59
  - src/ruby/nodes.js
37
60
  - src/ruby/nodes/alias.js
@@ -74,6 +97,7 @@ files:
74
97
  - src/utils/getTrailingComma.js
75
98
  - src/utils/hasAncestor.js
76
99
  - src/utils/inlineEnsureParens.js
100
+ - src/utils/isEmptyBodyStmt.js
77
101
  - src/utils/isEmptyStmts.js
78
102
  - src/utils/literal.js
79
103
  - src/utils/literalLineNoBreak.js