sorbet-rails 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +77 -0
  3. data/Gemfile +6 -0
  4. data/Gemfile.lock +176 -0
  5. data/README.md +68 -45
  6. data/Rakefile +6 -0
  7. data/SECURITY.md +5 -0
  8. data/lib/sorbet-rails/model_rbi_formatter.rb +1 -1
  9. data/lib/sorbet-rails/tasks/rails_rbi.rake +60 -0
  10. data/rbis/activerecord.rbi +133 -0
  11. data/sorbet-rails.gemspec +31 -0
  12. data/spec/model_rbi_formatter_spec.rb +54 -0
  13. data/spec/rails_helper.rb +14 -0
  14. data/spec/routes_rbi_formatter_spec.rb +21 -0
  15. data/spec/spec_helper.rb +8 -0
  16. data/spec/support/rails_app/.ruby-version +1 -0
  17. data/spec/support/rails_app/Gemfile +45 -0
  18. data/spec/support/rails_app/Gemfile.lock +139 -0
  19. data/spec/support/rails_app/README.md +24 -0
  20. data/spec/support/rails_app/Rakefile +6 -0
  21. data/spec/support/rails_app/app/channels/application_cable/channel.rb +4 -0
  22. data/spec/support/rails_app/app/channels/application_cable/connection.rb +4 -0
  23. data/spec/support/rails_app/app/controllers/application_controller.rb +2 -0
  24. data/spec/support/rails_app/app/controllers/concerns/.keep +0 -0
  25. data/spec/support/rails_app/app/controllers/test_controller.rb +5 -0
  26. data/spec/support/rails_app/app/jobs/application_job.rb +2 -0
  27. data/spec/support/rails_app/app/mailers/application_mailer.rb +4 -0
  28. data/spec/support/rails_app/app/models/application_record.rb +3 -0
  29. data/spec/support/rails_app/app/models/concerns/.keep +0 -0
  30. data/spec/support/rails_app/app/models/spell_book.rb +6 -0
  31. data/spec/support/rails_app/app/models/wand.rb +15 -0
  32. data/spec/support/rails_app/app/models/wizard.rb +14 -0
  33. data/spec/support/rails_app/app/views/layouts/mailer.html.erb +13 -0
  34. data/spec/support/rails_app/app/views/layouts/mailer.text.erb +1 -0
  35. data/spec/support/rails_app/bin/bundle +3 -0
  36. data/spec/support/rails_app/bin/rails +9 -0
  37. data/spec/support/rails_app/bin/rake +9 -0
  38. data/spec/support/rails_app/bin/setup +33 -0
  39. data/spec/support/rails_app/bin/spring +17 -0
  40. data/spec/support/rails_app/bin/update +28 -0
  41. data/spec/support/rails_app/config.ru +5 -0
  42. data/spec/support/rails_app/config/application.rb +35 -0
  43. data/spec/support/rails_app/config/boot.rb +3 -0
  44. data/spec/support/rails_app/config/cable.yml +10 -0
  45. data/spec/support/rails_app/config/credentials.yml.enc +1 -0
  46. data/spec/support/rails_app/config/database.yml +25 -0
  47. data/spec/support/rails_app/config/environment.rb +5 -0
  48. data/spec/support/rails_app/config/environments/development.rb +54 -0
  49. data/spec/support/rails_app/config/environments/production.rb +85 -0
  50. data/spec/support/rails_app/config/environments/test.rb +46 -0
  51. data/spec/support/rails_app/config/initializers/application_controller_renderer.rb +8 -0
  52. data/spec/support/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  53. data/spec/support/rails_app/config/initializers/cors.rb +16 -0
  54. data/spec/support/rails_app/config/initializers/filter_parameter_logging.rb +4 -0
  55. data/spec/support/rails_app/config/initializers/inflections.rb +16 -0
  56. data/spec/support/rails_app/config/initializers/mime_types.rb +4 -0
  57. data/spec/support/rails_app/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/support/rails_app/config/locales/en.yml +33 -0
  59. data/spec/support/rails_app/config/puma.rb +34 -0
  60. data/spec/support/rails_app/config/routes.rb +5 -0
  61. data/spec/support/rails_app/config/spring.rb +6 -0
  62. data/spec/support/rails_app/config/storage.yml +34 -0
  63. data/spec/support/rails_app/db/migrate/20190620001234_create_wizards.rb +12 -0
  64. data/spec/support/rails_app/db/migrate/20190620003037_create_wands.rb +11 -0
  65. data/spec/support/rails_app/db/migrate/20190620003739_create_spell_books.rb +8 -0
  66. data/spec/support/rails_app/db/schema.rb +39 -0
  67. data/spec/support/rails_app/db/seeds.rb +7 -0
  68. data/spec/support/rails_app/lib/tasks/.keep +0 -0
  69. data/spec/support/rails_app/log/.keep +0 -0
  70. data/spec/support/rails_app/public/robots.txt +1 -0
  71. data/spec/support/rails_app/storage/.keep +0 -0
  72. data/spec/support/rails_app/test/controllers/.keep +0 -0
  73. data/spec/support/rails_app/test/fixtures/.keep +0 -0
  74. data/spec/support/rails_app/test/fixtures/files/.keep +0 -0
  75. data/spec/support/rails_app/test/integration/.keep +0 -0
  76. data/spec/support/rails_app/test/mailers/.keep +0 -0
  77. data/spec/support/rails_app/test/models/.keep +0 -0
  78. data/spec/support/rails_app/test/test_helper.rb +10 -0
  79. data/spec/support/rails_app/tmp/.keep +0 -0
  80. data/spec/support/rails_app/vendor/.keep +0 -0
  81. data/spec/test_data/expected_routes.rbi +43 -0
  82. data/spec/test_data/expected_wizard_no_book.rbi +0 -0
  83. data/spec/test_data/models/expected_wand.rbi +174 -0
  84. data/spec/test_data/models/expected_wizard.rbi +189 -0
  85. data/spec/test_data/models/expected_wizard_wo_spellbook.rbi +189 -0
  86. metadata +338 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3f7dd83f8d099f5951a1a8bd13707c4e38d60e5
