prettier 1.5.4 → 2.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +338 -276
  3. data/CONTRIBUTING.md +8 -11
  4. data/LICENSE +1 -1
  5. data/README.md +31 -14
  6. data/dist/haml/embed.js +53 -0
  7. data/dist/haml/parser.js +31 -0
  8. data/{src → dist}/haml/parser.rb +8 -1
  9. data/dist/haml/printer.js +336 -0
  10. data/dist/parser/getInfo.js +17 -0
  11. data/{src → dist}/parser/netcat.js +1 -0
  12. data/dist/parser/parseSync.js +128 -0
  13. data/dist/parser/server.rb +140 -0
  14. data/dist/plugin.js +143 -0
  15. data/dist/prettier.js +15 -0
  16. data/dist/rbs/parser.js +34 -0
  17. data/{src → dist}/rbs/parser.rb +7 -1
  18. data/dist/rbs/printer.js +517 -0
  19. data/dist/ruby/embed.js +110 -0
  20. data/dist/ruby/nodes/alias.js +59 -0
  21. data/{src → dist}/ruby/nodes/aref.js +26 -35
  22. data/dist/ruby/nodes/args.js +165 -0
  23. data/dist/ruby/nodes/arrays.js +126 -0
  24. data/dist/ruby/nodes/assign.js +41 -0
  25. data/dist/ruby/nodes/blocks.js +68 -0
  26. data/dist/ruby/nodes/calls.js +220 -0
  27. data/dist/ruby/nodes/case.js +50 -0
  28. data/dist/ruby/nodes/class.js +54 -0
  29. data/dist/ruby/nodes/commands.js +124 -0
  30. data/dist/ruby/nodes/conditionals.js +242 -0
  31. data/dist/ruby/nodes/constants.js +38 -0
  32. data/dist/ruby/nodes/flow.js +66 -0
  33. data/dist/ruby/nodes/hashes.js +130 -0
  34. data/dist/ruby/nodes/heredocs.js +30 -0
  35. data/dist/ruby/nodes/hooks.js +35 -0
  36. data/dist/ruby/nodes/ints.js +27 -0
  37. data/dist/ruby/nodes/lambdas.js +69 -0
  38. data/dist/ruby/nodes/loops.js +73 -0
  39. data/dist/ruby/nodes/massign.js +73 -0
  40. data/dist/ruby/nodes/methods.js +70 -0
  41. data/dist/ruby/nodes/operators.js +70 -0
  42. data/dist/ruby/nodes/params.js +89 -0
  43. data/dist/ruby/nodes/patterns.js +109 -0
  44. data/dist/ruby/nodes/regexp.js +45 -0
  45. data/dist/ruby/nodes/rescue.js +82 -0
  46. data/dist/ruby/nodes/return.js +75 -0
  47. data/dist/ruby/nodes/statements.js +111 -0
  48. data/dist/ruby/nodes/strings.js +218 -0
  49. data/dist/ruby/nodes/super.js +30 -0
  50. data/dist/ruby/nodes/undef.js +26 -0
  51. data/dist/ruby/nodes.js +151 -0
  52. data/dist/ruby/parser.js +34 -0
  53. data/{src → dist}/ruby/parser.rb +1276 -290
  54. data/dist/ruby/printer.js +125 -0
  55. data/dist/ruby/toProc.js +93 -0
  56. data/dist/types/haml.js +4 -0
  57. data/dist/types/plugin.js +3 -0
  58. data/dist/types/rbs.js +4 -0
  59. data/dist/types/ruby.js +4 -0
  60. data/dist/types/utils.js +2 -0
  61. data/dist/types.js +30 -0
  62. data/dist/utils/containsAssignment.js +15 -0
  63. data/dist/utils/getTrailingComma.js +6 -0
  64. data/dist/utils/hasAncestor.js +15 -0
  65. data/{src → dist}/utils/inlineEnsureParens.js +16 -16
  66. data/dist/utils/isEmptyBodyStmt.js +10 -0
  67. data/dist/utils/isEmptyStmts.js +10 -0
  68. data/dist/utils/literal.js +8 -0
  69. data/dist/utils/literallineWithoutBreakParent.js +8 -0
  70. data/dist/utils/makeCall.js +13 -0
  71. data/dist/utils/noIndent.js +11 -0
  72. data/dist/utils/printEmptyCollection.js +44 -0
  73. data/dist/utils/skipAssignIndent.js +15 -0
  74. data/dist/utils.js +30 -0
  75. data/node_modules/prettier/bin-prettier.js +13343 -10961
  76. data/node_modules/prettier/doc.js +4829 -0
  77. data/node_modules/prettier/index.js +24010 -22251
  78. data/node_modules/prettier/package.json +23 -0
  79. data/node_modules/prettier/parser-angular.js +66 -0
  80. data/node_modules/prettier/parser-babel.js +22 -0
  81. data/node_modules/prettier/parser-espree.js +22 -0
  82. data/node_modules/prettier/parser-flow.js +22 -0
  83. data/node_modules/prettier/parser-glimmer.js +1 -0
  84. data/node_modules/prettier/parser-graphql.js +1 -0
  85. data/node_modules/prettier/parser-html.js +132 -0
  86. data/node_modules/prettier/parser-markdown.js +34 -0
  87. data/node_modules/prettier/parser-meriyah.js +22 -0
  88. data/node_modules/prettier/parser-postcss.js +22 -0
  89. data/node_modules/prettier/parser-typescript.js +22 -0
  90. data/node_modules/prettier/parser-yaml.js +15 -0
  91. data/node_modules/prettier/third-party.js +1734 -862
  92. data/package.json +27 -19
  93. data/rubocop.yml +9 -0
  94. metadata +88 -79
  95. data/src/haml/embed.js +0 -87
  96. data/src/haml/nodes/comment.js +0 -27
  97. data/src/haml/nodes/doctype.js +0 -34
  98. data/src/haml/nodes/filter.js +0 -16
  99. data/src/haml/nodes/hamlComment.js +0 -21
  100. data/src/haml/nodes/plain.js +0 -6
  101. data/src/haml/nodes/root.js +0 -8
  102. data/src/haml/nodes/script.js +0 -33
  103. data/src/haml/nodes/silentScript.js +0 -59
  104. data/src/haml/nodes/tag.js +0 -193
  105. data/src/haml/parser.js +0 -22
  106. data/src/haml/printer.js +0 -28
  107. data/src/parser/getLang.js +0 -32
  108. data/src/parser/getNetcat.js +0 -57
  109. data/src/parser/parseSync.js +0 -43
  110. data/src/parser/requestParse.js +0 -74
  111. data/src/parser/server.rb +0 -66
  112. data/src/plugin.js +0 -148
  113. data/src/prettier.js +0 -16
  114. data/src/rbs/parser.js +0 -39
  115. data/src/rbs/printer.js +0 -605
  116. data/src/ruby/embed.js +0 -142
  117. data/src/ruby/nodes/alias.js +0 -73
  118. data/src/ruby/nodes/args.js +0 -178
  119. data/src/ruby/nodes/arrays.js +0 -162
  120. data/src/ruby/nodes/assign.js +0 -47
  121. data/src/ruby/nodes/blocks.js +0 -90
  122. data/src/ruby/nodes/calls.js +0 -199
  123. data/src/ruby/nodes/case.js +0 -65
  124. data/src/ruby/nodes/class.js +0 -64
  125. data/src/ruby/nodes/commands.js +0 -131
  126. data/src/ruby/nodes/conditionals.js +0 -280
  127. data/src/ruby/nodes/constants.js +0 -43
  128. data/src/ruby/nodes/flow.js +0 -74
  129. data/src/ruby/nodes/hashes.js +0 -164
  130. data/src/ruby/nodes/heredocs.js +0 -36
  131. data/src/ruby/nodes/hooks.js +0 -34
  132. data/src/ruby/nodes/ints.js +0 -31
  133. data/src/ruby/nodes/lambdas.js +0 -76
  134. data/src/ruby/nodes/loops.js +0 -98
  135. data/src/ruby/nodes/massign.js +0 -98
  136. data/src/ruby/nodes/methods.js +0 -74
  137. data/src/ruby/nodes/operators.js +0 -83
  138. data/src/ruby/nodes/params.js +0 -113
  139. data/src/ruby/nodes/patterns.js +0 -157
  140. data/src/ruby/nodes/regexp.js +0 -56
  141. data/src/ruby/nodes/rescue.js +0 -101
  142. data/src/ruby/nodes/return.js +0 -94
  143. data/src/ruby/nodes/statements.js +0 -142
  144. data/src/ruby/nodes/strings.js +0 -177
  145. data/src/ruby/nodes/super.js +0 -35
  146. data/src/ruby/nodes/undef.js +0 -42
  147. data/src/ruby/nodes.js +0 -34
  148. data/src/ruby/parser.js +0 -39
  149. data/src/ruby/printer.js +0 -138
  150. data/src/ruby/toProc.js +0 -105
  151. data/src/utils/containsAssignment.js +0 -11
  152. data/src/utils/getTrailingComma.js +0 -5
  153. data/src/utils/hasAncestor.js +0 -17
  154. data/src/utils/isEmptyBodyStmt.js +0 -7
  155. data/src/utils/isEmptyStmts.js +0 -11
  156. data/src/utils/literal.js +0 -7
  157. data/src/utils/literallineWithoutBreakParent.js +0 -7
  158. data/src/utils/makeCall.js +0 -14
  159. data/src/utils/noIndent.js +0 -11
  160. data/src/utils/printEmptyCollection.js +0 -49
  161. data/src/utils/skipAssignIndent.js +0 -10
  162. data/src/utils.js +0 -13
