prettier 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1738251faac58ab78438da2dcf568a86708d1ccb651d7ec593f0e3c3efc5075a
4
- data.tar.gz: 91666c89e8846d9a908883339238dfec94816adb14c8949fe9232590e493c48b
3
+ metadata.gz: 2b3f385a13ce2aae0cef657abc5d33e5d3d2fbfb59edf1fb39193ded2828cf87
4
+ data.tar.gz: 1049cb733eb60e3221a7df64110f5841f39288f8e91cb589f08cc1c23a0ddfbe
5
5
  SHA512:
6
- metadata.gz: d7df78d09da53ada78d9d9a0d3421e279bc0f1593aaff7a099ef397deea85f4fdde3a044ef91bb88f8f5d6a4f91d52d303e912e60f84b946c35528c0c6f139e1
7
- data.tar.gz: 95e810fa06b71063a010f8e3e3dd3cf7302e2cf1b3573f8da4b7e7fed9288ecaf4d75cbd6429c4b04dbc31728dc879cf1605c8c104fc130bdbfc30583c837e5b
6
+ metadata.gz: ef14696b55d0dd1a544bba5fd45d88e3ab322ab9d2ae34d89b4b6bf84748ac35100022d5e050ed4ef0e5cf5ad93049c1782243cda27e4bae5b7dc87a2f951614
7
+ data.tar.gz: 1bedee0f2b091bc7b7b10ceb645d183271dcea847f8b843c79cd6db5ebf078bb94d7d91fd255127f77c71eb9edd185dcfa166ffe9c442f315f64beb9ba57f4ee
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.1] - 2020-12-12
10
+
11
+ ### Changed
12
+
13
+ - [@steobrien], [@kddeisz] - Ensure leading comments in empty array and hash literals do not duplicate.
14
+
9
15
  ## [1.0.0] - 2020-12-11
10
16
 
11
17
  ### Changed
@@ -951,7 +957,8 @@ would previously result in `array[]`, but now prints properly.
951
957
 
952
958
  - Initial release 🎉
953
959
 
