prettier 0.18.0 → 0.18.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 +4 -4
- data/CHANGELOG.md +51 -2
- data/node_modules/prettier/bin-prettier.js +33129 -26031
- data/node_modules/prettier/index.js +31778 -25277
- data/node_modules/prettier/third-party.js +10733 -3849
- data/package.json +27 -6
- data/src/haml.js +3 -3
- data/src/haml/embed.js +2 -2
- data/src/haml/nodes/tag.js +13 -7
- data/src/haml/parse.rb +5 -8
- data/src/nodes/alias.js +2 -2
- data/src/nodes/args.js +1 -1
- data/src/nodes/arrays.js +6 -6
- data/src/nodes/blocks.js +5 -5
- data/src/nodes/calls.js +44 -9
- data/src/nodes/case.js +1 -1
- data/src/nodes/commands.js +2 -2
- data/src/nodes/conditionals.js +7 -6
- data/src/nodes/hashes.js +2 -2
- data/src/nodes/hooks.js +1 -1
- data/src/nodes/lambdas.js +1 -1
- data/src/nodes/methods.js +2 -2
- data/src/nodes/operators.js +11 -3
- data/src/nodes/params.js +1 -1
- data/src/nodes/regexp.js +1 -1
- data/src/nodes/return.js +11 -1
- data/src/nodes/strings.js +5 -5
- data/src/prettier.js +0 -1
- data/src/ruby.js +3 -3
- data/src/toProc.js +2 -2
- data/src/utils.js +6 -6
- metadata +2 -2
data/src/nodes/lambdas.js
CHANGED
|
@@ -21,7 +21,7 @@ module.exports = {
|
|
|
21
21
|
paramsConcat = path.call(print, "body", 0, "body", 0);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const noParams = params.body.every(type => !type);
|
|
24
|
+
const noParams = params.body.every((type) => !type);
|
|
25
25
|
const inlineLambda = concat([
|
|
26
26
|
"->",
|
|
27
27
|
noParams ? "" : concat(["(", paramsConcat, ")"]),
|
data/src/nodes/methods.js
CHANGED
|
@@ -9,7 +9,7 @@ const {
|
|
|
9
9
|
} = require("../prettier");
|
|
10
10
|
const { first, literal } = require("../utils");
|
|
11
11
|
|
|
12
|
-
const printMethod = offset => (path, opts, print) => {
|
|
12
|
+
const printMethod = (offset) => (path, opts, print) => {
|
|
13
13
|
const [_name, params, body] = path.getValue().body.slice(offset);
|
|
14
14
|
const declaration = ["def "];
|
|
15
15
|
|
|
@@ -21,7 +21,7 @@ const printMethod = offset => (path, opts, print) => {
|
|
|
21
21
|
|
|
22
22
|
// In case there are no parens but there are arguments
|
|
23
23
|
const parens =
|
|
24
|
-
params.type === "params" && params.body.some(paramType => paramType);
|
|
24
|
+
params.type === "params" && params.body.some((paramType) => paramType);
|
|
25
25
|
|
|
26
26
|
declaration.push(
|
|
27
27
|
path.call(print, "body", offset),
|
data/src/nodes/operators.js
CHANGED
|
@@ -7,10 +7,18 @@ module.exports = {
|
|
|
7
7
|
|
|
8
8
|
return group(
|
|
9
9
|
concat([
|
|
10
|
-
|
|
11
|
-
operator,
|
|
10
|
+
group(path.call(print, "body", 0)),
|
|
12
11
|
indent(
|
|
13
|
-
concat([
|
|
12
|
+
concat([
|
|
13
|
+
useNoSpace ? "" : " ",
|
|
14
|
+
group(
|
|
15
|
+
concat([
|
|
16
|
+
operator,
|
|
17
|
+
useNoSpace ? softline : line,
|
|
18
|
+
path.call(print, "body", 2)
|
|
19
|
+
])
|
|
20
|
+
)
|
|
21
|
+
])
|
|
14
22
|
)
|
|
15
23
|
])
|
|
16
24
|
);
|
data/src/nodes/params.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { concat, group, join, line } = require("../prettier");
|
|
2
2
|
const { literal } = require("../utils");
|
|
3
3
|
|
|
4
|
-
const printGenericRestParam = symbol => (path, opts, print) =>
|
|
4
|
+
const printGenericRestParam = (symbol) => (path, opts, print) =>
|
|
5
5
|
path.getValue().body[0]
|
|
6
6
|
? concat([symbol, path.call(print, "body", 0)])
|
|
7
7
|
: symbol;
|
data/src/nodes/regexp.js
CHANGED
|
@@ -7,7 +7,7 @@ module.exports = {
|
|
|
7
7
|
const [contents, ending] = path.map(print, "body");
|
|
8
8
|
|
|
9
9
|
const useBraces = contents.some(
|
|
10
|
-
content => typeof content === "string" && content.includes("/")
|
|
10
|
+
(content) => typeof content === "string" && content.includes("/")
|
|
11
11
|
);
|
|
12
12
|
const parts = [useBraces ? "%r{" : "/"]
|
|
13
13
|
.concat(contents)
|
data/src/nodes/return.js
CHANGED
|
@@ -9,6 +9,16 @@ const {
|
|
|
9
9
|
} = require("../prettier");
|
|
10
10
|
const { literal } = require("../utils");
|
|
11
11
|
|
|
12
|
+
// You can't skip the parentheses if you have the `and` or `or` operator,
|
|
13
|
+
// because they have low enough operator precedence that you need to explicitly
|
|
14
|
+
// keep them in there.
|
|
15
|
+
const canSkipParens = (args) => {
|
|
16
|
+
const statement = args.body[0].body[0].body[0];
|
|
17
|
+
return (
|
|
18
|
+
statement.type !== "binary" || !["and", "or"].includes(statement.body[1])
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
12
22
|
const printReturn = (path, opts, print) => {
|
|
13
23
|
let args = path.getValue().body[0].body[0];
|
|
14
24
|
let steps = ["body", 0, "body", 0];
|
|
@@ -20,7 +30,7 @@ const printReturn = (path, opts, print) => {
|
|
|
20
30
|
// If the body of the return contains parens, then just skip directly to the
|
|
21
31
|
// content of the parens so that we can skip printing parens if we don't
|
|
22
32
|
// want them.
|
|
23
|
-
if (args.body[0] && args.body[0].type === "paren") {
|
|
33
|
+
if (args.body[0] && args.body[0].type === "paren" && canSkipParens(args)) {
|
|
24
34
|
args = args.body[0].body[0];
|
|
25
35
|
steps = steps.concat("body", 0, "body", 0);
|
|
26
36
|
}
|
data/src/nodes/strings.js
CHANGED
|
@@ -15,18 +15,18 @@ const { concatBody, empty, makeList, prefix, surround } = require("../utils");
|
|
|
15
15
|
// quote the user chose. (If they chose single quotes, then double quoting
|
|
16
16
|
// would activate the escape sequence, and if they chose double quotes, then
|
|
17
17
|
// single quotes would deactivate it.)
|
|
18
|
-
const isQuoteLocked = string =>
|
|
18
|
+
const isQuoteLocked = (string) =>
|
|
19
19
|
string.body.some(
|
|
20
|
-
part =>
|
|
20
|
+
(part) =>
|
|
21
21
|
part.type === "@tstring_content" &&
|
|
22
22
|
(part.body.includes("#{") || part.body.includes("\\"))
|
|
23
23
|
);
|
|
24
24
|
|
|
25
25
|
// A string is considered to be able to use single quotes if it contains only
|
|
26
26
|
// plain string content and that content does not contain a single quote.
|
|
27
|
-
const isSingleQuotable = string =>
|
|
27
|
+
const isSingleQuotable = (string) =>
|
|
28
28
|
string.body.every(
|
|
29
|
-
part => part.type === "@tstring_content" && !part.body.includes("'")
|
|
29
|
+
(part) => part.type === "@tstring_content" && !part.body.includes("'")
|
|
30
30
|
);
|
|
31
31
|
|
|
32
32
|
const quotePattern = new RegExp("\\\\([\\s\\S])|(['\"])", "g");
|
|
@@ -61,7 +61,7 @@ const quotePairs = {
|
|
|
61
61
|
"<": ">"
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
const getClosingQuote = quote => {
|
|
64
|
+
const getClosingQuote = (quote) => {
|
|
65
65
|
if (!quote.startsWith("%")) {
|
|
66
66
|
return quote;
|
|
67
67
|
}
|
data/src/prettier.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// directly, as it's been shipped with the gem.
|
|
4
4
|
const source = process.env.RBPRETTIER ? "../node_modules/prettier" : "prettier";
|
|
5
5
|
|
|
6
|
-
// eslint-disable-next-line import/no-dynamic-require
|
|
7
6
|
const prettier = require(source);
|
|
8
7
|
|
|
9
8
|
// Just combine all the things into one big object so that we can import
|
data/src/ruby.js
CHANGED
|
@@ -4,10 +4,10 @@ const print = require("./print");
|
|
|
4
4
|
const haml = require("./haml");
|
|
5
5
|
|
|
6
6
|
const pragmaPattern = /#\s*@(prettier|format)/;
|
|
7
|
-
const hasPragma = text => pragmaPattern.test(text);
|
|
7
|
+
const hasPragma = (text) => pragmaPattern.test(text);
|
|
8
8
|
|
|
9
|
-
const locStart = node => node.char_start;
|
|
10
|
-
const locEnd = node => node.char_end;
|
|
9
|
+
const locStart = (node) => node.char_start;
|
|
10
|
+
const locEnd = (node) => node.char_end;
|
|
11
11
|
|
|
12
12
|
/*
|
|
13
13
|
* metadata mostly pulled from linguist and rubocop:
|
data/src/toProc.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const isCall = node => ["::", "."].includes(node) || node.type === "@period";
|
|
1
|
+
const isCall = (node) => ["::", "."].includes(node) || node.type === "@period";
|
|
2
2
|
|
|
3
3
|
// If you have a simple block that only calls a method on the single required
|
|
4
4
|
// parameter that is passed to it, then you can replace that block with the
|
|
@@ -11,7 +11,7 @@ const isCall = node => ["::", "."].includes(node) || node.type === "@period";
|
|
|
11
11
|
// [1, 2, 3].map(&:to_s)
|
|
12
12
|
//
|
|
13
13
|
// This works with `do` blocks as well.
|
|
14
|
-
const toProc = node => {
|
|
14
|
+
const toProc = (node) => {
|
|
15
15
|
if (!node) {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
data/src/utils.js
CHANGED
|
@@ -10,11 +10,11 @@ const concatBody = (path, opts, print) => concat(path.map(print, "body"));
|
|
|
10
10
|
|
|
11
11
|
// If the node is a type of assignment or if the node is a paren and nested
|
|
12
12
|
// inside that paren is a node that is a type of assignment.
|
|
13
|
-
const containsAssignment = node =>
|
|
13
|
+
const containsAssignment = (node) =>
|
|
14
14
|
["assign", "massign"].includes(node.type) ||
|
|
15
15
|
(node.type === "paren" && node.body[0].body.some(containsAssignment));
|
|
16
16
|
|
|
17
|
-
const docLength = doc => {
|
|
17
|
+
const docLength = (doc) => {
|
|
18
18
|
if (doc.length) {
|
|
19
19
|
return doc.length;
|
|
20
20
|
}
|
|
@@ -50,7 +50,7 @@ const hasAncestor = (path, types) => {
|
|
|
50
50
|
return false;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
const literal = value => () => value;
|
|
53
|
+
const literal = (value) => () => value;
|
|
54
54
|
|
|
55
55
|
const makeArgs = (path, opts, print, argsIndex) => {
|
|
56
56
|
let argNodes = path.getValue().body[argsIndex];
|
|
@@ -103,13 +103,13 @@ const makeCall = (path, opts, print) => {
|
|
|
103
103
|
|
|
104
104
|
const makeList = (path, opts, print) => path.map(print, "body");
|
|
105
105
|
|
|
106
|
-
const prefix = value => (path, opts, print) =>
|
|
106
|
+
const prefix = (value) => (path, opts, print) =>
|
|
107
107
|
concat([value, path.call(print, "body", 0)]);
|
|
108
108
|
|
|
109
109
|
const printComments = (printed, start, comments) => {
|
|
110
110
|
let node = printed;
|
|
111
111
|
|
|
112
|
-
comments.forEach(comment => {
|
|
112
|
+
comments.forEach((comment) => {
|
|
113
113
|
if (comment.start < start) {
|
|
114
114
|
node = concat([
|
|
115
115
|
comment.break ? breakParent : "",
|
|
@@ -129,7 +129,7 @@ const printComments = (printed, start, comments) => {
|
|
|
129
129
|
return node;
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
const skipAssignIndent = node =>
|
|
132
|
+
const skipAssignIndent = (node) =>
|
|
133
133
|
["array", "hash", "heredoc", "lambda", "regexp_literal"].includes(
|
|
134
134
|
node.type
|
|
135
135
|
) ||
|
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: 0.18.
|
|
4
|
+
version: 0.18.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-
|
|
11
|
+
date: 2020-04-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|