data/package.json CHANGED
@@ -1,36 +1,46 @@
1
1
  {
2
2
  "name": "@prettier/plugin-ruby",
3
- "version": "1.5.4",
3
+ "version": "2.0.0-rc1",
4
4
  "description": "prettier plugin for the Ruby programming language",
5
- "main": "src/plugin.js",
5
+ "main": "dist/plugin.js",
6
6
  "scripts": {
7
- "check-format": "prettier --check '**/*'",
7
+ "checkFormat": "prettier --check '**/*'",
8
8
  "lint": "eslint --cache .",
9
+ "prepublishOnly": "tsc -p tsconfig.build.json && cp src/parser/getInfo.js dist/parser && cp src/parser/netcat.js dist/parser && cp src/parser/server.rb dist/parser && cp src/haml/parser.rb dist/haml && cp src/rbs/parser.rb dist/rbs && cp src/ruby/parser.rb dist/ruby",
9
10
  "test": "jest"
10
11
  },
11
12
  "repository": {
12
13
  "type": "git",
13
14
  "url": "git+https://github.com/prettier/plugin-ruby.git"
14
15
  },
15
- "author": "Kevin Deisz",
16
+ "author": "Kevin Newton",
16
17
  "license": "MIT",
17
18
  "bugs": {
18
19
  "url": "https://github.com/prettier/plugin-ruby/issues"
19
20
  },
20
21
  "homepage": "https://github.com/prettier/plugin-ruby#readme",
21
22
  "dependencies": {
22
- "prettier": ">=1.10"
23
+ "prettier": ">=2.3.0"
23
24
  },
24
25
  "devDependencies": {
26
+ "@types/jest": "^27.0.1",
27
+ "@types/node": "^16.9.1",
28
+ "@types/prettier": "^2.3.2",
29
+ "@typescript-eslint/eslint-plugin": "^4.31.2",
30
+ "@typescript-eslint/parser": "^4.31.2",
25
31
  "eslint": "^7.22.0",
26
32
  "eslint-config-prettier": "^8.0.0",
27
- "husky": "^5.0.9",
28
- "jest": "^26.0.0",
29
- "pretty-quick": "^3.1.0"
33
+ "husky": "^7.0.0",
34
+ "jest": "^27.0.1",
35
+ "pretty-quick": "^3.1.0",
36
+ "ts-jest": "^27.0.5",
37
+ "ts-node": "^10.2.1",
38
+ "typescript": "^4.4.3"
30
39
  },
31
40
  "eslintConfig": {
32
41
  "extends": [
33
42
  "eslint:recommended",
43
+ "plugin:@typescript-eslint/recommended",
34
44
  "prettier"
35
45
  ],
36
46
  "env": {
@@ -38,23 +48,21 @@
38
48
  "jest": true,
39
49
  "node": true
40
50
  },
51
+ "parser": "@typescript-eslint/parser",
41
52
  "rules": {
42
- "no-unused-vars": [
43
- "error",
44
- {
45
- "argsIgnorePattern": "^_",
46
- "varsIgnorePattern": "^_"
47
- }
48
- ]
53
+ "no-unused-vars": "off",
54
+ "@typescript-eslint/explicit-module-boundary-types": "off",
55
+ "@typescript-eslint/no-explicit-any": "off"
49
56
  }
50
57
  },
51
58
  "jest": {
52
- "globalSetup": "./test/js/globalSetup.js",
53
- "globalTeardown": "./test/js/globalTeardown.js",
59
+ "globalSetup": "./test/js/globalSetup.ts",
60
+ "globalTeardown": "./test/js/globalTeardown.ts",
61
+ "preset": "ts-jest",
54
62
  "setupFilesAfterEnv": [
55
- "./test/js/setupTests.js"
63
+ "./test/js/setupTests.ts"
56
64
  ],
57
- "testRegex": ".test.js$"
65
+ "testRegex": ".test.ts$"
58
66
  },
59
67
  "husky": {
60
68
  "hooks": {
data/rubocop.yml CHANGED
@@ -4,6 +4,15 @@
4
4
  Layout:
5
5
  Enabled: false
6
6
 
7
+ # Re-enable Layout/LineLength because certain cops that most projects use
8
+ # (e.g. Style/IfUnlessModifier) require Layout/LineLength to be enabled.
9
+ # By leaving it disabled, those rules will mis-fire.
10
+ #
11
+ # Users can always override these defaults in their own rubocop.yml files.
12
+ # https://github.com/prettier/plugin-ruby/issues/825
13
+ Layout/LineLength:
14
+ Enabled: true
15
+
7
16
  # Disabling all of the following options because they could conflict with a
8
17
  # prettier configuration setting.
9
18
 
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: 1.5.4
4
+ version: 2.0.0.pre.rc1
5
5
  platform: ruby
6
6
  authors:
7
- - Kevin Deisz
7
+ - Kevin Newton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-17 00:00:00.000000000 Z
11
+ date: 2021-09-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -23,88 +23,97 @@ files:
23
23
  - LICENSE
24
24
  - README.md
25
25
  - bin/console
26
+ - dist/haml/embed.js
27
+ - dist/haml/parser.js
28
+ - dist/haml/parser.rb
29
+ - dist/haml/printer.js
30
+ - dist/parser/getInfo.js
31
+ - dist/parser/netcat.js
32
+ - dist/parser/parseSync.js
33
+ - dist/parser/server.rb
34
+ - dist/plugin.js
35
+ - dist/prettier.js
36
+ - dist/rbs/parser.js
37
+ - dist/rbs/parser.rb
38
+ - dist/rbs/printer.js
39
+ - dist/ruby/embed.js
40
+ - dist/ruby/nodes.js
41
+ - dist/ruby/nodes/alias.js
42
+ - dist/ruby/nodes/aref.js
43
+ - dist/ruby/nodes/args.js
44
+ - dist/ruby/nodes/arrays.js
45
+ - dist/ruby/nodes/assign.js
46
+ - dist/ruby/nodes/blocks.js
47
+ - dist/ruby/nodes/calls.js
48
+ - dist/ruby/nodes/case.js
49
+ - dist/ruby/nodes/class.js
50
+ - dist/ruby/nodes/commands.js
51
+ - dist/ruby/nodes/conditionals.js
52
+ - dist/ruby/nodes/constants.js
53
+ - dist/ruby/nodes/flow.js
54
+ - dist/ruby/nodes/hashes.js
55
+ - dist/ruby/nodes/heredocs.js
56
+ - dist/ruby/nodes/hooks.js
57
+ - dist/ruby/nodes/ints.js
58
+ - dist/ruby/nodes/lambdas.js
59
+ - dist/ruby/nodes/loops.js
60
+ - dist/ruby/nodes/massign.js
61
+ - dist/ruby/nodes/methods.js
62
+ - dist/ruby/nodes/operators.js
63
+ - dist/ruby/nodes/params.js
64
+ - dist/ruby/nodes/patterns.js
65
+ - dist/ruby/nodes/regexp.js
66
+ - dist/ruby/nodes/rescue.js
67
+ - dist/ruby/nodes/return.js
68
+ - dist/ruby/nodes/statements.js
69
+ - dist/ruby/nodes/strings.js
70
+ - dist/ruby/nodes/super.js
71
+ - dist/ruby/nodes/undef.js
72
+ - dist/ruby/parser.js
73
+ - dist/ruby/parser.rb
74
+ - dist/ruby/printer.js
75
+ - dist/ruby/toProc.js
76
+ - dist/types.js
77
+ - dist/types/haml.js
78
+ - dist/types/plugin.js
79
+ - dist/types/rbs.js
80
+ - dist/types/ruby.js
81
+ - dist/types/utils.js
82
+ - dist/utils.js
83
+ - dist/utils/containsAssignment.js
84
+ - dist/utils/getTrailingComma.js
85
+ - dist/utils/hasAncestor.js
86
+ - dist/utils/inlineEnsureParens.js
87
+ - dist/utils/isEmptyBodyStmt.js
88
+ - dist/utils/isEmptyStmts.js
89
+ - dist/utils/literal.js
90
+ - dist/utils/literallineWithoutBreakParent.js
91
+ - dist/utils/makeCall.js
92
+ - dist/utils/noIndent.js
93
+ - dist/utils/printEmptyCollection.js
94
+ - dist/utils/skipAssignIndent.js
26
95
  - exe/rbprettier
27
96
  - lib/prettier.rb
28
97
  - lib/prettier/rake/task.rb
29
98
  - node_modules/prettier/bin-prettier.js
99
+ - node_modules/prettier/doc.js
30
100
  - node_modules/prettier/index.js
101
+ - node_modules/prettier/package.json
102
+ - node_modules/prettier/parser-angular.js
103
+ - node_modules/prettier/parser-babel.js
104
+ - node_modules/prettier/parser-espree.js
105
+ - node_modules/prettier/parser-flow.js
106
+ - node_modules/prettier/parser-glimmer.js
107
+ - node_modules/prettier/parser-graphql.js
108
+ - node_modules/prettier/parser-html.js
109
+ - node_modules/prettier/parser-markdown.js
110
+ - node_modules/prettier/parser-meriyah.js
111
+ - node_modules/prettier/parser-postcss.js
112
+ - node_modules/prettier/parser-typescript.js
113
+ - node_modules/prettier/parser-yaml.js
31
114
  - node_modules/prettier/third-party.js
32
115
  - package.json
33
116
  - rubocop.yml
34
- - src/haml/embed.js
35
- - src/haml/nodes/comment.js
36
- - src/haml/nodes/doctype.js
37
- - src/haml/nodes/filter.js
38
- - src/haml/nodes/hamlComment.js
39
- - src/haml/nodes/plain.js
40
- - src/haml/nodes/root.js
41
- - src/haml/nodes/script.js
42
- - src/haml/nodes/silentScript.js
43
- - src/haml/nodes/tag.js
44
- - src/haml/parser.js
45
- - src/haml/parser.rb
46
- - src/haml/printer.js
47
- - src/parser/getLang.js
48
- - src/parser/getNetcat.js
49
- - src/parser/netcat.js
50
- - src/parser/parseSync.js
51
- - src/parser/requestParse.js
52
- - src/parser/server.rb
53
- - src/plugin.js
54
- - src/prettier.js
55
- - src/rbs/parser.js
56
- - src/rbs/parser.rb
57
- - src/rbs/printer.js
58
- - src/ruby/embed.js
59
- - src/ruby/nodes.js
60
- - src/ruby/nodes/alias.js
61
- - src/ruby/nodes/aref.js
62
- - src/ruby/nodes/args.js
63
- - src/ruby/nodes/arrays.js
64
- - src/ruby/nodes/assign.js
65
- - src/ruby/nodes/blocks.js
66
- - src/ruby/nodes/calls.js
67
- - src/ruby/nodes/case.js
68
- - src/ruby/nodes/class.js
69
- - src/ruby/nodes/commands.js
70
- - src/ruby/nodes/conditionals.js
71
- - src/ruby/nodes/constants.js
72
- - src/ruby/nodes/flow.js
73
- - src/ruby/nodes/hashes.js
74
- - src/ruby/nodes/heredocs.js
75
- - src/ruby/nodes/hooks.js
76
- - src/ruby/nodes/ints.js
77
- - src/ruby/nodes/lambdas.js
78
- - src/ruby/nodes/loops.js
79
- - src/ruby/nodes/massign.js
80
- - src/ruby/nodes/methods.js
81
- - src/ruby/nodes/operators.js
82
- - src/ruby/nodes/params.js
83
- - src/ruby/nodes/patterns.js
84
- - src/ruby/nodes/regexp.js
85
- - src/ruby/nodes/rescue.js
86
- - src/ruby/nodes/return.js
87
- - src/ruby/nodes/statements.js
88
- - src/ruby/nodes/strings.js
89
- - src/ruby/nodes/super.js
90
- - src/ruby/nodes/undef.js
91
- - src/ruby/parser.js
92
- - src/ruby/parser.rb
93
- - src/ruby/printer.js
94
- - src/ruby/toProc.js
95
- - src/utils.js
96
- - src/utils/containsAssignment.js
97
- - src/utils/getTrailingComma.js
98
- - src/utils/hasAncestor.js
99
- - src/utils/inlineEnsureParens.js
100
- - src/utils/isEmptyBodyStmt.js
101
- - src/utils/isEmptyStmts.js
102
- - src/utils/literal.js
103
- - src/utils/literallineWithoutBreakParent.js
104
- - src/utils/makeCall.js
105
- - src/utils/noIndent.js
106
- - src/utils/printEmptyCollection.js
107
- - src/utils/skipAssignIndent.js
108
117
  homepage: https://github.com/prettier/plugin-ruby#readme
109
118
  licenses:
110
119
  - MIT
@@ -120,9 +129,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
129
  version: '0'
121
130
  required_rubygems_version: !ruby/object:Gem::Requirement
122
131
  requirements:
123
- - - ">="
132
+ - - ">"
124
133
  - !ruby/object:Gem::Version
125
- version: '0'
134
+ version: 1.3.1
126
135
  requirements: []
127
136
  rubygems_version: 3.2.3
128
137
  signing_key:
data/src/haml/embed.js DELETED
@@ -1,87 +0,0 @@
1
- const {
2
- concat,
3
- hardline,
4
- indent,
5
- literalline,
6
- markAsRoot,
7
- mapDoc,
8
- stripTrailingHardline
9
- } = require("../prettier");
10
-
11
- // Get the name of the parser that is represented by the given element node,
12
- // return null if a matching parser cannot be found
13
- function getParser(name, opts) {
14
- let parser = name;
15
-
16
- // We don't want to deal with some weird recursive parser situation, so we
17
- // need to explicitly call out the HAML parser here and just return null
18
- if (parser === "haml") {
19
- return null;
20
- }
21
-
22
- // In HAML the name of the JS filter is :javascript, whereas in prettier the
23
- // name of the JS parser is babel. Here we explicitly handle that conversion.
24
- if (parser === "javascript") {
25
- parser = "babel";
26
- }
27
-
28
- // If there is a plugin that has a parser that matches the name of this
29
- // element, then we're going to assume that's correct for embedding and go
30
- // ahead and switch to that parser
31
- if (
32
- opts.plugins.some(
33
- (plugin) =>
34
- plugin.parsers &&
35
- Object.prototype.hasOwnProperty.call(plugin.parsers, parser)
36
- )
37
- ) {
38
- return parser;
39
- }
40
-
41
- return null;
42
- }
43
-
44
- // This function is in here because it handles embedded parser values. I don't
45
- // have a test that exercises it because I'm not sure for which parser it is
46
- // necessary, but since it's in prettier core I'm keeping it here.
47
- /* istanbul ignore next */
48
- function replaceNewlines(doc) {
49
- return mapDoc(doc, (currentDoc) =>
50
- typeof currentDoc === "string" && currentDoc.includes("\n")
51
- ? concat(
52
- currentDoc
53
- .split(/(\n)/g)
54
- .map((v, i) => (i % 2 === 0 ? v : literalline))
55
- )
56
- : currentDoc
57
- );
58
- }
59
-
60
- function embed(path, _print, textToDoc, opts) {
61
- const node = path.getValue();
62
- if (node.type !== "filter") {
63
- return null;
64
- }
65
-
66
- const parser = getParser(node.value.name, opts);
67
- if (!parser) {
68
- return null;
69
- }
70
-
71
- return markAsRoot(
72
- concat([
73
- ":",
74
- node.value.name,
75
- indent(
76
- concat([
77
- hardline,
78
- replaceNewlines(
79
- stripTrailingHardline(textToDoc(node.value.text, { parser }))
80
- )
81
- ])
82
- )
83
- ])
84
- );
85
- }
86
-
87
- module.exports = embed;
@@ -1,27 +0,0 @@
1
- const { concat, group, hardline, indent, join } = require("../../prettier");
2
-
3
- // https://haml.info/docs/yardoc/file.REFERENCE.html#html-comments-
4
- function 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,34 +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
- // https://haml.info/docs/yardoc/file.REFERENCE.html#doctype-
15
- function 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 (versions.includes(value.version)) {
22
- parts.push(value.version);
23
- } else {
24
- parts.push(value.type);
25
- }
26
-
27
- if (value.encoding) {
28
- parts.push(value.encoding);
29
- }
30
-
31
- return join(" ", parts);
32
- }
33
-
34
- module.exports = doctype;
@@ -1,16 +0,0 @@
1
- const { concat, group, hardline, indent, join } = require("../../prettier");
2
-
3
- // https://haml.info/docs/yardoc/file.REFERENCE.html#filters
4
- function 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
- // https://haml.info/docs/yardoc/file.REFERENCE.html#haml-comments--
4
- function 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,6 +0,0 @@
1
- // https://haml.info/docs/yardoc/file.REFERENCE.html#plain-text
2
- function plain(path, _opts, _print) {
3
- return path.getValue().value.text;
4
- }
5
-
6
- module.exports = plain;
@@ -1,8 +0,0 @@
1
- const { concat, hardline, join } = require("../../prettier");
2
-
3
- // The root node in the AST
4
- function root(path, _opts, print) {
5
- return concat([join(hardline, path.map(print, "children")), hardline]);
6
- }
7
-
8
- module.exports = root;
@@ -1,33 +0,0 @@
1
- const { concat, group, hardline, indent, join } = require("../../prettier");
2
-
3
- // https://haml.info/docs/yardoc/file.REFERENCE.html#inserting_ruby
4
- function 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
- if (value.escape_html && !value.preserve && value.interpolate) {
19
- parts.push(" ", value.text.trim().slice(1, -1));
20
- } else {
21
- parts.push(" ", value.text.trim());
22
- }
23
-
24
- if (children.length > 0) {
25
- parts.push(
26
- indent(concat([hardline, join(hardline, path.map(print, "children"))]))
27
- );
28
- }
29
-
30
- return group(concat(parts));
31
- }
32
-
33
- module.exports = script;
@@ -1,59 +0,0 @@
1
- const { concat, group, hardline, indent, join } = require("../../prettier");
2
-
3
- function 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
- // https://haml.info/docs/yardoc/file.REFERENCE.html#running-ruby--
20
- function 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;