prettier 2.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +52 -6
  3. data/README.md +17 -16
  4. data/exe/rbprettier +2 -2
  5. data/lib/prettier/rake/task.rb +5 -5
  6. data/lib/prettier.rb +12 -11
  7. data/node_modules/prettier/bin-prettier.js +48 -18924
  8. data/node_modules/prettier/cli.js +12335 -0
  9. data/node_modules/prettier/doc.js +1306 -4755
  10. data/node_modules/prettier/index.js +37468 -57614
  11. data/node_modules/prettier/package.json +3 -2
  12. data/node_modules/prettier/parser-angular.js +2 -66
  13. data/node_modules/prettier/parser-babel.js +27 -22
  14. data/node_modules/prettier/parser-espree.js +26 -22
  15. data/node_modules/prettier/parser-flow.js +26 -22
  16. data/node_modules/prettier/parser-glimmer.js +27 -1
  17. data/node_modules/prettier/parser-graphql.js +15 -1
  18. data/node_modules/prettier/parser-html.js +21 -117
  19. data/node_modules/prettier/parser-markdown.js +61 -19
  20. data/node_modules/prettier/parser-meriyah.js +19 -22
  21. data/node_modules/prettier/parser-postcss.js +76 -22
  22. data/node_modules/prettier/parser-typescript.js +280 -22
  23. data/node_modules/prettier/parser-yaml.js +150 -15
  24. data/node_modules/prettier/third-party.js +8660 -11030
  25. data/package.json +11 -25
  26. data/rubocop.yml +6 -6
  27. data/src/getInfo.js +23 -0
  28. data/{dist/parser → src}/netcat.js +0 -1
  29. data/src/parseSync.js +216 -0
  30. data/src/plugin.js +170 -0
  31. data/{dist/parser → src}/server.rb +50 -27
  32. metadata +95 -75
  33. data/bin/console +0 -7
  34. data/dist/haml/embed.js +0 -53
  35. data/dist/haml/parser.js +0 -31
  36. data/dist/haml/parser.rb +0 -143
  37. data/dist/haml/printer.js +0 -336
  38. data/dist/parser/getInfo.js +0 -17
  39. data/dist/parser/parseSync.js +0 -179
  40. data/dist/plugin.js +0 -143
  41. data/dist/prettier.js +0 -15
  42. data/dist/rbs/parser.js +0 -34
  43. data/dist/rbs/parser.rb +0 -98
  44. data/dist/rbs/printer.js +0 -517
  45. data/dist/ruby/embed.js +0 -110
  46. data/dist/ruby/nodes/alias.js +0 -59
  47. data/dist/ruby/nodes/aref.js +0 -53
  48. data/dist/ruby/nodes/args.js +0 -165
  49. data/dist/ruby/nodes/arrays.js +0 -126
  50. data/dist/ruby/nodes/assign.js +0 -41
  51. data/dist/ruby/nodes/blocks.js +0 -87
  52. data/dist/ruby/nodes/calls.js +0 -260
  53. data/dist/ruby/nodes/case.js +0 -50
  54. data/dist/ruby/nodes/class.js +0 -54
  55. data/dist/ruby/nodes/commands.js +0 -124
  56. data/dist/ruby/nodes/conditionals.js +0 -242
  57. data/dist/ruby/nodes/constants.js +0 -38
  58. data/dist/ruby/nodes/flow.js +0 -66
  59. data/dist/ruby/nodes/hashes.js +0 -130
  60. data/dist/ruby/nodes/heredocs.js +0 -30
  61. data/dist/ruby/nodes/hooks.js +0 -35
  62. data/dist/ruby/nodes/ints.js +0 -27
  63. data/dist/ruby/nodes/lambdas.js +0 -69
  64. data/dist/ruby/nodes/loops.js +0 -73
  65. data/dist/ruby/nodes/massign.js +0 -73
  66. data/dist/ruby/nodes/methods.js +0 -70
  67. data/dist/ruby/nodes/operators.js +0 -70
  68. data/dist/ruby/nodes/params.js +0 -89
  69. data/dist/ruby/nodes/patterns.js +0 -122
  70. data/dist/ruby/nodes/regexp.js +0 -45
  71. data/dist/ruby/nodes/rescue.js +0 -85
  72. data/dist/ruby/nodes/return.js +0 -75
  73. data/dist/ruby/nodes/statements.js +0 -111
  74. data/dist/ruby/nodes/strings.js +0 -218
  75. data/dist/ruby/nodes/super.js +0 -30
  76. data/dist/ruby/nodes/undef.js +0 -26
  77. data/dist/ruby/nodes.js +0 -151
  78. data/dist/ruby/parser.js +0 -34
  79. data/dist/ruby/parser.rb +0 -3636
  80. data/dist/ruby/printer.js +0 -129
  81. data/dist/ruby/toProc.js +0 -93
  82. data/dist/types/haml.js +0 -4
  83. data/dist/types/plugin.js +0 -3
  84. data/dist/types/rbs.js +0 -4
  85. data/dist/types/ruby.js +0 -4
  86. data/dist/types/utils.js +0 -2
  87. data/dist/types.js +0 -30
  88. data/dist/utils/containsAssignment.js +0 -15
  89. data/dist/utils/getTrailingComma.js +0 -6
  90. data/dist/utils/hasAncestor.js +0 -15
  91. data/dist/utils/inlineEnsureParens.js +0 -49
  92. data/dist/utils/isEmptyBodyStmt.js +0 -10
  93. data/dist/utils/isEmptyStmts.js +0 -10
  94. data/dist/utils/literal.js +0 -8
  95. data/dist/utils/literallineWithoutBreakParent.js +0 -8
  96. data/dist/utils/makeCall.js +0 -13
  97. data/dist/utils/noIndent.js +0 -11
  98. data/dist/utils/printEmptyCollection.js +0 -44
  99. data/dist/utils/skipAssignIndent.js +0 -15
  100. data/dist/utils.js +0 -30
