prettier 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -6
  3. data/README.md +16 -16
  4. data/exe/rbprettier +2 -2
  5. data/lib/prettier/rake/task.rb +5 -5
  6. data/lib/prettier.rb +11 -11
  7. data/package.json +9 -23
  8. data/rubocop.yml +6 -6
  9. data/{dist/parser → src}/getInfo.js +0 -1
  10. data/{dist/parser → src}/netcat.js +0 -1
  11. data/src/parseSync.js +212 -0
  12. data/src/plugin.js +161 -0
  13. data/{dist/parser → src}/server.rb +45 -31
  14. metadata +94 -78
  15. data/bin/console +0 -7
  16. data/dist/haml/embed.js +0 -53
  17. data/dist/haml/parser.js +0 -31
  18. data/dist/haml/parser.rb +0 -149
  19. data/dist/haml/printer.js +0 -336
  20. data/dist/parser/parseSync.js +0 -179
  21. data/dist/plugin.js +0 -143
  22. data/dist/prettier.js +0 -15
  23. data/dist/rbs/parser.js +0 -34
  24. data/dist/rbs/parser.rb +0 -155
  25. data/dist/rbs/printer.js +0 -525
  26. data/dist/ruby/embed.js +0 -115
  27. data/dist/ruby/location.js +0 -19
  28. data/dist/ruby/nodes/alias.js +0 -60
  29. data/dist/ruby/nodes/aref.js +0 -51
  30. data/dist/ruby/nodes/args.js +0 -138
  31. data/dist/ruby/nodes/arrays.js +0 -122
  32. data/dist/ruby/nodes/assign.js +0 -37
  33. data/dist/ruby/nodes/blocks.js +0 -90
  34. data/dist/ruby/nodes/calls.js +0 -263
  35. data/dist/ruby/nodes/case.js +0 -50
  36. data/dist/ruby/nodes/class.js +0 -54
  37. data/dist/ruby/nodes/commands.js +0 -138
  38. data/dist/ruby/nodes/conditionals.js +0 -246
  39. data/dist/ruby/nodes/constants.js +0 -35
  40. data/dist/ruby/nodes/flow.js +0 -59
  41. data/dist/ruby/nodes/hashes.js +0 -126
  42. data/dist/ruby/nodes/heredocs.js +0 -30
  43. data/dist/ruby/nodes/hooks.js +0 -35
  44. data/dist/ruby/nodes/ints.js +0 -27
  45. data/dist/ruby/nodes/lambdas.js +0 -70
  46. data/dist/ruby/nodes/loops.js +0 -75
  47. data/dist/ruby/nodes/massign.js +0 -60
  48. data/dist/ruby/nodes/methods.js +0 -50
  49. data/dist/ruby/nodes/operators.js +0 -68
  50. data/dist/ruby/nodes/params.js +0 -95
  51. data/dist/ruby/nodes/patterns.js +0 -119
  52. data/dist/ruby/nodes/regexp.js +0 -45
  53. data/dist/ruby/nodes/rescue.js +0 -86
  54. data/dist/ruby/nodes/return.js +0 -100
  55. data/dist/ruby/nodes/statements.js +0 -110
  56. data/dist/ruby/nodes/strings.js +0 -220
  57. data/dist/ruby/nodes/super.js +0 -26
  58. data/dist/ruby/nodes/undef.js +0 -31
  59. data/dist/ruby/nodes.js +0 -177
  60. data/dist/ruby/parser.js +0 -35
  61. data/dist/ruby/parser.rb +0 -9134
  62. data/dist/ruby/printer.js +0 -67
  63. data/dist/ruby/toProc.js +0 -91
  64. data/dist/types/haml.js +0 -4
  65. data/dist/types/plugin.js +0 -3
  66. data/dist/types/rbs.js +0 -4
  67. data/dist/types/ruby.js +0 -4
  68. data/dist/types/utils.js +0 -2
  69. data/dist/types.js +0 -34
  70. data/dist/utils/containsAssignment.js +0 -18
  71. data/dist/utils/getChildNodes.js +0 -305
  72. data/dist/utils/getTrailingComma.js +0 -6
  73. data/dist/utils/hasAncestor.js +0 -15
  74. data/dist/utils/inlineEnsureParens.js +0 -49
  75. data/dist/utils/isEmptyBodyStmt.js +0 -10
  76. data/dist/utils/isEmptyParams.js +0 -12
  77. data/dist/utils/isEmptyStmts.js +0 -10
  78. data/dist/utils/literal.js +0 -8
  79. data/dist/utils/literallineWithoutBreakParent.js +0 -8
  80. data/dist/utils/makeCall.js +0 -14
  81. data/dist/utils/noIndent.js +0 -11
  82. data/dist/utils/printEmptyCollection.js +0 -46
  83. data/dist/utils/skipAssignIndent.js +0 -19
  84. data/dist/utils.js +0 -32
