syntax_tree-rbs 0.1.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eff99e85b92644bcfc8cf94291ec8e056c30cb72723bf98e571a0ffef264fcd8
4
- data.tar.gz: 75ee446a19c76662c34bf17e323d0e26101cbb3cb173eb6546088e96e11fa867
3
+ metadata.gz: 7e0550ed09644f60c85734f0633143c5fa621356c9fada7f073446070037ca2e
4
+ data.tar.gz: fbad990727e58695a58c37cbf31eea3a0f5ed418b4666d38416a8b4fe2aecdaf
5
5
  SHA512:
6
- metadata.gz: 3121deff5c7b0b25889b95cecbe79ca611d140d00d6ebc52d6232696f944d882431c6d41f4b669bd4ec68f2452d1a48c18c4292d97c60d155491894886c73b11
7
- data.tar.gz: 3a05df94b6b1be4115e39ce358b3dbba4846fd39cc592fbf5b73825e17fb7054bc0e8e9b0c8db585c85a46c75789deb16626c07cb9bcd51679b8e9b1b98cf5df
6
+ metadata.gz: 1c95de371dba5bbffb0b8d78251f77c6143de8db74c17576ae674125b46173db0b35d65ab97eb6ebd8cf44e91311e33a138c78ff84ab5b17c13d0cb914217af9
7
+ data.tar.gz: d4bf5bc46aa49848425f119937e45e9e15f131e0dc623b8f6bc4c3f93863cb21a5ce824fbca5aa6fbcf9f34129dd1093eb1ee16806cc27003b3b3b21382d3021
@@ -4,16 +4,27 @@ on:
4
4
  - pull_request_target
5
5
  jobs:
6
6
  ci:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ ruby:
11
+ - '2.7.5'
12
+ - '3.0'
13
+ - '3.1'
14
+ gemfile:
15
+ - rbs1
16
+ - rbs2
7
17
  name: CI
8
18
  runs-on: ubuntu-latest
9
19
  env:
20
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
10
21
  CI: true
11
22
  steps:
12
23
  - uses: actions/checkout@master
13
24
  - uses: ruby/setup-ruby@v1
14
25
  with:
15
26
  bundler-cache: true
16
- ruby-version: '3.1'
27
+ ruby-version: ${{ matrix.ruby }}
17
28
  - name: Test
18
29
  run: bundle exec rake test
19
30
  automerge:
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /tmp/
9
9
 
10
10
  test.rbs
