src/nodes/arrays.js in prettier-1.0.0 vs src/nodes/arrays.js in prettier-1.0.1
- old
+ new
@@ -1,17 +1,16 @@
const {
concat,
group,
- hardline,
ifBreak,
indent,
join,
line,
softline
} = require("../prettier");
-const { getTrailingComma } = require("../utils");
+const { getTrailingComma, printEmptyCollection } = require("../utils");
// Checks that every argument within this args node is a string_literal node
// that has no spaces or interpolations. This means we're dealing with an array
// that looks something like:
//
@@ -91,28 +90,10 @@
return function printSpecialArrayWithStart(path, opts, print) {
return [start].concat(path.map(print, "body"));
};
}
-function printEmptyArrayWithComments(path, opts) {
- const arrayNode = path.getValue();
-
- const printComment = (commentPath, index) => {
- arrayNode.comments[index].printed = true;
- return opts.printer.printComment(commentPath);
- };
-
- return concat([
- "[",
- indent(
- concat([hardline, join(hardline, path.map(printComment, "comments"))])
- ),
- line,
- "]"
- ]);
-}
-
// An array node is any literal array in Ruby. This includes all of the special
// array literals as well as regular arrays. If it is a special array literal
// then it will have one child that represents the special array, otherwise it
// will have one child that contains all of the elements of the array.
function printArray(path, opts, print) {
@@ -120,10 +101,10 @@
const args = array.body[0];
// If there is no inner arguments node, then we're dealing with an empty
// array, so we can go ahead and return.
if (args === null) {
- return array.comments ? printEmptyArrayWithComments(path, opts) : "[]";
+ return printEmptyCollection(path, opts, "[", "]");
}
// If we have an array that contains only simple string literals with no
// spaces or interpolation, then we're going to print a %w array.
if (opts.rubyArrayLiteral && isStringArray(args)) {