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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1f1b3a234ed95cb01a603dafef678f5363e34953a35fb662ce59a83a0462393
4
- data.tar.gz: 77fbbb7333e1d119a3ec3fbd6f4c3c305cba1826b9b03e5b22a7876ef5f0f686
3
+ metadata.gz: 053a1f574f1b5a2ba7b9bc721c0541af8a8455d9bfe56eafcf78e55634458ae8
4
+ data.tar.gz: 94c18ccd603fdb0df700d21ae2d3cdffc327acc42074e39fcc0f4c02301f71b6
5
5
  SHA512:
6
- metadata.gz: 541b753615c3d8daab03eaeb2d82ec4fcca83e112ffc252a86be359f44f98368244701e92f386ab3c9b38f519e308144d9f8274017a25ee9258ca0f2af075226
7
- data.tar.gz: 60da4e2ab1e640bb58df4ffccdade65c7dad1b923372f30d43799939ad084623ec996c3ef24c501681119a09d4ecaf481583770cb367d21f43a308748ac84483
6
+ metadata.gz: 6d072b0718ba67963b0e115b1f61006668ac512789226dd34ba2912c2426fc1841764920961a10b550ac8c0f106d4a41c50ec73484c7eef419b94e892970a9c8
7
+ data.tar.gz: 68583e2a4ed6b8b5ba4a5f45a7c40684e2b8127d1118140c0b94424b3818473eb99a6f174c54cae703c37f59206fa844ca2809399423ef595949b1e346359c4c
@@ -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.19.1...HEAD
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "0.19.1",
3
+ "version": "0.20.0",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/ruby.js",
6
6
  "scripts": {
@@ -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;
@@ -21,7 +21,7 @@ module.exports = (text, _parsers, _opts) => {
21
21
  "ruby",
22
22
  ["--disable-gems", path.join(__dirname, "./ripper.rb")],
23
23
  {
24
- env: { LANG },
24
+ env: Object.assign({}, process.env, { LANG }),
25
25
  input: text,
26
26
  maxBuffer: 10 * 1024 * 1024 // 10MB
27
27
  }
@@ -1,3 +1,4 @@
1
+ const embed = require("./embed");
1
2
  const parse = require("./parse");
2
3
  const print = require("./print");
3
4
 
@@ -101,6 +102,7 @@ module.exports = {
101
102
  },
102
103
  printers: {
103
104
  ruby: {
105
+ embed,
104
106
  print
105
107
  },
106
108
  haml: {
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.19.1
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-21 00:00:00.000000000 Z
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