11
+ gemfiles/*.lock
data/CHANGELOG.md CHANGED
@@ -6,11 +6,34 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.4.0] - 2022-05-13
10
+
11
+ ### Added
12
+
13
+ - Add an optional `maxwidth` second argument to `SyntaxTree::RBS.format`.
14
+
15
+ ## [0.3.0] - 2022-05-13
16
+
17
+ ### Changed
18
+
19
+ - Use the `prettier_print` gem for formatting instead of `prettyprint`.
20
+
21
+ ## [0.2.0] - 2022-04-22
22
+
23
+ ### Added
24
+
25
+ - Support for RBS 1.0 in addition to RBS 2.0.
26
+ - Adding support back for Ruby 2.7.
27
+ - Support for inline visibility modifiers in RBS 2.0.
28
+
9
29
  ## [0.1.0] - 2022-04-05
10
30
 
11
31
  ### Added
12
32
 
13
33
  - 🎉 Initial release! 🎉
14
34
 
15
- [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.1.0...HEAD
35
+ [unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.4.0...HEAD
36
+ [0.4.0]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.3.0...v0.4.0
37
+ [0.3.0]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.2.0...v0.3.0
38
+ [0.2.0]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.1.0...v0.2.0
16
39
  [0.1.0]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/93efc7...v0.1.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syntax_tree-rbs (0.1.0)
4
+ syntax_tree-rbs (0.4.0)
5
+ prettier_print
5
6
  rbs
6
7
  syntax_tree (>= 2.0.1)
7
8
 
@@ -10,17 +11,20 @@ GEM
10
11
  specs:
11
12
  docile (1.4.0)
12
13
  minitest (5.15.0)
14
+ prettier_print (0.1.0)
13
15
  rake (13.0.6)
14
- rbs (2.3.2)
16
+ rbs (2.4.0)
15
17
  simplecov (0.21.2)
16
18
  docile (~> 1.1)
17
19
  simplecov-html (~> 0.11)
18
20
  simplecov_json_formatter (~> 0.1)
19
21
  simplecov-html (0.12.3)
20
22
  simplecov_json_formatter (0.1.4)
21
- syntax_tree (2.0.1)
23
+ syntax_tree (2.5.0)
24
+ prettier_print
22
25
 
23
26
  PLATFORMS
27
+ x86_64-darwin-19
24
28
  x86_64-darwin-21
25
29
  x86_64-linux
26
30
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec path: ".."
6
+
7
+ gem "rbs", "~> 1"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec path: ".."
6
+
7
+ gem "rbs", "~> 2"
@@ -16,6 +16,7 @@ module SyntaxTree
16
16
 
17
17
  def format(q)
18
18
  q.group do
19
+ q.text("#{node.visibility} ") if node.visibility
19
20
  q.text("attr_#{type} ")
20
21
  q.text("self.") if node.kind == :singleton
21
22
  q.text(node.name)
@@ -43,6 +44,12 @@ module SyntaxTree
43
44
  q.text("name=")
44
45
  q.pp(node.name)
45
46
 
47
+ if node.visibility
48
+ q.breakable
49
+ q.text("visibility=")
50
+ q.pp(node.visibility)
51
+ end
52
+
46
53
  unless node.ivar_name.nil?
47
54
  q.breakable
48
55
  q.text("ivar_name=")
@@ -281,6 +288,7 @@ module RBS
281
288
  SyntaxTree::RBS::Annotations.maybe_format(q, annotations)
282
289
 
283
290
  q.group do
291
+ q.text("#{visibility} ") if visibility
284
292
  q.text("def ")
285
293
 
286
294
  if kind == :singleton
@@ -332,6 +340,12 @@ module RBS
332
340
  q.text("name=")
333
341
  q.pp(name)
334
342
 
343
+ if visibility
344
+ q.breakable
345
+ q.text("visibility=")
346
+ q.pp(visibility)
347
+ end
348
+
335
349
  if overload?
336
350
  q.breakable
337
351
  q.text("overload")
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ if defined?(RBS::AST::Declarations::ModuleTypeParams)
4
+ require "delegate"
5
+
6
+ # Previously there were specialized types that didn't include some additional
7
+ # information for type params. So here we wrap them up in order to maintain the
8
+ # same API.
9
+ module ShimTypeParams
10
+ class ShimTypeParam < SimpleDelegator
11
+ def unchecked?
12
+ false
13
+ end
14
+
15
+ def upper_bound
16
+ nil
17
+ end
18
+ end
19
+
20
+ # Overriding the type params method to return an array of wrapped objects.
21
+ def type_params
22
+ super.params.map { |param| ShimTypeParam.new(param) }
23
+ end
24
+ end
25
+
26
+ module RBS::AST::Declarations
27
+ Alias.prepend(ShimTypeParams)
28
+ Class.prepend(ShimTypeParams)
29
+ Interface.prepend(ShimTypeParams)
30
+ Module.prepend(ShimTypeParams)
31
+ end
32
+ end
33
+
34
+ # Previously this attribute didn't exist on some nodes. So if they don't have
35
+ # it, we're just going to apply it and have it return nil.
36
+ module ShimVisibility
37
+ def visibility
38
+ end
39
+ end
40
+
41
+ module RBS::AST::Members
42
+ [AttrAccessor, AttrReader, AttrWriter, MethodDefinition].each do |klass|
43
+ klass.include(ShimVisibility) unless klass.method_defined?(:visibility)
44
+ end
45
+ end
@@ -139,7 +139,7 @@ module RBS
139
139
 
140
140
  class Literal
141
141
  def format(q)
142
- unless literal in String
142
+ unless literal.is_a?(String)
143
143
  q.text(literal.inspect)
144
144
  return
145
145
  end
@@ -132,7 +132,7 @@ module SyntaxTree
132
132
 
133
133
  def format(q)
134
134
  node.name.format(q)
135
- return if node.type_params.length == 0
135
+ return if node.type_params.empty?
136
136
 
137
137
  q.text("[")
138
138
  q.seplist(node.type_params, -> { q.text(", ") }) do |param|
@@ -308,7 +308,8 @@ module SyntaxTree
308
308
  if node.respond_to?(:type_params) && node.type_params.any?
309
309
  q.text("[")
310
310
  q.seplist(node.type_params, -> { q.text(", ") }) do |param|
311
- q.text(param.name)
311
+ # We need to do a type check here to support RBS 1.0
312
+ q.text(param.is_a?(Symbol) ? param.to_s : param.name)
312
313
  end
313
314
  q.text("] ")
314
315
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SyntaxTree
4
4
  module RBS
5
- VERSION = "0.1.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
@@ -1,21 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "prettier_print"
3
4
  require "rbs"
4
5
  require "syntax_tree"
5
6
 
6
7
  require_relative "rbs/declarations"
7
8
  require_relative "rbs/members"
9
+ require_relative "rbs/shims"
8
10
  require_relative "rbs/types"
9
11
  require_relative "rbs/utils"
10
12
  require_relative "rbs/version"
11
13
 
12
14
  module SyntaxTree
13
15
  module RBS
14
- # A slight extension to the default PP formatter that keeps track of the
15
- # source (so that it can be referenced by annotations if they need it) and
16
- # keeps track of the level of intersections and unions so that parentheses
17
- # can be forced if necessary.
18
- class Formatter < PP
16
+ # A slight extension to the default PrettierPrint formatter that keeps track
17
+ # of the source (so that it can be referenced by annotations if they need
18
+ # it) and keeps track of the level of intersections and unions so that
19
+ # parentheses can be forced if necessary.
20
+ class Formatter < PrettierPrint
19
21
  attr_reader :source
20
22
 
21
23
  def initialize(source, ...)
@@ -67,8 +69,8 @@ module SyntaxTree
67
69
  end
68
70
 
69
71
  class << self
70
- def format(source)
71
- formatter = Formatter.new(source, [])
72
+ def format(source, maxwidth = 80)
73
+ formatter = Formatter.new(source, [], maxwidth)
72
74
  parse(source).format(formatter)
73
75
 
74
76
  formatter.flush
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = %w[lib]
25
25
 
26
+ spec.add_dependency "prettier_print"
26
27
  spec.add_dependency "rbs"
27
28
  spec.add_dependency "syntax_tree", ">= 2.0.1"
28
29
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syntax_tree-rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.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: 2022-04-07 00:00:00.000000000 Z
11
+ date: 2022-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prettier_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rbs
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -114,9 +128,12 @@ files:
114
128
  - bin/format
115
129
  - bin/parse
116
130
  - bin/setup
131
+ - gemfiles/rbs1.gemfile
132
+ - gemfiles/rbs2.gemfile
117
133
  - lib/syntax_tree/rbs.rb
118
134
  - lib/syntax_tree/rbs/declarations.rb
119
135
  - lib/syntax_tree/rbs/members.rb
136
+ - lib/syntax_tree/rbs/shims.rb
120
137
  - lib/syntax_tree/rbs/types.rb
121
138
  - lib/syntax_tree/rbs/utils.rb
122
139
  - lib/syntax_tree/rbs/version.rb