4
- data.tar.gz: 4c7e2dc570d7695826c1c88d3f6711c7600dbe57
3
+ metadata.gz: ab8c01f01bcf1f1400adb25f52d0a6c35127a206
4
+ data.tar.gz: ad481caa38ffc63d0ea5159a091ff91503c6f17b
5
5
  SHA512:
6
- metadata.gz: '0780d48a3e347edd504e6b3b2e11ca88e60118a29e25b3b0b4c931192aec27e8c2f2d1f2ddeff5c111a106a5174ed2feb8e7d462f92a59cc8a91284c9d0c48eb'
7
- data.tar.gz: 8a3af472623c72b6cf615acd4a19b52b341b82ed18392feb8e25ddcd9a10177b329d3ab77c557b1ca32dacada4216f1ac92e6dcc1503ada0fa9507a087ebf786
6
+ metadata.gz: 488ffc6eac8fec70207a86a71f13f034b55732df73ea9a3dc0aba4f694fa59eb36f98f52dee3f80267f9437484d9b165360a55b3f0033a81d8f5dd4f2bebb40e
7
+ data.tar.gz: f82f7455bafb5a375ad65b6c0d725a15e2b4e0df53fbd3a3a69d65d7089571b29afbde8befb569ba4f8f1c66b708258bf6a91dcd5d5cae6bfbaa94f50c260abf
@@ -0,0 +1,77 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ # Rails app
53
+ /spec/support/rails_app/tmp/*
54
+ /spec/support/rails_app/.bundle
55
+
56
+ # Ignore the default SQLite database.
57
+ /spec/support/rails_app/db/*.sqlite3
58
+ /spec/support/rails_app/db/*.sqlite3-journal
59
+
60
+ # Ignore all logfiles and tempfiles.
61
+ /spec/support/rails_app/log/*
62
+ /spec/support/rails_app/tmp/*
63
+ !/spec/support/rails_app/log/.keep
64
+ !/spec/support/rails_app/tmp/.keep
65
+
66
+ # Ignore uploaded files in development
67
+ /spec/support/rails_app/storage/*
68
+ !/spec/support/rails_app/storage/.keep
69
+
70
+ /spec/support/rails_app/node_modules
71
+ /spec/support/rails_app/yarn-error.log
72
+
73
+ /spec/support/rails_app/public/assets
74
+ .byebug_history
75
+
76
+ # Ignore master key for decrypting credentials and more.
77
+ /spec/support/rails_app/config/master.key
data/Gemfile CHANGED
@@ -1 +1,7 @@
1
1
  source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'simplecov', require: false
7
+ end
@@ -0,0 +1,176 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sorbet-rails (0.1.3)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actioncable (5.2.3)
10
+ actionpack (= 5.2.3)
11
+ nio4r (~> 2.0)
12
+ websocket-driver (>= 0.6.1)
13
+ actionmailer (5.2.3)
14
+ actionpack (= 5.2.3)
15
+ actionview (= 5.2.3)
16
+ activejob (= 5.2.3)
17
+ mail (~> 2.5, >= 2.5.4)
18
+ rails-dom-testing (~> 2.0)
19
+ actionpack (5.2.3)
20
+ actionview (= 5.2.3)
21
+ activesupport (= 5.2.3)
22
+ rack (~> 2.0)
23
+ rack-test (>= 0.6.3)
24
+ rails-dom-testing (~> 2.0)
25
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
26
+ actionview (5.2.3)
27
+ activesupport (= 5.2.3)
28
+ builder (~> 3.1)
29
+ erubi (~> 1.4)
30
+ rails-dom-testing (~> 2.0)
31
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
32
+ activejob (5.2.3)
33
+ activesupport (= 5.2.3)
34
+ globalid (>= 0.3.6)
35
+ activemodel (5.2.3)
36
+ activesupport (= 5.2.3)
37
+ activerecord (5.2.3)
38
+ activemodel (= 5.2.3)
39
+ activesupport (= 5.2.3)
40
+ arel (>= 9.0)
41
+ activestorage (5.2.3)
42
+ actionpack (= 5.2.3)
43
+ activerecord (= 5.2.3)
44
+ marcel (~> 0.3.1)
45
+ activesupport (5.2.3)
46
+ concurrent-ruby (~> 1.0, >= 1.0.2)
47
+ i18n (>= 0.7, < 2)
48
+ minitest (~> 5.1)
49
+ tzinfo (~> 1.1)
50
+ arel (9.0.0)
51
+ awesome_print (1.8.0)
52
+ builder (3.2.3)
53
+ byebug (11.0.1)
54
+ concurrent-ruby (1.1.5)
55
+ crass (1.0.4)
56
+ diff-lcs (1.3)
57
+ docile (1.3.2)
58
+ erubi (1.8.0)
59
+ ffi (1.11.1)
60
+ globalid (0.4.2)
61
+ activesupport (>= 4.2.0)
62
+ i18n (1.6.0)
63
+ concurrent-ruby (~> 1.0)
64
+ json (2.2.0)
65
+ listen (3.1.5)
66
+ rb-fsevent (~> 0.9, >= 0.9.4)
67
+ rb-inotify (~> 0.9, >= 0.9.7)
68
+ ruby_dep (~> 1.2)
69
+ loofah (2.2.3)
70
+ crass (~> 1.0.2)
71
+ nokogiri (>= 1.5.9)
72
+ mail (2.7.1)
73
+ mini_mime (>= 0.1.1)
74
+ marcel (0.3.3)
75
+ mimemagic (~> 0.3.2)
76
+ method_source (0.9.2)
77
+ mimemagic (0.3.3)
78
+ mini_mime (1.0.1)
79
+ mini_portile2 (2.4.0)
80
+ minitest (5.11.3)
81
+ nio4r (2.3.1)
82
+ nokogiri (1.10.3)
83
+ mini_portile2 (~> 2.4.0)
84
+ puma (3.12.1)
85
+ rack (2.0.7)
86
+ rack-test (1.1.0)
87
+ rack (>= 1.0, < 3)
88
+ rails (5.2.3)
89
+ actioncable (= 5.2.3)
90
+ actionmailer (= 5.2.3)
91
+ actionpack (= 5.2.3)
92
+ actionview (= 5.2.3)
93
+ activejob (= 5.2.3)
94
+ activemodel (= 5.2.3)
95
+ activerecord (= 5.2.3)
96
+ activestorage (= 5.2.3)
97
+ activesupport (= 5.2.3)
98
+ bundler (>= 1.3.0)
99
+ railties (= 5.2.3)
100
+ sprockets-rails (>= 2.0.0)
101
+ rails-dom-testing (2.0.3)
102
+ activesupport (>= 4.2.0)
103
+ nokogiri (>= 1.6)
104
+ rails-html-sanitizer (1.0.4)
105
+ loofah (~> 2.2, >= 2.2.2)
106
+ railties (5.2.3)
107
+ actionpack (= 5.2.3)
108
+ activesupport (= 5.2.3)
109
+ method_source
110
+ rake (>= 0.8.7)
111
+ thor (>= 0.19.0, < 2.0)
112
+ rake (12.3.2)
113
+ rb-fsevent (0.10.3)
114
+ rb-inotify (0.10.0)
115
+ ffi (~> 1.0)
116
+ rspec (3.8.0)
117
+ rspec-core (~> 3.8.0)
118
+ rspec-expectations (~> 3.8.0)
119
+ rspec-mocks (~> 3.8.0)
120
+ rspec-core (3.8.1)
121
+ rspec-support (~> 3.8.0)
122
+ rspec-expectations (3.8.4)
123
+ diff-lcs (>= 1.2.0, < 2.0)
124
+ rspec-support (~> 3.8.0)
125
+ rspec-mocks (3.8.1)
126
+ diff-lcs (>= 1.2.0, < 2.0)
127
+ rspec-support (~> 3.8.0)
128
+ rspec-rails (3.8.2)
129
+ actionpack (>= 3.0)
130
+ activesupport (>= 3.0)
131
+ railties (>= 3.0)
132
+ rspec-core (~> 3.8.0)
133
+ rspec-expectations (~> 3.8.0)
134
+ rspec-mocks (~> 3.8.0)
135
+ rspec-support (~> 3.8.0)
136
+ rspec-support (3.8.2)
137
+ ruby_dep (1.5.0)
138
+ simplecov (0.16.1)
139
+ docile (~> 1.1)
140
+ json (>= 1.8, < 3)
141
+ simplecov-html (~> 0.10.0)
142
+ simplecov-html (0.10.2)
143
+ sprockets (3.7.2)
144
+ concurrent-ruby (~> 1.0)
145
+ rack (> 1, < 3)
146
+ sprockets-rails (3.2.1)
147
+ actionpack (>= 4.0)
148
+ activesupport (>= 4.0)
149
+ sprockets (>= 3.0.0)
150
+ sqlite3 (1.4.1)
151
+ thor (0.20.3)
152
+ thread_safe (0.3.6)
153
+ tzinfo (1.2.5)
154
+ thread_safe (~> 0.1)
155
+ websocket-driver (0.7.1)
156
+ websocket-extensions (>= 0.1.0)
157
+ websocket-extensions (0.1.4)
158
+
159
+ PLATFORMS
160
+ ruby
161
+
162
+ DEPENDENCIES
163
+ awesome_print (>= 1.8.0)
164
+ bundler (>= 1.3.0)
165
+ byebug (>= 11.0.1)
166
+ listen (>= 3.1.5)
167
+ puma (>= 3.12.1)
168
+ rails (>= 5.2.3)
169
+ rspec (~> 3.8)
170
+ rspec-rails (>= 3.8.2)
171
+ simplecov
172
+ sorbet-rails!
173
+ sqlite3 (>= 1.4.1)
174
+
175
+ BUNDLED WITH
176
+ 2.0.1
data/README.md CHANGED
@@ -1,50 +1,50 @@
1
1
  # sorbet-rails
2
- Set of tools to make sorbet work with rails seamlessly.
2
+ A set of tools to make the [Sorbet](https://sorbet.org) type checker work with Ruby on Rails seamlessly.
3
3
 
4
- This gem adds a few rake tasks to generate RBI for dynamic methods generated by Rails. It also includes sigs for related Rails classes. The generated rbis are added to `sorbet/rails-rbi/` folder.
4
+ This gem adds a few Rake tasks to generate Ruby Interface (RBI) files for dynamic methods generated by Rails. It also includes signatures for related Rails classes. The RBI files are added to a `sorbet/rails-rbi/` folder.
5
5
 
6
- Please feel free to send PR requests or file issues to improve the functionality of the gem!
6
+ ## Initial Setup
7
7
 
8
- ## Initial setup
8
+ 1. Install the gem and set up Sorbet, up to being able to run `srb tc`. Follow the steps [here](https://sorbet.org/docs/adopting).
9
9
 
10
- Following the steps below to setup the rbis after `srb tc`
11
- 1. Include ActiveRecord RBI
12
- ```
13
- $ srb tc sorbet-typed
14
- ```
15
- 2. Generate routes RBI
10
+ 2. Include the ActiveRecord RBI file:
11
+ ```sh
12
+ $ srb rbi sorbet-typed
16
13
  ```
14
+ 3. Generate RBI files for routes and models:
15
+ ```sh
17
16
  $ rake rails_rbi:routes
18
- ```
19
- 3. Generate models RBI
20
- ```
21
17
  $ rake rails_rbi:models
22
18
  ```
23
- 4. Auto-upgrade the typecheck level of files
19
+ 4. Auto-upgrade the typecheck level of files:
20
+ ```sh
21
+ $ srb tc --suggest-typed --typed=strict --error-white-list=7022 --autocorrect
24
22
  ```
25
- $ srb tc --suggest-typed --typed=strict --error-white-list=7022 -a
26
- ```
27
- Because we've generated RBI files for models & routes, a lot more files should be type-checkable now
23
+ Because we've generated RBI files for routes and models, a lot more files should be type-checkable now.
28
24
 
29
- ## ActiveRecord RBI
25
+ ## RBI Files
30
26
 
31
- There are ActiveRecord RBI that we vendor with this gem. Please run `srb tc sorbet-typed` to include the provided RBI in your `sorbet/rbi_list`
27
+ ### ActiveRecord RBI
32
28
 
33
- ## Routes RBI
34
- The following rake task generates `_path` and `_url` methods for all named routes defined in `routes.rb`
35
- ```
36
- rake rails_rbi:routes
37
- ```
38
- ## Models RBI
39
- The following rake task generates rbi files for all models in the Rails App (all descendants of ActiveRecord::Base)
40
- ```
41
- rake rails_rbi:models
29
+ There is an ActiveRecord RBI file that we vendor with this gem. Run `srb rbi sorbet-typed` to include the provided RBI file in your `sorbet/rbi_list`.
30
+
31
+ ### Routes RBI
32
+
33
+ This Rake task generates an RBI file defining `_path` and `_url` methods for all named routes in `routes.rb`:
34
+ ```sh
35
+ $ rake rails_rbi:routes
42
36
  ```
43
- You can also regenerate rbi files for specific models
37
+ ### Models RBI
38
+
39
+ This Rake task generates RBI files for all models in the Rails application (all descendants of `ActiveRecord::Base`):
40
+ ```sh
41
+ $ rake rails_rbi:models
44
42
  ```
45
- rake rails_rbi:models[ModelName,AnotherOne,...]
43
+ You can also regenerate RBI files for specific models:
44
+ ```sh
45
+ $ rake rails_rbi:models[ModelName,AnotherOne,...]
46
46
  ```
47
- At the moment, the generation task generate the following signatures
47
+ The generation task currently creates the following signatures:
48
48
  - Column getters & setters
49
49
  - Associations getters & setters
50
50
  - Enum values, checkers & scopes
@@ -52,44 +52,67 @@ At the moment, the generation task generate the following signatures
52
52
  - Model relation class
53
53
 
54
54
  ## Tips & Tricks
55
+
55
56
  ### `find`, `first` and `last`
56
- These 3 methods can either return a single nilable record or an array of records. Sorbet does not allow us to define multiple sigs for a function. It doesn't support defining one function sig that has varying returning value depending on the input param type. We opt to define the most commonly used sig for these methods, and monkey-patch new functions for the secondary use.
57
+
58
+ These 3 methods can either return a single nilable record or an array of records. Sorbet does not allow us to define multiple signatures for a function. It doesn't support defining one function signature that has varying returning value depending on the input parameter type. We opt to define the most commonly used signature for these methods, and monkey-patch new functions for the secondary use case.
57
59
 
58
60
  In short:
59
- - Use `find`, `first` and `last` to fetch a single record
61
+ - Use `find`, `first` and `last` to fetch a single record.
60
62
  - Use `find_n`, `first_n`, `last_n` to fetch an array of records.
61
63
 
62
64
  ### `find_by_<attributes>`, `<attribute>_changed?`, etc.
63
- Rails supports dynamic methods based on attribute names, such as `find_by_<attribute>`, `<attribute>_changed?`, etc. They all have static counterparts. Instead of generating all possible dynamic methods that Rails support, we recommend to use of the static version of these methods instead (also recommended by RuboCop). We've added sigs for th
64
65
 
65
- Following are the list of attribute dynamic methods and their static counterpart. The static methods have proper sigs.
66
+ Rails supports dynamic methods based on attribute names, such as `find_by_<attribute>`, `<attribute>_changed?`, etc. They all have static counterparts. Instead of generating all possible dynamic methods that Rails support, we recommend to use of the static version of these methods instead (also recommended by RuboCop).
67
+
68
+ Following are the list of attribute dynamic methods and their static counterparts. The static methods have proper signatures:
66
69
  - `find_by_<attributes>` -> `find_by(<attributes>)`
67
70
  - `find_by_<attributes>!` -> `find_by!(<attributes>)`
68
71
  - `<attribute>_changed?` -> `attribute_changed?(<attribute>)`
69
72
  - `saved_change_to_<attribute>?` -> `saved_change_to_attribute?(<attribute>)`
70
73
 
71
74
  ### `after_commit` and other callbacks
72
- Consider codemod-ing `after_commit` callbacks to use instance method functions. Sorbet doesn't support binding an optional block with a different context. Because of this, when using a callback with a custom block, the block is evaluated in the wrong context (Class-level context).
73
75
 
74
- ```
76
+ Consider converting `after_commit` callbacks to use instance method functions. Sorbet doesn't support binding an optional block with a different context. Because of this, when using a callback with a custom block, the block is evaluated in the wrong context (Class-level context). Refer to [this page](https://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html) for a full list of callbacks available in Rails.
77
+
78
+ Before:
79
+ ```ruby
75
80
  after_commit do ... end
76
81
  ```
77
- codemod to
78
- ```
82
+ After:
83
+ ```ruby
79
84
  after_commit :after_commit
80
85
  def after_commit
81
86
  ...
82
87
  end
83
88
  ```
84
89
 
85
- I've created a gist with codemod commands to convert the code automatically
86
- https://gist.github.com/manhhung741/d2e0a8f9c4178f328b241dd8b28ccc67
90
+ If you wanted to make these changes using [Codemod](https://github.com/facebook/codemod), try these commands:
91
+ ```shell
92
+ # from methods like after_commit do <...> end
93
+ codemod -d app/models/ --extensions rb \
94
+ '(\s*)(before|after)_(validation|save|create|commit|find|initialize|destroy) do' \
95
+ '\1\2_\3 :\2_\3\n\1def \2_\3'
87
96
 
88
- See this link for a full list of callbacks available in Rails:
89
- https://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
97
+ # from methods like after_commit { <...> }
98
+ codemod -d app/models/ --extensions rb \
99
+ '(\s*)(before|after)_(validation|save|create|commit|find|initialize|destroy) \{ (.*) \}' \
100
+ '\1\2_\3 :\2_\3\n\1def \2_\3\n\1\1\4\n\1end'
101
+ ```
102
+ Note that Codemod's preview may show that the indentation is off, but it works.
90
103
 
91
104
  ### Look for `# typed: ignore` files
92
105
 
93
- Because sorbet initial setup tries to flag files at the typecheck level that generates 0 errors, there may be files in your repository that is `# typed: ignore`. This is because sometimes Rails allow very dynamic code that Sorbet does not regard as typecheck-able.
106
+ Because Sorbet's initial setup tries to flag files at whichever typecheck level generates 0 errors, there may be files in your repository that are `# typed: ignore`. This is because sometimes Rails allows very dynamic code that Sorbet does not believe it can typecheck.
107
+
108
+ It is worth going through the list of files that is ignored and resolve them (and auto upgrade the types of other files; see [initial setup](#initial-setup) above). Usually this will make many more files able to be typechecked.
109
+
110
+ ## Contributing
111
+
112
+ Contributions and ideas are welcome! Please don't hesitate to open an issue or send a pull request to improve the functionality of this gem.
113
+
114
+ This project adheres to the Contributor Covenant [code of conduct](https://github.com/chanzuckerberg/.github/tree/master/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to opensource@chanzuckerberg.com.
115
+
116
+ ## License
94
117
 
95
- It is worth going through the list of files that is ignored and resolve them (and auto upgrade the types of other files -- see Initial Setup #4). Usually this will resolve in many more files typecheckable.
118
+ [MIT](https://github.com/chanzuckerberg/sorbet-rails/blob/master/LICENSE)
@@ -0,0 +1,6 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ # Reporting Security Vulnerabilities
2
+
3
+ The Chan Zuckerberg Initiative takes security issues seriously. We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions.
4
+
5
+ If you believe you have found a security issue, please contact us at security@chanzuckerberg.com.