prettier 0.20.0 → 0.20.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
5
  "main": "src/ruby.js",
6
6
  "scripts": {
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "all-contributors-cli": "^6.14.1",
26
- "eslint": "^7.1.0",
26
+ "eslint": "^7.8.1",
27
27
  "eslint-config-prettier": "^6.10.1",
28
28
  "husky": "^4.2.5",
29
29
  "jest": "^26.0.0",
@@ -2,8 +2,6 @@ const embed = require("./embed");
2
2
  const parse = require("./parse");
3
3
  const print = require("./print");
4
4
 
5
- const haml = require("./haml");
6
-
7
5
  const pragmaPattern = /#\s*@(prettier|format)/;
8
6
  const hasPragma = (text) => pragmaPattern.test(text);
9
7
 
@@ -76,12 +74,6 @@ module.exports = {
76
74
  interpreters: ["jruby", "macruby", "rake", "rbx", "ruby"],
77
75
  linguistLanguageId: 326,
78
76
  vscodeLanguageIds: ["ruby"]
79
- },
80
- {
81
- name: "HAML",
82
- parsers: ["haml"],
83
- extensions: [".haml"],
84
- vscodeLanguageIds: ["haml"]
85
77
  }
86
78
  ],
87
79
  parsers: {
@@ -91,23 +83,12 @@ module.exports = {
91
83
  hasPragma,
92
84
  locStart,
93
85
  locEnd
94
- },
95
- haml: {
96
- parse: haml.parse,
97
- astFormat: "haml",
98
- hasPragma: haml.hasPragma,
99
- locStart: haml.locStart,
100
- locEnd: haml.locEnd
101
86
  }
102
87
  },
103
88
  printers: {
104
89
  ruby: {
105
90
  embed,
106
91
  print
107
- },
108
- haml: {
109
- embed: haml.embed,
110
- print: haml.print
111
92
  }
112
93
  },
