prettier 0.19.1 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -1
- data/package.json +1 -1
- data/src/embed.js +71 -0
- data/src/parse.js +1 -1
- data/src/ruby.js +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 053a1f574f1b5a2ba7b9bc721c0541af8a8455d9bfe56eafcf78e55634458ae8
|
4
|
+
data.tar.gz: 94c18ccd603fdb0df700d21ae2d3cdffc327acc42074e39fcc0f4c02301f71b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d072b0718ba67963b0e115b1f61006668ac512789226dd34ba2912c2426fc1841764920961a10b550ac8c0f106d4a41c50ec73484c7eef419b94e892970a9c8
|
7
|
+
data.tar.gz: 68583e2a4ed6b8b5ba4a5f45a7c40684e2b8127d1118140c0b94424b3818473eb99a6f174c54cae703c37f59206fa844ca2809399423ef595949b1e346359c4c
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,25 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.20.0] - 2020-08-28
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- [@kddeisz] - Allow embedded formatting on heredocs by the name placed at the start. For example,
|
14
|
+
|
15
|
+
<!-- prettier-ignore -->
|
16
|
+
```ruby
|
17
|
+
javascript = <<~JAVASCRIPT
|
18
|
+
const a=1;
|
19
|
+
const b=2;
|
20
|
+
return a+b;
|
21
|
+
JAVASCRIPT
|
22
|
+
```
|
23
|
+
|
24
|
+
### Changed
|
25
|
+
|
26
|
+
- [@mmainz] - Fix the encoding setting such that we're not overwriting the entire set of environment variables.
|
27
|
+
|
9
28
|
## [0.19.1] - 2020-08-21
|
10
29
|
|
11
30
|
### Changed
|
@@ -819,7 +838,8 @@ would previously result in `array[]`, but now prints properly.
|
|
819
838
|
|
820
839
|
- Initial release 🎉
|
821
840
|
|
822
|
-
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.
|
841
|
+
[unreleased]: https://github.com/prettier/plugin-ruby/compare/v0.20.0...HEAD
|
842
|
+
[0.20.0]: https://github.com/prettier/plugin-ruby/compare/v0.19.1...v0.20.0
|
823
843
|
[0.19.1]: https://github.com/prettier/plugin-ruby/compare/v0.19.0...v0.19.1
|
824
844
|
[0.19.0]: https://github.com/prettier/plugin-ruby/compare/v0.18.2...v0.19.0
|
825
845
|
[0.18.2]: https://github.com/prettier/plugin-ruby/compare/v0.18.1...v0.18.2
|
data/package.json
CHANGED
data/src/embed.js
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
const {
|
2
|
+
concat,
|
3
|
+
indent,
|
4
|
+
literalline,
|
5
|
+
mapDoc,
|
6
|
+
markAsRoot,
|
7
|
+
stripTrailingHardline
|
8
|
+
} = require("./prettier");
|
9
|
+
|
10
|
+
const parsers = {
|
11
|
+
css: "css",
|
12
|
+
javascript: "babel",
|
13
|
+
js: "babel",
|
14
|
+
less: "less",
|
15
|
+
markdown: "markdown",
|
16
|
+
ruby: "ruby",
|
17
|
+
scss: "scss"
|
18
|
+
};
|
19
|
+
|
20
|
+
const replaceNewlines = (doc) =>
|
21
|
+
mapDoc(doc, (currentDoc) =>
|
22
|
+
typeof currentDoc === "string" && currentDoc.includes("\n")
|
23
|
+
? concat(
|
24
|
+
currentDoc
|
25
|
+
.split(/(\n)/g)
|
26
|
+
.map((v, i) => (i % 2 === 0 ? v : literalline))
|
27
|
+
)
|
28
|
+
: currentDoc
|
29
|
+
);
|
30
|
+
|
31
|
+
const embed = (path, _print, textToDoc, _opts) => {
|
32
|
+
const node = path.getValue();
|
33
|
+
|
34
|
+
// Currently we only support embedded formatting on heredoc nodes
|
35
|
+
if (node.type !== "heredoc") {
|
36
|
+
return null;
|
37
|
+
}
|
38
|
+
|
39
|
+
// First, ensure that we don't have any interpolation
|
40
|
+
const { beging, body, ending } = node;
|
41
|
+
if (body.some((part) => part.type !== "@tstring_content")) {
|
42
|
+
return null;
|
43
|
+
}
|
44
|
+
|
45
|
+
// Next, find the parser associated with this heredoc (if there is one). For
|
46
|
+
// example, if you use <<~CSS, we'd hook it up to the css parser.
|
47
|
+
const parser = parsers[beging.slice(3).toLowerCase()];
|
48
|
+
if (!parser) {
|
49
|
+
return null;
|
50
|
+
}
|
51
|
+
|
52
|
+
// Get the content as if it were a source string, and then pass that content
|
53
|
+
// into the embedded parser. Get back the doc node.
|
54
|
+
const content = body.map((part) => part.body).join("");
|
55
|
+
const formatted = concat([
|
56
|
+
literalline,
|
57
|
+
replaceNewlines(stripTrailingHardline(textToDoc(content, { parser })))
|
58
|
+
]);
|
59
|
+
|
60
|
+
// If we're using a squiggly heredoc, then we can properly handle indentation
|
61
|
+
// ourselves.
|
62
|
+
if (beging[2] === "~") {
|
63
|
+
return concat([beging, indent(markAsRoot(formatted)), literalline, ending]);
|
64
|
+
}
|
65
|
+
|
66
|
+
// Otherwise, we need to just assume it's formatted correctly and return the
|
67
|
+
// content as it is.
|
68
|
+
return markAsRoot(concat([beging, formatted, literalline, ending]));
|
69
|
+
};
|
70
|
+
|
71
|
+
module.exports = embed;
|
data/src/parse.js
CHANGED
data/src/ruby.js
CHANGED
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.
|
4
|
+
version: 0.20.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: 2020-08-
|
11
|
+
date: 2020-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- node_modules/prettier/index.js
|
73
73
|
- node_modules/prettier/third-party.js
|
74
74
|
- package.json
|
75
|
+
- src/embed.js
|
75
76
|
- src/haml.js
|
76
77
|
- src/haml/embed.js
|
77
78
|
- src/haml/nodes/comment.js
|