rbs_heuristic_prototype 0.4.0 → 0.5.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: af9a660bde45e0c64701f350cfa2fed63112aec3c6fd3320f0387b084c5a6236
4
- data.tar.gz: 92f823a5423774c78a092b35719ec66d440e9d63dedc5488d07c7049fd3b03df
3
+ metadata.gz: 358275124e21b1d4060fa62fc17832e1b4398ce9f74571a5cda63b5677747bf0
4
+ data.tar.gz: 819ee68bf26be9f3352191aa62a1e244ac0584dd66ab19946df7230da8fb176b
5
5
  SHA512:
6
- metadata.gz: e0dce9def43b5ccd0445b2f4d748626381bf83eeb9831082b9bd184d49f7cc0a0c039c16a3dda9df2ae7bb595a056e2b39551c13dbc8b74a91dcbd54f474732d
7
- data.tar.gz: 9d7aeaa4971e0b3535e94abb963dde4ad11528c8601a770ddae778fa4adde37a0bca5c4b7dda2088fe651ebf0ecd9dae843df4ea02aa00a97fd7824cc4c6417d
6
+ metadata.gz: aa3f88c1a520774b683e9cdb486e0ba58f68bb7da9c96629658e6bd1eb58efd320b26952d07e673bfa38ecc13a374ebb561c6fca4cf61d6cf4af380aae50b88f
7
+ data.tar.gz: 371d461c82de68c3fd03ef9cbf03a2f59b4c03e796255938237087fa066fff359bcfced4b5d760a778dfa95d5839540b9c80e590a5d248a449a267cae57407ea
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs_heuristic_prototype (0.4.0)
4
+ rbs_heuristic_prototype (0.5.0)
5
5
  rbs
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -45,6 +45,8 @@ by `rbs prototype` according to the heuristic rules.
45
45
  * Rule 4:
46
46
  * Convert a scoped module/class definition (ex. `Foo::Bar::Baz`) to the nested definitions
47
47
  * This is useful to define intermediate modules automatically like what Rails and zeitwerk does.
48
+ * Rule 5:
49
+ * Convert a module reference without type arguments (ex. `include Enumerable`) to a module reference with type arguments (ex. `include Enumerable[untyped]`)
48
50
 
49
51
  ## Development
50
52
 
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module RbsHeuristicPrototype
6
+ module Filters
7
+ class TypeArgsFilter < Base
8
+ def process_class(decl)
9
+ decl = super(decl)
10
+ RBS::AST::Declarations::Class.new(
11
+ name: decl.name,
12
+ type_params: decl.type_params,
13
+ super_class: process_super_class(decl.super_class),
14
+ members: decl.members,
15
+ annotations: decl.annotations,
16
+ location: decl.location,
17
+ comment: decl.comment
18
+ )
19
+ end
20
+
21
+ def process_super_class(decl)
22
+ return unless decl
23
+
24
+ class_decl = external_env.class_decls[decl.name.absolute!]
25
+ if class_decl && decl.args.empty?
26
+ RBS::AST::Declarations::Class::Super.new(
27
+ name: decl.name,
28
+ args: class_decl.type_params.size.times.map { :untyped },
29
+ location: decl.location
30
+ )
31
+ else
32
+ decl
33
+ end
34
+ end
35
+
36
+ def process_member(decl)
37
+ case decl
38
+ when RBS::AST::Members::Include
39
+ process_include(decl)
40
+ else
41
+ super
42
+ end
43
+ end
44
+
45
+ def process_include(decl)
46
+ class_decl = external_env.class_decls[decl.name.absolute!]
47
+ if class_decl && decl.args.empty?
48
+ RBS::AST::Members::Include.new(
49
+ name: decl.name,
50
+ args: class_decl.type_params.size.times.map { :untyped },
51
+ annotations: decl.annotations,
52
+ location: decl.location,
53
+ comment: decl.comment
54
+ )
55
+ else
56
+ decl
57
+ end
58
+ end
59
+
60
+ def external_env
61
+ loader = RBS::EnvironmentLoader.new
62
+ RBS::Environment.from_loader(loader)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -10,7 +10,8 @@ module RbsHeuristicPrototype
10
10
  active_model_validations: Filters::ActiveModelValidationsFilter,
11
11
  boolean_methods: Filters::BooleanMethodsFilter,
12
12
  deep_module: Filters::DeepModuleFilter,
13
- symbol_array_constants: Filters::SymbolArrayConstantsFilter
13
+ symbol_array_constants: Filters::SymbolArrayConstantsFilter,
14
+ type_args: Filters::TypeArgsFilter
14
15
  }.freeze
15
16
 
16
17
  attr_reader :name, :path
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbsHeuristicPrototype
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -4,6 +4,7 @@ require_relative "rbs_heuristic_prototype/filters/active_model_validations_filte
4
4
  require_relative "rbs_heuristic_prototype/filters/boolean_methods_filter"
5
5
  require_relative "rbs_heuristic_prototype/filters/deep_module_filter"
6
6
  require_relative "rbs_heuristic_prototype/filters/symbol_array_constants_filter"
7
+ require_relative "rbs_heuristic_prototype/filters/type_args_filter"
7
8
  require_relative "rbs_heuristic_prototype/rake_task"
8
9
  require_relative "rbs_heuristic_prototype/version"
9
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs_heuristic_prototype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi KOMIYA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-01 00:00:00.000000000 Z
11
+ date: 2023-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -49,6 +49,7 @@ files:
49
49
  - lib/rbs_heuristic_prototype/filters/boolean_methods_filter.rb
50
50
  - lib/rbs_heuristic_prototype/filters/deep_module_filter.rb
51
51
  - lib/rbs_heuristic_prototype/filters/symbol_array_constants_filter.rb
52
+ - lib/rbs_heuristic_prototype/filters/type_args_filter.rb
52
53
  - lib/rbs_heuristic_prototype/rake_task.rb
53
54
  - lib/rbs_heuristic_prototype/version.rb
54
55
  - rbs_collection.lock.yaml