rbs_heuristic_prototype 0.5.0 → 0.6.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: 358275124e21b1d4060fa62fc17832e1b4398ce9f74571a5cda63b5677747bf0
4
- data.tar.gz: 819ee68bf26be9f3352191aa62a1e244ac0584dd66ab19946df7230da8fb176b
3
+ metadata.gz: 5e7e11861501ff2a314a91b2f337ad4d2eb221ebe592370e45af6e92ea948702
4
+ data.tar.gz: 44ffa57df421f66295eca2b851a284aa081261ef54260cb2b504cad251462cf5
5
5
  SHA512:
6
- metadata.gz: aa3f88c1a520774b683e9cdb486e0ba58f68bb7da9c96629658e6bd1eb58efd320b26952d07e673bfa38ecc13a374ebb561c6fca4cf61d6cf4af380aae50b88f
7
- data.tar.gz: 371d461c82de68c3fd03ef9cbf03a2f59b4c03e796255938237087fa066fff359bcfced4b5d760a778dfa95d5839540b9c80e590a5d248a449a267cae57407ea
6
+ metadata.gz: ab5dec88b9972879a5e138af3b6cec83570fde7dad9b639ce4d8a23b7c8e5f3658d58817b9fb0578bd201a511e5694b377a184842d933e08fdfb6608524ee848
7
+ data.tar.gz: 9f889db54fe192e9ec8e2b825fa65181e400f7f7459a1cc8a6a1f04917c6314390bd9c59194b87040e98e20859f345d5fde6f7bde803e2870dc13e4ebe31d44b
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ gemspec
8
8
  gem "activerecord"
9
9
  gem "railties"
10
10
  gem "rake", "~> 13.0"
11
- gem "rubocop", "~> 1.55"
11
+ gem "rubocop", "~> 1.56"
12
12
 
13
13
  group :development do
14
14
  gem "rspec", require: false
data/Gemfile.lock CHANGED
@@ -1,36 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs_heuristic_prototype (0.5.0)
4
+ rbs_heuristic_prototype (0.6.0)
5
+ activesupport
5
6
  rbs
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- actionpack (7.0.6)
11
- actionview (= 7.0.6)
12
- activesupport (= 7.0.6)
11
+ actionpack (7.0.7.2)
12
+ actionview (= 7.0.7.2)
13
+ activesupport (= 7.0.7.2)
13
14
  rack (~> 2.0, >= 2.2.4)
14
15
  rack-test (>= 0.6.3)
15
16
  rails-dom-testing (~> 2.0)
16
17
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
- actionview (7.0.6)
18
- activesupport (= 7.0.6)
18
+ actionview (7.0.7.2)
19
+ activesupport (= 7.0.7.2)
19
20
  builder (~> 3.1)
20
21
  erubi (~> 1.4)
21
22
  rails-dom-testing (~> 2.0)
22
23
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
- activemodel (7.0.6)
24
- activesupport (= 7.0.6)
25
- activerecord (7.0.6)
26
- activemodel (= 7.0.6)
27
- activesupport (= 7.0.6)
28
- activesupport (7.0.6)
24
+ activemodel (7.0.7.2)
25
+ activesupport (= 7.0.7.2)
26
+ activerecord (7.0.7.2)
27
+ activemodel (= 7.0.7.2)
28
+ activesupport (= 7.0.7.2)
29
+ activesupport (7.0.7.2)
29
30
  concurrent-ruby (~> 1.0, >= 1.0.2)
30
31
  i18n (>= 1.6, < 2)
31
32
  minitest (>= 5.1)
32
33
  tzinfo (~> 2.0)
33
34
  ast (2.4.2)
35
+ base64 (0.1.1)
34
36
  builder (3.2.4)
35
37
  coderay (1.1.3)
36
38
  concurrent-ruby (1.2.2)
@@ -53,9 +55,9 @@ GEM
53
55
  nokogiri (>= 1.12.0)
54
56
  method_source (1.0.0)
55
57
  minitest (5.19.0)
56
- nokogiri (1.15.2-x86_64-darwin)
58
+ nokogiri (1.15.4-x86_64-darwin)
57
59
  racc (~> 1.4)
