prettier 1.5.5 → 2.0.0.pre.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +344 -282
  3. data/CONTRIBUTING.md +8 -11
  4. data/LICENSE +1 -1
  5. data/README.md +30 -12
  6. data/dist/haml/embed.js +53 -0
  7. data/dist/haml/parser.js +31 -0
  8. data/{src → dist}/haml/parser.rb +0 -0
  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 +142 -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 +0 -0
  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 +260 -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 +1274 -288
  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 +23988 -22229
  78. data/node_modules/prettier/package.json +23 -0
  79. data/node_modules/prettier/parser-angular.js +60 -40
  80. data/node_modules/prettier/parser-babel.js +22 -1
  81. data/node_modules/prettier/parser-espree.js +22 -1
  82. data/node_modules/prettier/parser-flow.js +22 -1
  83. data/node_modules/prettier/parser-glimmer.js +1 -1
  84. data/node_modules/prettier/parser-graphql.js +1 -1
  85. data/node_modules/prettier/parser-html.js +82 -63
  86. data/node_modules/prettier/parser-markdown.js +24 -9
  87. data/node_modules/prettier/parser-meriyah.js +22 -1
  88. data/node_modules/prettier/parser-postcss.js +22 -1
  89. data/node_modules/prettier/parser-typescript.js +22 -1
  90. data/node_modules/prettier/parser-yaml.js +2 -2
  91. data/node_modules/prettier/third-party.js +1734 -862
  92. data/package.json +27 -19
  93. data/rubocop.yml +9 -0
  94. metadata +77 -77
  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 -232
  105. data/src/haml/parser.js +0 -22
  106. data/src/haml/printer.js +0 -28
  107. data/src/parser/parseSync.js +0 -170
  108. data/src/parser/server.rb +0 -66
  109. data/src/plugin.js +0 -148
  110. data/src/prettier.js +0 -16
  111. data/src/rbs/parser.js +0 -39
  112. data/src/rbs/printer.js +0 -615
  113. data/src/ruby/embed.js +0 -142
  114. data/src/ruby/nodes/alias.js +0 -73
  115. data/src/ruby/nodes/args.js +0 -178
  116. data/src/ruby/nodes/arrays.js +0 -162
  117. data/src/ruby/nodes/assign.js +0 -47
  118. data/src/ruby/nodes/blocks.js +0 -90
  119. data/src/ruby/nodes/calls.js +0 -199
  120. data/src/ruby/nodes/case.js +0 -65
  121. data/src/ruby/nodes/class.js +0 -64
  122. data/src/ruby/nodes/commands.js +0 -131
  123. data/src/ruby/nodes/conditionals.js +0 -280
  124. data/src/ruby/nodes/constants.js +0 -43
  125. data/src/ruby/nodes/flow.js +0 -74
  126. data/src/ruby/nodes/hashes.js +0 -164
  127. data/src/ruby/nodes/heredocs.js +0 -36
  128. data/src/ruby/nodes/hooks.js +0 -34
  129. data/src/ruby/nodes/ints.js +0 -31
  130. data/src/ruby/nodes/lambdas.js +0 -76
  131. data/src/ruby/nodes/loops.js +0 -98
  132. data/src/ruby/nodes/massign.js +0 -98
  133. data/src/ruby/nodes/methods.js +0 -74
  134. data/src/ruby/nodes/operators.js +0 -83
  135. data/src/ruby/nodes/params.js +0 -113
  136. data/src/ruby/nodes/patterns.js +0 -157
  137. data/src/ruby/nodes/regexp.js +0 -56
  138. data/src/ruby/nodes/rescue.js +0 -101
  139. data/src/ruby/nodes/return.js +0 -94
  140. data/src/ruby/nodes/statements.js +0 -142
  141. data/src/ruby/nodes/strings.js +0 -177
  142. data/src/ruby/nodes/super.js +0 -35
  143. data/src/ruby/nodes/undef.js +0 -42
  144. data/src/ruby/nodes.js +0 -34
  145. data/src/ruby/parser.js +0 -39
  146. data/src/ruby/printer.js +0 -138
  147. data/src/ruby/toProc.js +0 -105
  148. data/src/utils/containsAssignment.js +0 -11
  149. data/src/utils/getTrailingComma.js +0 -5
  150. data/src/utils/hasAncestor.js +0 -17
  151. data/src/utils/isEmptyBodyStmt.js +0 -7
  152. data/src/utils/isEmptyStmts.js +0 -11
  153. data/src/utils/literal.js +0 -7
  154. data/src/utils/literallineWithoutBreakParent.js +0 -7
  155. data/src/utils/makeCall.js +0 -14
  156. data/src/utils/noIndent.js +0 -11
  157. data/src/utils/printEmptyCollection.js +0 -49
  158. data/src/utils/skipAssignIndent.js +0 -10
  159. data/src/utils.js +0 -13