metadata CHANGED
@@ -1,15 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prettier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Newton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-28 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: syntax_tree
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: syntax_tree-haml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: syntax_tree-rbs
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
13
97
  description:
14
98
  email:
15
99
  executables:
@@ -22,80 +106,11 @@ files:
22
106
  - CONTRIBUTING.md
23
107
  - LICENSE
24
108
  - README.md
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
95
109
  - exe/rbprettier
96
110
  - lib/prettier.rb
97
111
  - lib/prettier/rake/task.rb
98
112
  - node_modules/prettier/bin-prettier.js
113
+ - node_modules/prettier/cli.js
99
114
  - node_modules/prettier/doc.js
100
115
  - node_modules/prettier/index.js
101
116
  - node_modules/prettier/package.json
@@ -114,6 +129,11 @@ files:
114
129
  - node_modules/prettier/third-party.js
115
130
  - package.json
116
131
  - rubocop.yml
132
+ - src/getInfo.js
133
+ - src/netcat.js
134
+ - src/parseSync.js
135
+ - src/plugin.js
136
+ - src/server.rb
117
137
  homepage: https://github.com/prettier/plugin-ruby#readme
118
138
  licenses:
119
139
  - MIT
@@ -126,14 +146,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
146
  requirements:
127
147
  - - ">="
128
148
  - !ruby/object:Gem::Version
129
- version: '0'
149
+ version: 2.7.3
130
150
  required_rubygems_version: !ruby/object:Gem::Requirement
131
151
  requirements:
132
152
  - - ">="
133
153
  - !ruby/object:Gem::Version
134
154
  version: '0'
135
155
  requirements: []
136
- rubygems_version: 3.2.3
156
+ rubygems_version: 3.4.0.dev
137
157
  signing_key:
138
158
  specification_version: 4
139
159
  summary: prettier plugin for the Ruby programming language