58
- nokogiri (1.15.2-x86_64-linux)
60
+ nokogiri (1.15.4-x86_64-linux)
59
61
  racc (~> 1.4)
60
62
  parallel (1.23.0)
61
63
  parser (3.2.2.3)
@@ -65,19 +67,19 @@ GEM
65
67
  coderay (~> 1.1)
66
68
  method_source (~> 1.0)
67
69
  racc (1.7.1)
68
- rack (2.2.7)
70
+ rack (2.2.8)
69
71
  rack-test (2.1.0)
70
72
  rack (>= 1.3)
71
- rails-dom-testing (2.1.1)
73
+ rails-dom-testing (2.2.0)
72
74
  activesupport (>= 5.0.0)
73
75
  minitest
74
76
  nokogiri (>= 1.6)
75
77
  rails-html-sanitizer (1.6.0)
76
78
  loofah (~> 2.21)
77
79
  nokogiri (~> 1.14)
78
- railties (7.0.6)
79
- actionpack (= 7.0.6)
80
- activesupport (= 7.0.6)
80
+ railties (7.0.7.2)
81
+ actionpack (= 7.0.7.2)
82
+ activesupport (= 7.0.7.2)
81
83
  method_source
82
84
  rake (>= 12.2)
83
85
  thor (~> 1.0)
@@ -87,7 +89,7 @@ GEM
87
89
  rb-fsevent (0.11.2)
88
90
  rb-inotify (0.10.1)
89
91
  ffi (~> 1.0)
90
- rbs (3.1.2)
92
+ rbs (3.1.3)
91
93
  regexp_parser (2.8.1)
92
94
  rexml (3.2.6)
93
95
  rspec (3.12.0)
@@ -106,7 +108,8 @@ GEM
106
108
  diff-lcs (>= 1.2.0, < 2.0)
107
109
  rspec-support (~> 3.12.0)
108
110
  rspec-support (3.12.0)
109
- rubocop (1.55.0)
111
+ rubocop (1.56.2)
112
+ base64 (~> 0.1.1)
110
113
  json (~> 2.3)
111
114
  language_server-protocol (>= 3.17.0)
112
115
  parallel (~> 1.10)
@@ -121,7 +124,7 @@ GEM
121
124
  parser (>= 3.2.1.0)
122
125
  ruby-progressbar (1.13.0)
123
126
  securerandom (0.2.2)
124
- steep (1.5.2)
127
+ steep (1.5.3)
125
128
  activesupport (>= 5.1)
126
129
  concurrent-ruby (>= 1.1.10)
127
130
  csv (>= 3.0.9)
@@ -143,7 +146,7 @@ GEM
143
146
  tzinfo (2.0.6)
144
147
  concurrent-ruby (~> 1.0)
145
148
  unicode-display_width (2.4.2)
146
- zeitwerk (2.6.8)
149
+ zeitwerk (2.6.11)
147
150
 
148
151
  PLATFORMS
149
152
  x86_64-darwin-19
@@ -157,7 +160,7 @@ DEPENDENCIES
157
160
  rbs_heuristic_prototype!
158
161
  rspec
159
162
  rspec-daemon
160
- rubocop (~> 1.55)
163
+ rubocop (~> 1.56)
161
164
  steep
162
165
 
163
166
  BUNDLED WITH
data/README.md CHANGED
@@ -8,7 +8,7 @@ Add a new entry to your Gemfile and run bundle install:
8
8
 
9
9
  ```
10
10
  group :development do
11
- gem 'rbs_heuristic_prototype'
11
+ gem 'rbs_heuristic_prototype', require: false
12
12
  end
13
13
  ```
14
14
 
@@ -18,14 +18,6 @@ After the installation, please run rake task generator:
18
18
  bundle exec rails g rbs_heuristic_prototype:install