data/dist/plugin.js DELETED
@@ -1,143 +0,0 @@
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 DELETED
@@ -1,15 +0,0 @@
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;
data/dist/rbs/parser.js DELETED
@@ -1,34 +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 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;
data/dist/rbs/parser.rb DELETED
@@ -1,155 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- begin
4
- require 'rbs'
5
- rescue LoadError
6
- # If we can't load the rbs gem, then we're going to provide a shim parser that
7
- # will warn and bail out.
8
- class Prettier::RBSParser
9
- def self.parse(text)
10
- warn(
11
- 'The `rbs` gem could not be loaded. Please ensure you have it ' \
12
- 'installed and that it is available in the gem path.'
13
- )
14
-
15
- false
16
- end
17
- end
18
-
19
- return
20
- end
21
-
22
- # This was removed at some point, so we need to support both versions.
23
- RBS::KEYWORD_RAW =
24
- if RBS::Parser.const_defined?(:KEYWORDS_RE)
25
- RBS::Parser::KEYWORDS_RE
26
- else
27
- RBS::Parser::KEYWORDS.keys.join('|')
28
- end
29
-
30
- # This enforces that the full matched string is a keyword.
31
- RBS::KEYWORD_FULL = /\A#{RBS::KEYWORD_RAW}\z/
32
-
33
- # Monkey-patch this so that we can get the character positions.
34
- class RBS::Location
35
- def to_json(*args)
36
- {
37
- start: {
38
- line: start_line,
39
- column: start_column
40
- },
41
- end: {
42
- line: end_line,
43
- column: end_column
44
- },
45
- start_pos: start_pos,
46
- end_pos: end_pos
47
- }.to_json(*args)
48
- end
49
- end
50
-
51
- # Monkey-patch this so that we get whether or not it needs to be escaped.
52
- class RBS::Types::Function::Param
53
- def to_json(*a)
54
- escaped = name && RBS::KEYWORD_FULL.match?(name)
55
-
56
- # More modern versions of RBS just include the ` in the name so there's no
57
- # need to escape it further.
58
- escaped = false if name.to_s.start_with?('`')
59
-
60
- { type: type, name: name, escaped: escaped }.to_json(*a)
61
- end
62
- end
63
-
64
- # Monkey-patch this so that we get the name field in the serialized JSON, as
65
- # well as information about whether or not we need to escape it.
66
- class RBS::AST::Members::MethodDefinition
67
- def to_json(*a)
68
- {
69
- member: :method_definition,
70
- name: name,
71
- kind: kind,
72
- types: types,
73
- annotations: annotations,
74
- location: location,
75
- comment: comment,
76
- overload: overload
77
- }.to_json(*a)
78
- end
79
- end
80
-
81
- # Monkey-patch this so that we get the information we need about how to join the
82
- # key-value pairs of the record.
83
- class RBS::Types::Record
84
- def to_json(*a)
85
- fields_extra = {}
86
-
87
- # Explicitly not using Enumerable#to_h here to support Ruby 2.5
88
- fields.each do |key, type|
89
- if key.is_a?(Symbol) && key.match?(/\A[A-Za-z_][A-Za-z_]*\z/) &&
90
- !key.match?(RBS::KEYWORD_RAW)
91
- fields_extra[key] = { type: type, joiner: :label }
92
- else
93
- fields_extra[key.inspect] = { type: type, joiner: :rocket }
94
- end
95
- end
96
-
97
- { class: :record, fields: fields_extra, location: location }.to_json(*a)
98
- end
99
- end
100
-
101
- if defined?(RBS::AST::Declarations::ModuleTypeParams)
102
- # This class was removed in rbs 2.0. Monkeypatch < 2.0 to give the same json
103
- # output
104
- class RBS::AST::Declarations::ModuleTypeParams
105
- def to_json(*a)
106
- params.to_json(*a)
107
- end
108
- end
109
-
110
- # make this look like the new AST::TypeParam json
111
- class RBS::AST::Declarations::ModuleTypeParams::TypeParam
112
- def to_json(*a)
113
- { name: name, variance: variance, unchecked: skip_validation }.to_json(*a)
114
- end
115
- end
116
-
117
- # https://github.com/ruby/rbs/commit/3ccdcb1f3ac5dcb866280f745866a852658195e6
118
- class RBS::MethodType
119
- # promote the array of symbols into TypeParam looking-things
120
- def to_json(*a)
121
- type_param_objects =
122
- type_params.map do |name|
123
- {
124
- name: name,
125
- variance: 'invariant',
126
- unchecked: 'false',
127
- upper_bound: nil
128
- # location - harder to get this but not needed
129
- }
130
- end
131
-
132
- {
133
- type_params: type_param_objects,
134
- type: type,
135
- block: block,
136
- location: location
137
- }.to_json(*a)
138
- end
139
- end
140
- end
141
-
142
- # The main parser interface.
143
- module Prettier
144
- class RBSParser
145
- def self.parse(text)
146
- {
147
- declarations: RBS::Parser.parse_signature(text),
148
- location: {
149
- start_pos: 0,
150
- end_pos: text.length
151
- }
152
- }
153
- end
154
- end
155
- end