data/bin/console DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'prettier'
5
-
6
- require 'irb'
7
- IRB.start(__FILE__)
data/dist/haml/embed.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const prettier_1 = __importDefault(require("../prettier"));
7
- const { hardline, indent, literalline, markAsRoot, mapDoc, stripTrailingHardline } = prettier_1.default;
8
- // This function is in here because it handles embedded parser values. I don't
9
- // have a test that exercises it because I'm not sure for which parser it is
10
- // necessary, but since it's in prettier core I'm keeping it here.
11
- /* istanbul ignore next */
12
- function replaceNewlines(doc) {
13
- return mapDoc(doc, (currentDoc) => typeof currentDoc === "string" && currentDoc.includes("\n")
14
- ? currentDoc.split(/(\n)/g).map((v, i) => (i % 2 === 0 ? v : literalline))
15
- : currentDoc);
16
- }
17
- const embed = (path, _print, textToDoc, opts) => {
18
- const node = path.getValue();
19
- // We're only going to embed other languages on filter nodes.
20
- if (node.type !== "filter") {
21
- return null;
22
- }
23
- let parser = node.value.name;
24
- // We don't want to deal with some weird recursive parser situation, so we
25
- // need to explicitly call out the HAML parser here and just return null.
26
- if (parser === "haml") {
27
- return null;
28
- }
29
- // In HAML the name of the JS filter is :javascript, whereas in prettier the
30
- // name of the JS parser is babel. Here we explicitly handle that conversion.
31
- if (parser === "javascript") {
32
- parser = "babel";
33
- }
34
- // If there aren't any plugins that look like the name of the filter, then we
35
- // will just exit early.
36
- if (!opts.plugins.some((plugin) => typeof plugin !== "string" &&
37
- plugin.parsers &&
38
- Object.prototype.hasOwnProperty.call(plugin.parsers, parser))) {
39
- return null;
40
- }
41
- // If there is a plugin that has a parser that matches the name of this
42
- // filter, then we're going to assume that's correct for embedding and go
43
- // ahead and switch to that parser.
44
- return markAsRoot([
45
- ":",
46
- node.value.name,
47
- indent([
48
- hardline,
49
- replaceNewlines(stripTrailingHardline(textToDoc(node.value.text, { parser })))
50
- ])
51
- ]);
52
- };
53
- exports.default = embed;
data/dist/haml/parser.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const parseSync_1 = __importDefault(require("../parser/parseSync"));
7
- const parser = {
8
- // This function is responsible for taking an input string of text and
9
- // returning to prettier a JavaScript object that is the equivalent AST that
10
- // represents the code stored in that string. We accomplish this by spawning a
11
- // new process and reading JSON off STDOUT.
12
- parse(text) {
13
- return (0, parseSync_1.default)("haml", text);
14
- },
15
- astFormat: "haml",
16
- // This function handles checking whether or not the source string has the
17
- // pragma for prettier. This is an optional workflow for incremental adoption.
18
- hasPragma(text) {
19
- return /^\s*-#\s*@(prettier|format)/.test(text);
20
- },
21
- // These functions are just placeholders until we can actually perform this
22
- // properly. The functions are necessary otherwise the format with cursor
23
- // functions break.
24
- locStart() {
25
- return 0;
26
- },
27
- locEnd() {
28
- return 0;
29
- }
30
- };
31
- exports.default = parser;
data/dist/haml/parser.rb DELETED
@@ -1,143 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ripper'
4
-
5
- begin
6
- require 'haml'
7
- rescue LoadError
8
- # If we can't load the haml gem, then we're going to provide a shim parser
9
- # that will warn and bail out.
10
- class Prettier::HAMLParser
11
- def self.parse(text)
12
- warn(
13
- 'The `haml` gem could not be loaded. Please ensure you have it ' \
14
- 'installed and that it is available in the gem path.'
15
- )
16
-
17
- false
18
- end
19
- end
20
-
21
- return
22
- end
23
-
24
- class Haml::Parser::ParseNode
25
- class DeepAttributeParser
26
- def parse(string)
27
- Haml::AttributeParser.available? ? parse_value(string) : string
28
- end
29
-
30
- private
31
-
32
- def literal(string, level)
33
- level == 0 ? string : "&#{string}"
34
- end
35
-
36
- def parse_value(string, level = 0)
37
- response = Ripper.sexp(string)
38
- return literal(string, level) unless response
39
-
40
- case response[1][0][0]
41
- when :hash
42
- hash = Haml::AttributeParser.parse(string)
43
-
44
- if hash
45
- # Explicitly not using Enumerable#to_h here to support Ruby 2.5
46
- hash.each_with_object({}) do |(key, value), response|
47
- response[key] = parse_value(value, level + 1)
48
- end
49
- else
50
- literal(string, level)
51
- end
52
- when :string_literal
53
- string[1...-1]
54
- else
55
- literal(string, level)
56
- end
57
- end
58
- end
59
-
60
- ESCAPE = /Haml::Helpers.html_escape\(\((.+)\)\)/.freeze
61
-
62
- # If a node comes in as the plain type but starts with one of the special
63
- # characters that haml parses, then we need to escape it with a \ when
64
- # printing. So here we make a regexp pattern to check if the node needs to be
65
- # escaped.
66
- special_chars =
67
- Haml::Parser::SPECIAL_CHARACTERS.map { |char| Regexp.escape(char) }
68
-
69
- SPECIAL_START = /\A(?:#{special_chars.join('|')})/
70
-
71
- def as_json
72
- case type
73
- when :comment, :doctype, :silent_script
74
- to_h.tap do |json|
75
- json.delete(:parent)
76
- json[:children] = children.map(&:as_json)
77
- end
78
- when :filter, :haml_comment
79
- to_h.tap { |json| json.delete(:parent) }
80
- when :plain
81
- to_h.tap do |json|
82
- json.delete(:parent)
83
- json[:children] = children.map(&:as_json)
84
-
85
- text = json[:value][:text]
86
- json[:value][:text] = "\\#{text}" if text.match?(SPECIAL_START)
87
- end
88
- when :root
89
- to_h.tap do |json|
90
- json[:children] = children.map(&:as_json)
91
-
92
- # We need this information in the printer to know how to lay out
93
- # multi-line attributes.
94
- json[:supports_multiline] =
95
- Gem::Version.new(Haml::VERSION) >= Gem::Version.new('5.2')
96
- end
97
- when :script
98
- to_h.tap do |json|
99
- json.delete(:parent)
100
- json[:children] = children.map(&:as_json)
101
-
102
- if json[:value][:text].match?(ESCAPE)
103
- json[:value][:text].gsub!(ESCAPE) { $1 }
104
- json[:value].merge!(escape_html: 'escape_html', interpolate: true)
105
- end
106
- end
107
- when :tag
108
- to_h.tap do |json|
109
- json.delete(:parent)
110
-
111
- # For some reason this is actually using a symbol to represent a null
112
- # object ref instead of nil itself, so just replacing it here for
113
- # simplicity in the printer
114
- json[:value][:object_ref] = nil if json[:value][:object_ref] == :nil
115
-
116
- # Get a reference to the dynamic attributes hash
117
- dynamic_attributes = value[:dynamic_attributes].to_h
118
-
119
- # If we have any in the old style, then we're going to pass it through
120
- # the deep attribute parser filter.
121
- if dynamic_attributes[:old]
122
- dynamic_attributes[:old] =
123
- DeepAttributeParser.new.parse(dynamic_attributes[:old])
124
- end
125
-
126
- json.merge!(
127
- children: children.map(&:as_json),
128
- value: value.merge(dynamic_attributes: dynamic_attributes)
129
- )
130
- end
131
- else
132
- raise ArgumentError, "Unsupported type: #{type}"
133
- end
134
- end
135
- end
136
-
137
- module Prettier
138
- class HAMLParser
139
- def self.parse(source)
140
- Haml::Parser.new({}).call(source).as_json
141
- end
142
- end
143
- end