19
19
  ```
20
20
 
21
- Additionally, it would be better to add the following entry to your rbs_collection.yml:
22
-
23
- ```
24
- gems:
25
- - name: rbs_heuristic_prototype
26
- ignore: true
27
- ```
28
-
29
21
  ## Usage
30
22
 
31
23
  1. Run `rbs prototype rb` or `rbs prototype runtime` first
@@ -47,6 +39,8 @@ by `rbs prototype` according to the heuristic rules.
47
39
  * This is useful to define intermediate modules automatically like what Rails and zeitwerk does.
48
40
  * Rule 5:
49
41
  * Convert a module reference without type arguments (ex. `include Enumerable`) to a module reference with type arguments (ex. `include Enumerable[untyped]`)
42
+ * Rule 6:
43
+ * Convert a module definition of controller concerns to have its module-self-types (ex. `module Loginable` to `module Loginable: ApplicationController`)
50
44
 
51
45
  ## Development
52
46
 
@@ -7,7 +7,7 @@ module RbsHeuristicPrototype
7
7
  def create_raketask
8
8
  create_file "lib/tasks/rbs_heuristic_prototype.rake", <<~RUBY
9
9
  begin
10
- require 'rbs_heuristic_prototype'
10
+ require 'rbs_heuristic_prototype/rake_task'
11
11
  RbsHeuristicPrototype::RakeTask.new
12
12
  rescue LoadError
13
13
  # failed to load rbs_heuristic_prototype. Skip to load rbs_heuristic_prototype tasks.
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+ require "active_support/concern"
5
+
6
+ module RbsHeuristicPrototype
7
+ module Filters
8
+ class ControllerConcernsFilter < Base
9
+ def process_module(decl)
10
+ mod = const_get(decl)
11
+ if controller_concern?(mod) && decl.self_types.empty?
12
+ RBS::AST::Declarations::Module.new(
13
+ name: decl.name,
14
+ type_params: decl.type_params,
15
+ members: decl.members,
16
+ self_types: self_types_for(mod),
17
+ annotations: decl.annotations,
18
+ location: decl.location,
19
+ comment: decl.comment
20
+ )
21
+ else
22
+ decl
23
+ end
24
+ end
25
+
26
+ def controller_concern?(mod)
27
+ return false unless mod.instance_variable_defined?(:@_dependencies)
28
+
29
+ source_location = Kernel.const_source_location(mod.name)
30
+ return false unless source_location
31
+
32
+ filename, = source_location.first
33
+ filename.include?("app/controllers/concerns")
34
+ end
35
+
36
+ def self_types_for(mod)
37
+ name = if Kernel.const_get("ApplicationController") && !(mod > ApplicationController)
38
+ TypeName("::ApplicationController")
39
+ else
40
+ TypeName("::ActionController::Base")
41
+ end
42
+
43
+ [RBS::AST::Declarations::Module::Self.new(name: name, args: [], location: nil)]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -7,11 +7,12 @@ require "rake/tasklib"
7
7
  module RbsHeuristicPrototype
8
8
  class RakeTask < Rake::TaskLib
9
9
  FILTERS = {
10
- active_model_validations: Filters::ActiveModelValidationsFilter,
11
- boolean_methods: Filters::BooleanMethodsFilter,
12
- deep_module: Filters::DeepModuleFilter,
13
- symbol_array_constants: Filters::SymbolArrayConstantsFilter,
14
- type_args: Filters::TypeArgsFilter
10
+ active_model_validations: "RbsHeuristicPrototype::Filters::ActiveModelValidationsFilter",
11
+ boolean_methods: "RbsHeuristicPrototype::Filters::BooleanMethodsFilter",
12
+ controller_concerns: "RbsHeuristicPrototype::Filters::ControllerConcernsFilter",
13
+ deep_module: "RbsHeuristicPrototype::Filters::DeepModuleFilter",
14
+ symbol_array_constants: "RbsHeuristicPrototype::Filters::SymbolArrayConstantsFilter",
15
+ type_args: "RbsHeuristicPrototype::Filters::TypeArgsFilter"
15
16
  }.freeze
16
17
 
17
18
  attr_reader :name, :path
@@ -38,11 +39,13 @@ module RbsHeuristicPrototype
38
39
  def define_apply_task
39
40
  desc "Apply heuristic filters to prototype signatures"
40
41
  task("#{name}:apply": :environment) do
42
+ require "rbs_heuristic_prototype" # load RbsHeuristicPrototype lazily
43
+
41
44
  path.find do |entry|
42
45
  next unless entry.file?
43
46
 
44
47
  env = FILTERS.inject(load_env(entry)) do |result, (_name, filter)|
45
- filter.new(result).apply
48
+ filter.constantize.new(result).apply
46
49
  end
47
50
 
48
51
  write_env(entry, env)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbsHeuristicPrototype
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "rbs_heuristic_prototype/filters/active_model_validations_filter"
4
4
  require_relative "rbs_heuristic_prototype/filters/boolean_methods_filter"
5
+ require_relative "rbs_heuristic_prototype/filters/controller_concerns_filter"
5
6
  require_relative "rbs_heuristic_prototype/filters/deep_module_filter"
6
7
  require_relative "rbs_heuristic_prototype/filters/symbol_array_constants_filter"
7
8
  require_relative "rbs_heuristic_prototype/filters/type_args_filter"
@@ -2,7 +2,7 @@
2
2
  sources:
3
3
  - type: git
4
4
  name: ruby/gem_rbs_collection
5
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
5
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
6
6
  remote: https://github.com/ruby/gem_rbs_collection.git
7
7
  repo_dir: gems
8
8
  path: ".gem_rbs_collection"
@@ -16,7 +16,7 @@ gems:
16
16
  source:
17
17
  type: git
18
18
  name: ruby/gem_rbs_collection
19
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
19
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
20
20
  remote: https://github.com/ruby/gem_rbs_collection.git
21
21
  repo_dir: gems
22
22
  - name: actionview
@@ -24,7 +24,7 @@ gems:
24
24
  source:
25
25
  type: git
26
26
  name: ruby/gem_rbs_collection
27
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
27
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
28
28
  remote: https://github.com/ruby/gem_rbs_collection.git
29
29
  repo_dir: gems
30
30
  - name: activemodel
@@ -32,7 +32,7 @@ gems:
32
32
  source:
33
33
  type: git
34
34
  name: ruby/gem_rbs_collection
35
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
35
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
36
36
  remote: https://github.com/ruby/gem_rbs_collection.git
37
37
  repo_dir: gems
38
38
  - name: activerecord
@@ -40,7 +40,7 @@ gems:
40
40
  source:
41
41
  type: git
42
42
  name: ruby/gem_rbs_collection
43
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
43
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
44
44
  remote: https://github.com/ruby/gem_rbs_collection.git
45
45
  repo_dir: gems
46
46
  - name: activesupport
@@ -48,7 +48,7 @@ gems:
48
48
  source:
49
49
  type: git
50
50
  name: ruby/gem_rbs_collection
51
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
51
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
52
52
  remote: https://github.com/ruby/gem_rbs_collection.git
53
53
  repo_dir: gems
54
54
  - name: ast
@@ -56,9 +56,13 @@ gems:
56
56
  source:
57
57
  type: git
58
58
  name: ruby/gem_rbs_collection
59
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
59
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
60
60
  remote: https://github.com/ruby/gem_rbs_collection.git
61
61
  repo_dir: gems
62
+ - name: base64
63
+ version: '0'
64
+ source:
65
+ type: stdlib
62
66
  - name: cgi
63
67
  version: '0'
64
68
  source:
@@ -68,7 +72,7 @@ gems:
68
72
  source:
69
73
  type: git
70
74
  name: ruby/gem_rbs_collection
71
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
75
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
72
76
  remote: https://github.com/ruby/gem_rbs_collection.git
73
77
  repo_dir: gems
74
78
  - name: date
@@ -80,7 +84,7 @@ gems:
80
84
  source:
81
85
  type: git
82
86
  name: ruby/gem_rbs_collection
83
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
87
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
84
88
  remote: https://github.com/ruby/gem_rbs_collection.git
85
89
  repo_dir: gems
86
90
  - name: json
@@ -108,7 +112,7 @@ gems:
108
112
  source:
109
113
  type: git
110
114
  name: ruby/gem_rbs_collection
111
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
115
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
112
116
  remote: https://github.com/ruby/gem_rbs_collection.git
113
117
  repo_dir: gems
114
118
  - name: optparse
@@ -120,7 +124,7 @@ gems:
120
124
  source:
121
125
  type: git
122
126
  name: ruby/gem_rbs_collection
123
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
127
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
124
128
  remote: https://github.com/ruby/gem_rbs_collection.git
125
129
  repo_dir: gems
126
130
  - name: pathname
@@ -132,7 +136,7 @@ gems:
132
136
  source:
133
137
  type: git
134
138
  name: ruby/gem_rbs_collection
135
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
139
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
136
140
  remote: https://github.com/ruby/gem_rbs_collection.git
137
141
  repo_dir: gems
138
142
  - name: rails-dom-testing
@@ -140,7 +144,7 @@ gems:
140
144
  source:
141
145
  type: git
142
146
  name: ruby/gem_rbs_collection
143
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
147
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
144
148
  remote: https://github.com/ruby/gem_rbs_collection.git
145
149
  repo_dir: gems
146
150
  - name: railties
@@ -148,7 +152,7 @@ gems:
148
152
  source:
149
153
  type: git
150
154
  name: ruby/gem_rbs_collection
151
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
155
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
152
156
  remote: https://github.com/ruby/gem_rbs_collection.git
153
157
  repo_dir: gems
154
158
  - name: rainbow
@@ -156,11 +160,11 @@ gems:
156
160
  source:
157
161
  type: git
158
162
  name: ruby/gem_rbs_collection
159
- revision: 9330d49993d18362cce9190b9596f03d1f4915f8
163
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
160
164
  remote: https://github.com/ruby/gem_rbs_collection.git
161
165
  repo_dir: gems
162
166
  - name: rbs
163
- version: 3.1.2
167
+ version: 3.1.3
164
168
  source:
165
169
  type: rubygems
166
170
  - name: rdoc
@@ -27,5 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
+ spec.add_dependency "activesupport"
30
31
  spec.add_dependency "rbs"
31
32
  end
@@ -0,0 +1,9 @@
1
+ module RbsHeuristicPrototype
2
+ module Filters
3
+ class BooleanMethodsFilter < Base
4
+ def process_module: (RBS::AST::Declarations::Module decl) -> RBS::AST::Declarations::Module
5
+ def controller_concern?: (Module mod) -> bool
6
+ def self_types_for: (Module mod) -> Array[RBS::AST::Declarations::Module::Self]
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,6 @@
1
1
  module RbsHeuristicPrototype
2
2
  class RakeTask < Rake::TaskLib
3
- FILTERS: Hash[Symbol, singleton(Filters::Base)]
3
+ FILTERS: Hash[Symbol, String]
4
4
 
5
5
  attr_reader name: Symbol
6
6
  attr_reader path: Pathname
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs_heuristic_prototype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.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-02 00:00:00.000000000 Z
11
+ date: 2023-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
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
@@ -47,6 +61,7 @@ files:
47
61
  - lib/rbs_heuristic_prototype/filters/active_model_validations_filter.rb
48
62
  - lib/rbs_heuristic_prototype/filters/base.rb
49
63
  - lib/rbs_heuristic_prototype/filters/boolean_methods_filter.rb
64
+ - lib/rbs_heuristic_prototype/filters/controller_concerns_filter.rb
50
65
  - lib/rbs_heuristic_prototype/filters/deep_module_filter.rb
51
66
  - lib/rbs_heuristic_prototype/filters/symbol_array_constants_filter.rb
52
67
  - lib/rbs_heuristic_prototype/filters/type_args_filter.rb
@@ -61,6 +76,7 @@ files:
61
76
  - sig/rbs_heuristic_prototype/filters/active_model_validations_filter.rbs
62
77
  - sig/rbs_heuristic_prototype/filters/base.rbs
63
78
  - sig/rbs_heuristic_prototype/filters/boolean_methods_filter.rbs
79
+ - sig/rbs_heuristic_prototype/filters/controller_concerns_filter.rbs
64
80
  - sig/rbs_heuristic_prototype/filters/deep_module_filter.rbs
65
81
  - sig/rbs_heuristic_prototype/filters/symbol_array_constants_filter.rbs
66
82
  - sig/rbs_heuristic_prototype/rake_task.rbs