@@ -0,0 +1,142 @@
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
+ exports.getInfoFilepath = exports.getLang = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const fs_1 = require("fs");
9
+ const os_1 = __importDefault(require("os"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const process_1 = __importDefault(require("process"));
12
+ let parserArgs;
13
+ if (process_1.default.env.PRETTIER_RUBY_HOST) {
14
+ const [cmd, ...args] = process_1.default.env.PRETTIER_RUBY_HOST.split(" ");
15
+ parserArgs = { cmd, args };
16
+ }
17
+ // In order to properly parse ruby code, we need to tell the ruby process to
18
+ // parse using UTF-8. Unfortunately, the way that you accomplish this looks
19
+ // differently depending on your platform.
20
+ /* istanbul ignore next */
21
+ function getLang() {
22
+ const { env, platform } = process_1.default;
23
+ const envValue = env.LC_ALL || env.LC_CTYPE || env.LANG;
24
+ // If an env var is set for the locale that already includes UTF-8 in the
25
+ // name, then assume we can go with that.
26
+ if (envValue && envValue.includes("UTF-8")) {
27
+ return envValue;
28
+ }
29
+ // Otherwise, we're going to guess which encoding to use based on the system.
30
+ // This is probably not the best approach in the world, as you could be on
31
+ // linux and not have C.UTF-8, but in that case you're probably passing an env
32
+ // var for it. This object below represents all of the possible values of
33
+ // process.platform per:
34
+ // https://nodejs.org/api/process.html#process_process_platform
35
+ return {
36
+ aix: "C.UTF-8",
37
+ android: "C.UTF-8",
38
+ cygwin: "C.UTF-8",
39
+ darwin: "en_US.UTF-8",
40
+ freebsd: "C.UTF-8",
41
+ haiku: "C.UTF-8",
42
+ linux: "C.UTF-8",
43
+ netbsd: "C.UTF-8",
44
+ openbsd: "C.UTF-8",
45
+ sunos: "C.UTF-8",
46
+ win32: ".UTF-8"
47
+ }[platform];
48
+ }
49
+ exports.getLang = getLang;
50
+ // Generate the filepath that should be used to communicate the connection
51
+ // information between this process and the parser server.
52
+ function getInfoFilepath() {
53
+ return path_1.default.join(os_1.default.tmpdir(), `prettier-ruby-parser-${process_1.default.pid}.info`);
54
+ }
55
+ exports.getInfoFilepath = getInfoFilepath;
56
+ // Create a file that will act as a communication mechanism, spawn a parser
57
+ // server with that filepath as an argument, then spawn another process that
58
+ // will read that information in order to enable us to connect to it in the
59
+ // spawnSync function.
60
+ function spawnServer() {
61
+ const filepath = getInfoFilepath();
62
+ const server = (0, child_process_1.spawn)("ruby", [path_1.default.join(__dirname, "./server.rb"), filepath], {
63
+ env: Object.assign({}, process_1.default.env, { LANG: getLang() }),
64
+ detached: true,
65
+ stdio: "inherit"
66
+ });
67
+ server.unref();
68
+ process_1.default.on("exit", () => {
69
+ if ((0, fs_1.existsSync)(filepath)) {
70
+ (0, fs_1.unlinkSync)(filepath);
71
+ }
72
+ try {
73
+ if (server.pid) {
74
+ process_1.default.kill(-server.pid);
75
+ }
76
+ }
77
+ catch (e) {
78
+ if (process_1.default.env.PLUGIN_RUBY_CI) {
79
+ throw new Error(`Failed to kill the parser server: ${e}`);
80
+ }
81
+ }
82
+ });
83
+ const info = (0, child_process_1.spawnSync)("node", [
84
+ path_1.default.join(__dirname, "./getInfo.js"),
85
+ filepath
86
+ ]);
87
+ if (info.status !== 0) {
88
+ throw new Error(`
89
+ We failed to spawn our parser server. Please report this error on GitHub
90
+ at https://github.com/prettier/plugin-ruby. The error message was:
91
+
92
+ ${info.stderr.toString()}.
93
+ `);
94
+ }
95
+ const [cmd, ...args] = info.stdout.toString().split(" ");
96
+ return { cmd, args };
97
+ }
98
+ // If we're in a yarn Plug'n'Play environment, then the relative paths being
99
+ // used by the parser server and the various scripts used to communicate
100
+ // therein are not going to work with its virtual file system. Presumably
101
+ // there's a way to fix this but I haven't figured out how yet.
102
+ function checkPnP() {
103
+ if (process_1.default.versions.pnp) {
104
+ throw new Error(`
105
+ @prettier/plugin-ruby does not current work within the yarn Plug'n'Play
106
+ virtual file system. If you would like to help support the effort to fix
107
+ this, please see https://github.com/prettier/plugin-ruby/issues/894.
108
+ `);
109
+ }
110
+ }
111
+ // Formats and sends a request to the parser server. We use netcat (or something
112
+ // like it) here since Prettier requires the results of `parse` to be
113
+ // synchronous and Node.js does not offer a mechanism for synchronous socket
114
+ // requests.
115
+ function parseSync(parser, source) {
116
+ if (!parserArgs) {
117
+ checkPnP();
118
+ parserArgs = spawnServer();
119
+ }
120
+ const response = (0, child_process_1.spawnSync)(parserArgs.cmd, parserArgs.args, {
121
+ input: `${parser}|${source}`,
122
+ maxBuffer: 15 * 1024 * 1024
123
+ });
124
+ const stdout = response.stdout.toString();
125
+ const stderr = response.stderr.toString();
126
+ const { status } = response;
127
+ // If we didn't receive anything over stdout or we have a bad exit status,
128
+ // then throw whatever we can.
129
+ if (stdout.length === 0 || (status !== null && status !== 0)) {
130
+ throw new Error(stderr || "An unknown error occurred");
131
+ }
132
+ const parsed = JSON.parse(stdout);
133
+ if (parsed.error) {
134
+ const error = new Error(parsed.error);
135
+ if (parsed.loc) {
136
+ error.loc = parsed.loc;
137
+ }
138
+ throw error;
139
+ }
140
+ return parsed;
141
+ }
142
+ exports.default = parseSync;
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup' if ENV['PLUGIN_RUBY_CI']
4
+ require 'socket'
5
+ require 'json'
6
+ require 'fileutils'
7
+ require 'open3'
8
+
9
+ require_relative '../ruby/parser'
10
+ require_relative '../rbs/parser'
11
+ require_relative '../haml/parser'
12
+
13
+ # Make sure we trap these signals to be sure we get the quit command coming from
14
+ # the parent node process
15
+ quit = false
16
+ trap(:INT) { quit = true }
17
+ trap(:TERM) { quit = true }
18
+ trap(:QUIT) { quit = true } if Signal.list.key?('QUIT')
19
+
20
+ # The information variable stores the actual connection information, which will
21
+ # either be an IP address and port or a path to a unix socket file.
22
+ information = ''
23
+
24
+ # The candidates array is a list of potential programs that could be used to
25
+ # connect to our server. We'll run through them after the server starts to find
26
+ # the best one to use.
27
+ candidates = []
28
+
29
+ if Gem.win_platform?
30
+ # If we're on windows, we're going to start up a TCP server. The 0 here means
31
+ # to bind to some available port.
32
+ server = TCPServer.new('127.0.0.1', 0)
33
+ address = server.local_address
34
+
35
+ # Ensure that we close the server when this process exits.
36
+ at_exit { server.close }
37
+
38
+ information = "#{address.ip_address} #{address.ip_port}"
39
+ candidates = %w[nc telnet]
40
+ else
41
+ # If we're not on windows, then we're going to assume we can use unix socket
42
+ # files (since they're faster than a TCP server).
43
+ filepath = "/tmp/prettier-ruby-parser-#{Process.pid}.sock"
44
+ server = UNIXServer.new(filepath)
45
+
46
+ # Ensure that we close the server and delete the socket file when this
47
+ # process exits.
48
+ at_exit do
49
+ server.close
50
+ File.unlink(filepath)
51
+ end
52
+
53
+ information = server.local_address.unix_path
54
+ candidates = ['nc -w 3 -U', 'ncat -w 3 -U']
55
+ end
56
+
57
+ # This is the actual listening thread that will be acting as our server. We have
58
+ # to start it in another thread to begin with so that we can run through our
59
+ # candidate connection programs. Eventually we'll just join into this thread
60
+ # though and it will act as a daemon.
61
+ listener =
62
+ Thread.new do
63
+ loop do
64
+ break if quit
65
+
66
+ # Start up a new thread that will handle each successive connection.
67
+ Thread.new(server.accept_nonblock) do |socket|
68
+ parser, source = socket.read.force_encoding('UTF-8').split('|', 2)
69
+
70
+ response =
71
+ case parser
72
+ when 'ping'
73
+ 'pong'
74
+ when 'ruby'
75
+ Prettier::Parser.parse(source)
76
+ when 'rbs'
77
+ Prettier::RBSParser.parse(source)
78
+ when 'haml'
79
+ Prettier::HAMLParser.parse(source)
80
+ end
81
+
82
+ if response
83
+ socket.write(JSON.fast_generate(response))
84
+ else
85
+ socket.write('{ "error": true }')
86
+ end
87
+ rescue Prettier::Parser::ParserError => error
88
+ loc = { start: { line: error.lineno, column: error.column } }
89
+ socket.write(JSON.fast_generate(error: error.message, loc: loc))
90
+ rescue StandardError => error
91
+ begin
92
+ socket.write(JSON.fast_generate(error: error.message))
93
+ rescue Errno::EPIPE
94
+ # Do nothing, the pipe has been closed by the parent process so we don't
95
+ # actually care about writing to it anymore.
96
+ end
97
+ ensure
98
+ socket.close
99
+ end
100
+ rescue IO::WaitReadable, Errno::EINTR
101
+ # Wait for select(2) to give us a connection that has content for 1
102
+ # second. Otherwise timeout and continue on (so that we hit our
103
+ # "break if quit" pretty often).
104
+ IO.select([server], nil, nil, 1)
105
+
106
+ retry unless quit
107
+ end
108
+ end
109
+
110
+ # Map each candidate connection method to a thread that will check if it works.
111
+ candidates.map! do |candidate|
112
+ Thread.new do
113
+ Thread.current.report_on_exception = false
114
+
115
+ stdout, status =
116
+ Open3.capture2("#{candidate} #{information}", stdin_data: 'ping')
117
+
118
+ candidate if JSON.parse(stdout) == 'pong' && status.exitstatus == 0
119
+ rescue StandardError
120
+ # We don't actually care if this fails, because we'll just skip that
121
+ # connection option.
122
+ end
123
+ end
124
+
125
+ # Find the first one prefix that successfully returned the correct value.
126
+ prefix =
127
+ candidates.detect do |candidate|
128
+ value = candidate.value
129
+ break value if value
130
+ end
131
+
132
+ # Default to running the netcat.js script that we ship with the plugin. It's a
133
+ # good fallback as it will always work, but it is slower than the other options.
134
+ prefix ||= "node #{File.expand_path('netcat.js', __dir__)}"
135
+
136
+ # Write out our connection information to the file given as the first argument
137
+ # to this script.
138
+ File.write(ARGV[0], "#{prefix} #{information}")
139
+
140
+ listener.join
data/dist/plugin.js ADDED
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const printer_1 = __importDefault(require("./ruby/printer"));
6
+ const parser_1 = __importDefault(require("./ruby/parser"));
7
+ const printer_2 = __importDefault(require("./rbs/printer"));
8
+ const parser_2 = __importDefault(require("./rbs/parser"));
9
+ const printer_3 = __importDefault(require("./haml/printer"));
10
+ const parser_3 = __importDefault(require("./haml/parser"));
11
+ /*
12
+ * metadata mostly pulled from linguist and rubocop:
13
+ * https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
14
+ * https://github.com/rubocop/rubocop/blob/master/spec/rubocop/target_finder_spec.rb
15
+ */
16
+ const plugin = {
17
+ languages: [
18
+ {
19
+ name: "Ruby",
20
+ parsers: ["ruby"],
21
+ extensions: [
22
+ ".arb",
23
+ ".axlsx",
24
+ ".builder",
25
+ ".eye",
26
+ ".fcgi",
27
+ ".gemfile",
28
+ ".gemspec",
29
+ ".god",
30
+ ".jb",
31
+ ".jbuilder",
32
+ ".mspec",
33
+ ".opal",
34
+ ".pluginspec",
35
+ ".podspec",
36
+ ".rabl",
37
+ ".rake",
38
+ ".rb",
39
+ ".rbi",
40
+ ".rbuild",
41
+ ".rbw",
42
+ ".rbx",
43
+ ".ru",
44
+ ".ruby",
45
+ ".thor",
46
+ ".watchr"
47
+ ],
48
+ filenames: [
49
+ ".irbrc",
50
+ ".pryrc",
51
+ ".simplecov",
52
+ "Appraisals",
53
+ "Berksfile",
54
+ "Brewfile",
55
+ "Buildfile",
56
+ "Capfile",
57
+ "Cheffile",
58
+ "Dangerfile",
59
+ "Deliverfile",
60
+ "Fastfile",
61
+ "Gemfile",
62
+ "Guardfile",
63
+ "Jarfile",
64
+ "Mavenfile",
65
+ "Podfile",
66
+ "Puppetfile",
67
+ "Rakefile",
68
+ "Snapfile",
69
+ "Thorfile",
70
+ "Vagabondfile",
71
+ "Vagrantfile",
72
+ "buildfile"
73
+ ],
74
+ interpreters: ["jruby", "macruby", "rake", "rbx", "ruby"],
75
+ linguistLanguageId: 326,
76
+ vscodeLanguageIds: ["ruby"]
77
+ },
78
+ {
79
+ name: "RBS",
80
+ parsers: ["rbs"],
81
+ extensions: [".rbs"]
82
+ },
83
+ {
84
+ name: "HAML",
85
+ parsers: ["haml"],
86
+ extensions: [".haml"],
87
+ vscodeLanguageIds: ["haml"]
88
+ }
89
+ ],
90
+ parsers: {
91
+ ruby: parser_1.default,
92
+ rbs: parser_2.default,
93
+ haml: parser_3.default
94
+ },
95
+ printers: {
96
+ ruby: printer_1.default,
97
+ rbs: printer_2.default,
98
+ haml: printer_3.default
99
+ },
100
+ options: {
101
+ rubyArrayLiteral: {
102
+ type: "boolean",
103
+ category: "Ruby",
104
+ default: true,
105
+ description: "When possible, favor the use of string and symbol array literals.",
106
+ since: "1.0.0"
107
+ },
108
+ rubyHashLabel: {
109
+ type: "boolean",
110
+ category: "Ruby",
111
+ default: true,
112
+ description: "When possible, uses the shortened hash key syntax, as opposed to hash rockets.",
113
+ since: "1.0.0"
114
+ },
115
+ rubyModifier: {
116
+ type: "boolean",
117
+ category: "Ruby",
118
+ default: true,
119
+ description: "When it fits on one line, allows if, unless, while, and until statements to use the modifier form.",
120
+ since: "1.0.0"
121
+ },
122
+ rubySingleQuote: {
123
+ type: "boolean",
124
+ category: "Ruby",
125
+ default: true,
126
+ description: "When double quotes are not necessary for interpolation, prefers the use of single quotes for string literals.",
127
+ since: "1.0.0"
128
+ },
129
+ rubyToProc: {
130
+ type: "boolean",
131
+ category: "Ruby",
132
+ default: false,
133
+ description: "When possible, convert blocks to the more concise Symbol#to_proc syntax.",
134
+ since: "1.0.0"
135
+ }
136
+ },
137
+ defaultOptions: {
138
+ printWidth: 80,
139
+ tabWidth: 2,
140
+ trailingComma: "none"
141
+ }
142
+ };
143
+ module.exports = plugin;
data/dist/prettier.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // If `RBPRETTIER` is set, then this is being run from the `Prettier::run` ruby
4
+ // method. In that case, we need to pull `prettier` from the node_modules
5
+ // directly, as it's been shipped with the gem.
6
+ /* istanbul ignore next */
7
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8
+ const source = require(process.env.RBPRETTIER
9
+ ? "../node_modules/prettier"
10
+ : "prettier");
11
+ // Cramming everything together to make it simpler to pull in all of the right
12
+ // utilities and builders.
13
+ const builders = source.doc.builders;
14
+ const exported = { ...builders, ...source.doc.utils, ...source.util };
15
+ exports.default = exported;
@@ -0,0 +1,34 @@
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 Ruby process of parser.rb and reading JSON off STDOUT.
12
+ parse(text) {
13
+ return (0, parseSync_1.default)("rbs", text);
14
+ },
15
+ astFormat: "rbs",
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\n]*@(format|prettier)\s*(\n|$)/.test(text);
20
+ },
21
+ // This function is critical for comments and cursor support, and is
22
+ // responsible for returning the index of the character within the source
23
+ // string that is the beginning of the given node.
24
+ locStart(node) {
25
+ return node.location.start_pos;
26
+ },
27
+ // This function is critical for comments and cursor support, and is
28
+ // responsible for returning the index of the character within the source
29
+ // string that is the ending of the given node.
30
+ locEnd(node) {
31
+ return node.location.end_pos;
32
+ }
33
+ };
34
+ exports.default = parser;
File without changes