113
94
  options: {
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.20.0
4
+ version: 0.20.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-08-28 00:00:00.000000000 Z
11
+ date: 2020-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,18 +73,6 @@ files:
73
73
  - node_modules/prettier/third-party.js
74
74
  - package.json
75
75
  - src/embed.js
76
- - src/haml.js
77
- - src/haml/embed.js
78
- - src/haml/nodes/comment.js
79
- - src/haml/nodes/doctype.js
80
- - src/haml/nodes/filter.js
81
- - src/haml/nodes/hamlComment.js
82
- - src/haml/nodes/script.js
83
- - src/haml/nodes/silentScript.js
84
- - src/haml/nodes/tag.js
85
- - src/haml/parse.js
86
- - src/haml/parse.rb
87
- - src/haml/print.js
88
76
  - src/nodes.js
89
77
  - src/nodes/alias.js
90
78
  - src/nodes/args.js
@@ -1,21 +0,0 @@
1
- const embed = require("./haml/embed");
2
- const parse = require("./haml/parse");
3
- const print = require("./haml/print");
4
-
5
- const pragmaPattern = /^\s*-#\s*@(prettier|format)/;
6
- const hasPragma = (text) => pragmaPattern.test(text);
7
-
8
- // These functions are just placeholders until we can actually perform this
9
- // properly. The functions are necessary otherwise the format with cursor
10
- // functions break.
11
- const locStart = (_node) => 0;
12
- const locEnd = (_node) => 0;
13
-
14
- module.exports = {
15
- embed,
16
- hasPragma,
17
- locStart,
18
- locEnd,
19
- parse,
20
- print
21
- };
@@ -1,58 +0,0 @@
1
- const {
2
- concat,
3
- hardline,
4
- indent,
5
- literalline,
6
- mapDoc,
7
- markAsRoot,
8
- stripTrailingHardline
9
- } = require("../prettier");
10
-
11
- const parsers = {
12
- css: "css",
13
- javascript: "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
- if (node.type !== "filter") {
34
- return null;
35
- }
36
-
37
- const parser = parsers[node.value.name];
38
- if (!parser) {
39
- return null;
40
- }
41
-
42
- return markAsRoot(
43
- concat([
44
- ":",
45
- node.value.name,
46
- indent(
47
- concat([
48
- hardline,
49
- replaceNewlines(
50
- stripTrailingHardline(textToDoc(node.value.text, { parser }))
51
- )
52
- ])
53
- )
54
- ])
55
- );
56
- };
57
-
58
- module.exports = embed;
@@ -1,27 +0,0 @@
1
- const { concat, group, hardline, indent, join } = require("../../prettier");
2
-
3
- // http://haml.info/docs/yardoc/file.REFERENCE.html#html-comments-
4
- const comment = (path, opts, print) => {
5
- const { children, value } = path.getValue();
6
- const parts = ["/"];
7
-
8
- if (value.revealed) {
9
- parts.push("!");
10
- }
11
-
12
- if (value.conditional) {
13
- parts.push(value.conditional);
14
- } else if (value.text) {
15
- parts.push(" ", value.text);
16
- }
17
-
18
- if (children.length > 0) {
19
- parts.push(
20
- indent(concat([hardline, join(hardline, path.map(print, "children"))]))
21
- );
22
- }
23
-
24
- return group(concat(parts));
25
- };
26
-
27
- module.exports = comment;
@@ -1,32 +0,0 @@
1
- const { join } = require("../../prettier");
2
-
3
- const types = {
4
- basic: "Basic",
5
- frameset: "Frameset",
6
- mobile: "Mobile",
7
- rdfa: "RDFa",
8
- strict: "Strict",
9
- xml: "XML"
10
- };
11
-
12
- const versions = ["1.1", "5"];
13
-
14
- // http://haml.info/docs/yardoc/file.REFERENCE.html#doctype-
15
- const doctype = (path, _opts, _print) => {
16
- const { value } = path.getValue();
17
- const parts = ["!!!"];
18
-
19
- if (value.type in types) {
20
- parts.push(types[value.type]);
21
- } else if (value.version in versions) {
22
- parts.push(versions[value.version]);
23
- }
24
-
25
- if (value.encoding) {
26
- parts.push(value.encoding);
27
- }
28
-
29
- return join(" ", parts);
30
- };
31
-
32
- module.exports = doctype;
@@ -1,16 +0,0 @@
1
- const { concat, group, hardline, indent, join } = require("../../prettier");
2
-
3
- // http://haml.info/docs/yardoc/file.REFERENCE.html#filters
4
- const filter = (path, _opts, _print) => {
5
- const { value } = path.getValue();
6
-
7
- return group(
8
- concat([
9
- ":",
10
- value.name,
11
- indent(concat([hardline, join(hardline, value.text.trim().split("\n"))]))
12
- ])
13
- );
14
- };
15
-
16
- module.exports = filter;
@@ -1,21 +0,0 @@
1
- const { concat, hardline, indent, join } = require("../../prettier");
2
-
3
- // http://haml.info/docs/yardoc/file.REFERENCE.html#haml-comments--
4
- const hamlComment = (path, opts, _print) => {
5
- const node = path.getValue();
6
- const parts = ["-#"];
7
-
8
- if (node.value.text) {
9
- if (opts.originalText.split("\n")[node.line - 1].trim() === "-#") {
10
- const lines = node.value.text.trim().split("\n");
11
-
12
- parts.push(indent(concat([hardline, join(hardline, lines)])));
13
- } else {
14
- parts.push(" ", node.value.text.trim());
15
- }
16
- }
17
-
18
- return concat(parts);
19
- };
20
-
21
- module.exports = hamlComment;
@@ -1,29 +0,0 @@
1
- const { concat, group, hardline, indent, join } = require("../../prettier");
2
-
3
- // http://haml.info/docs/yardoc/file.REFERENCE.html#inserting-ruby-
4
- const script = (path, opts, print) => {
5
- const { children, value } = path.getValue();
6
- const parts = [];
7
-
8
- if (value.escape_html) {
9
- parts.unshift("&");
10
- }
11
-
12
- if (value.preserve) {
13
- parts.push("~");
14
- } else if (!value.interpolate) {
15
- parts.push("=");
16
- }
17
-
18
- parts.push(" ", value.text.trim());
19
-
20
- if (children.length > 0) {
21
- parts.push(
22
- indent(concat([hardline, join(hardline, path.map(print, "children"))]))
23
- );
24
- }
25
-
26
- return group(concat(parts));
27
- };
28
-
29
- module.exports = script;
@@ -1,59 +0,0 @@
1
- const { concat, group, hardline, indent, join } = require("../../prettier");
2
-
3
- const findKeywordIndices = (children, keywords) => {
4
- const indices = [];
5
-
6
- children.forEach((child, index) => {
7
- if (child.type !== "silent_script") {
8
- return;
9
- }
10
-
11
- if (keywords.includes(child.value.keyword)) {
12
- indices.push(index);
13
- }
14
- });
15
-
16
- return indices;
17
- };
18
-
19
- // http://haml.info/docs/yardoc/file.REFERENCE.html#running-ruby--
20
- const silentScript = (path, opts, print) => {
21
- const { children, value } = path.getValue();
22
- const parts = [`- ${value.text.trim()}`];
23
-
24
- if (children.length > 0) {
25
- const scripts = path.map(print, "children");
26
-
27
- if (value.keyword === "case") {
28
- const keywordIndices = findKeywordIndices(children, ["when", "else"]);
29
-
30
- parts.push(
31
- concat(
32
- scripts.map((script, index) => {
33
- const concated = concat([hardline, script]);
34
-
35
- return keywordIndices.includes(index) ? concated : indent(concated);
36
- })
37
- )
38
- );
39
- } else if (["if", "unless"].includes(value.keyword)) {
40
- const keywordIndices = findKeywordIndices(children, ["elsif", "else"]);
41
-
42
- parts.push(
43
- concat(
44
- scripts.map((script, index) => {
45
- const concated = concat([hardline, script]);
46
-
47
- return keywordIndices.includes(index) ? concated : indent(concated);
48
- })
49
- )
50
- );
51
- } else {
52
- parts.push(indent(concat([hardline, join(hardline, scripts)])));
53
- }
54
- }
55
-
56
- return group(concat(parts));
57
- };
58
-
59
- module.exports = silentScript;
@@ -1,157 +0,0 @@
1
- const {
2
- align,
3
- concat,
4
- fill,
5
- group,
6
- hardline,
7
- ifBreak,
8
- indent,
9
- join,
10
- line,
11
- softline
12
- } = require("../../prettier");
13
-
14
- const getDynamicAttributes = (header, attributes) => {
15
- const pairs = attributes
16
- .slice(1, -2)
17
- .split(",")
18
- .map((pair) => pair.slice(1).split('" => '));
19
- const parts = [concat([pairs[0][0], "=", pairs[0][1]])];
20
-
21
- pairs.slice(1).forEach((pair) => {
22
- parts.push(line, concat([pair[0], "=", pair[1]]));
23
- });
24
-
25
- return group(concat(["(", align(header + 1, fill(parts)), ")"]));
26
- };
27
-
28
- const getHashValue = (value, opts) => {
29
- if (typeof value === "string") {
30
- const quote = opts.preferSingleQuotes ? "'" : '"';
31
- return `${quote}${value}${quote}`;
32
- }
33
-
34
- return value;
35
- };
36
-
37
- const getHashRocket = (key, value, opts) => {
38
- const quote = opts.preferSingleQuotes ? "'" : '"';
39
- const leftSide = key.includes(":") ? `:${quote}${key}${quote}` : `:${key}`;
40
-
41
- return `${leftSide} => ${getHashValue(value, opts)}`;
42
- };
43
-
44
- const getHashLabel = (key, value, opts) => {
45
- const quote = opts.preferSingleQuotes ? "'" : '"';
46
- const leftSide = key.includes(":") ? `${quote}${key}${quote}` : key;
47
-
48
- return `${leftSide}: ${getHashValue(value, opts)}`;
49
- };
50
-
51
- const getStaticAttributes = (header, attributes, opts) => {
52
- const keys = Object.keys(attributes).filter(
53
- (name) => !["class", "id"].includes(name)
54
- );
55
-
56
- const getKeyValuePair = opts.preferHashLabels ? getHashLabel : getHashRocket;
57
- const parts = [getKeyValuePair(keys[0], attributes[keys[0]], opts)];
58
-
59
- keys.slice(1).forEach((key) => {
60
- parts.push(",", line, getKeyValuePair(key, attributes[key], opts));
61
- });
62
-
63
- return group(concat(["{", align(header + 1, fill(parts)), "}"]));
64
- };
65
-
66
- const getHeader = (value, opts) => {
67
- const { attributes } = value;
68
- const parts = [];
69
-
70
- if (value.name !== "div") {
71
- parts.push(`%${value.name}`);
72
- }
73
-
74
- if (attributes.class) {
75
- parts.push(`.${attributes.class.replace(/ /g, ".")}`);
76
- }
77
-
78
- if (attributes.id) {
79
- parts.push(`#${attributes.id}`);
80
- }
81
-
82
- if (value.dynamic_attributes.new) {
83
- parts.push(
84
- getDynamicAttributes(parts.join("").length, value.dynamic_attributes.new)
85
- );
86
- }
87
-
88
- if (
89
- Object.keys(attributes).some((name) => name !== "class" && name !== "id")
90
- ) {
91
- parts.push(getStaticAttributes(parts.join("").length, attributes, opts));
92
- }
93
-
94
- if (value.dynamic_attributes.old) {
95
- if (parts.length === 0) {
96
- parts.push("%div");
97
- }
98
- parts.push(value.dynamic_attributes.old);
99
- }
100
-
101
- if (value.object_ref) {
102
- if (parts.length === 0) {
103
- parts.push("%div");
104
- }
105
- parts.push(value.object_ref);
106
- }
107
-
108
- if (value.nuke_outer_whitespace) {
109
- parts.push(">");
110
- }
111
-
112
- if (value.nuke_inner_whitespace) {
113
- parts.push("<");
114
- }
115
-
116
- if (value.self_closing) {
117
- parts.push("/");
118
- }
119
-
120
- if (value.value) {
121
- const prefix = value.parse ? "= " : ifBreak("", " ");
122
-
123
- return group(
124
- concat([
125
- group(concat(parts)),
126
- indent(concat([softline, prefix, value.value]))
127
- ])
128
- );
129
- }
130
-
131
- // In case none of the other if statements have matched and we're printing a
132
- // div, we need to explicitly add it back into the array.
133
- if (parts.length === 0 && value.name === "div") {
134
- parts.push("%div");
135
- }
136
-
137
- return group(concat(parts));
138
- };
139
-
140
- // http://haml.info/docs/yardoc/file.REFERENCE.html#element-name-
141
- const tag = (path, opts, print) => {
142
- const { children, value } = path.getValue();
143
- const header = getHeader(value, opts);
144
-
145
- if (children.length === 0) {
146
- return header;
147
- }
148
-
149
- return group(
150
- concat([
151
- header,
152
- indent(concat([hardline, join(hardline, path.map(print, "children"))]))
153
- ])
154
- );
155
- };
156
-
157
- module.exports = tag;