954
- [unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.0.0...HEAD
960
+ [unreleased]: https://github.com/prettier/plugin-ruby/compare/v1.0.1...HEAD
961
+ [1.0.1]: https://github.com/prettier/plugin-ruby/compare/v1.0.0...v1.0.1
955
962
  [1.0.0]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc2...v1.0.0
956
963
  [1.0.0-rc2]: https://github.com/prettier/plugin-ruby/compare/v1.0.0-rc1...v1.0.0-rc2
957
964
  [1.0.0-rc1]: https://github.com/prettier/plugin-ruby/compare/v0.22.0...v1.0.0-rc1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/ruby.js",
6
6
  "scripts": {
@@ -1,7 +1,6 @@
1
1
  const {
2
2
  concat,
3
3
  group,
4
- hardline,
5
4
  ifBreak,
6
5
  indent,
7
6
  join,
@@ -9,7 +8,7 @@ const {
9
8
  softline
10
9
  } = require("../prettier");
11
10
 
12
- const { getTrailingComma } = require("../utils");
11
+ const { getTrailingComma, printEmptyCollection } = require("../utils");
13
12
 
14
13
  // Checks that every argument within this args node is a string_literal node
15
14
  // that has no spaces or interpolations. This means we're dealing with an array
@@ -93,24 +92,6 @@ function printSpecialArray(start) {
93
92
  };
94
93
  }
95
94
 
96
- function printEmptyArrayWithComments(path, opts) {
97
- const arrayNode = path.getValue();
98
-
99
- const printComment = (commentPath, index) => {
100
- arrayNode.comments[index].printed = true;
101
- return opts.printer.printComment(commentPath);
102
- };
103
-
104
- return concat([
105
- "[",
106
- indent(
107
- concat([hardline, join(hardline, path.map(printComment, "comments"))])
108
- ),
109
- line,
110
- "]"
111
- ]);
112
- }
113
-
114
95
  // An array node is any literal array in Ruby. This includes all of the special
115
96
  // array literals as well as regular arrays. If it is a special array literal
116
97
  // then it will have one child that represents the special array, otherwise it
@@ -122,7 +103,7 @@ function printArray(path, opts, print) {
122
103
  // If there is no inner arguments node, then we're dealing with an empty
123
104
  // array, so we can go ahead and return.
124
105
  if (args === null) {
125
- return array.comments ? printEmptyArrayWithComments(path, opts) : "[]";
106
+ return printEmptyCollection(path, opts, "[", "]");
126
107
  }
127
108
 
128
109
  // If we have an array that contains only simple string literals with no
@@ -1,14 +1,11 @@
1
- const {
2
- concat,
3
- group,
4
- hardline,
5
- ifBreak,
6
- indent,
7
- join,
8
- line
9
- } = require("../prettier");
1
+ const { concat, group, ifBreak, indent, join, line } = require("../prettier");
10
2
 
11
- const { getTrailingComma, prefix, skipAssignIndent } = require("../utils");
3
+ const {
4
+ getTrailingComma,
5
+ prefix,
6
+ printEmptyCollection,
7
+ skipAssignIndent
8
+ } = require("../utils");
12
9
 
13
10
  // When attempting to convert a hash rocket into a hash label, you need to take
14
11
  // care because only certain patterns are allowed. Ruby source says that they
@@ -96,26 +93,6 @@ function printHashContents(path, opts, print) {
96
93
  return join(concat([",", line]), path.map(print, "body"));
97
94
  }
98
95
 
99
- function printEmptyHashWithComments(path, opts) {
100
- const hashNode = path.getValue();
101
-
102
- const printComment = (commentPath, index) => {
103
- hashNode.comments[index].printed = true;
104
- return opts.printer.printComment(commentPath);
105
- };
106
-
107
- return group(
108
- concat([
109
- "{",
110
- indent(
111
- concat([hardline, join(hardline, path.map(printComment, "comments"))])
112
- ),
113
- line,
114
- "}"
115
- ])
116
- );
117
- }
118
-
119
96
  function printHash(path, opts, print) {
120
97
  const hashNode = path.getValue();
121
98
 
@@ -123,7 +100,7 @@ function printHash(path, opts, print) {
123
100
  // missing, then it means we're dealing with an empty hash, so we can just
124
101
  // exit here and print.
125
102
  if (hashNode.body[0] === null) {
126
- return hashNode.comments ? printEmptyHashWithComments(path, opts) : "{}";
103
+ return printEmptyCollection(path, opts, "{", "}");
127
104
  }
128
105
 
129
106
  return group(
@@ -98,8 +98,8 @@ module.exports = {
98
98
  stmts[0].comments
99
99
  ) {
100
100
  const comments = path.map(
101
- (commentPath, index) => {
102
- stmts[0].comments[index].printed = true;
101
+ (commentPath) => {
102
+ commentPath.getValue().printed = true;
103
103
  return opts.printer.printComment(commentPath);
104
104
  },
105
105
  "body",
@@ -1,6 +1,7 @@
1
1
  const { concat } = require("./prettier");
2
2
  const isEmptyStmts = require("./utils/isEmptyStmts");
3
3
  const literalLineNoBreak = require("./utils/literalLineNoBreak");
4
+ const printEmptyCollection = require("./utils/printEmptyCollection");
4
5
 
5
6
  // If the node is a type of assignment or if the node is a paren and nested
6
7
  // inside that paren is a node that is a type of assignment.
@@ -89,5 +90,6 @@ module.exports = {
89
90
  makeCall,
90
91
  noIndent,
91
92
  prefix,
93
+ printEmptyCollection,
92
94
  skipAssignIndent
93
95
  };
@@ -0,0 +1,42 @@
1
+ const { concat, group, hardline, indent, join, line } = require("../prettier");
2
+
3
+ // Empty collections are array or hash literals that do not contain any
4
+ // contents. They can, however, have comments inside the body. You can solve
5
+ // this by having a child node inside the array that gets the comments attached
6
+ // to it, but that requires modifying the parser. Instead, we can just manually
7
+ // print out the non-leading comments here.
8
+ function printEmptyCollection(path, opts, startToken, endToken) {
9
+ const node = path.getValue();
10
+
11
+ // If there are no comments or only leading comments, then we can just print
12
+ // out the start and end token and be done, as there are no comments inside
13
+ // the body of this node.
14
+ if (!node.comments || !node.comments.some((comment) => !comment.leading)) {
15
+ return `${startToken}${endToken}`;
16
+ }
17
+
18
+ const comments = [];
19
+
20
+ // For each comment, go through its path and print it out manually.
21
+ const printComment = (commentPath) => {
22
+ const comment = commentPath.getValue();
23
+
24
+ if (!comment.leading) {
25
+ comment.printed = true;
26
+ comments.push(opts.printer.printComment(commentPath));
27
+ }
28
+ };
29
+
30
+ path.each(printComment, "comments");
31
+
32
+ return group(
33
+ concat([
34
+ startToken,
35
+ indent(concat([hardline, join(hardline, comments)])),
36
+ line,
37
+ endToken
38
+ ])
39
+ );
40
+ }
41
+
42
+ module.exports = printEmptyCollection;
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.0.0
4
+ version: 1.0.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: 2020-12-11 00:00:00.000000000 Z
11
+ date: 2020-12-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -73,6 +73,7 @@ files:
73
73
  - src/utils/inlineEnsureParens.js
74
74
  - src/utils/isEmptyStmts.js
75
75
  - src/utils/literalLineNoBreak.js
76
+ - src/utils/printEmptyCollection.js
76
77
  homepage: https://github.com/prettier/plugin-ruby#readme
77
78
  licenses:
78
79
  - MIT