Sorbet "typed" comment being deleted
Hi everyone! I am getting a weird behavior whenever I have typed comment from Sorbet at the top. When I run rake db:migrate it moves the typed comment at the bottom of the annotations and then if I add a new column and run rake db:migrate again, it deletes the typed comment.
Example:
Before adding annotate gem
After running annotate for the first time and before adding new column
After adding new column

Commands
$ rake db:migrate
$ rails g migration migration_that_adds_a_new_column
$ rake db:migrate
Version
- annotate version - 3.1.1
- rails version - 6.0.1
- ruby version - 2.6.5
I see that it deletes every comment that is below the annotations unless there is an empty line after the annotations, but on the first run it deletes empty lines, is that expected?
Even if typed is considered as magic comment, this form is invalid as magic comment
https://github.com/sorbet/sorbet/issues/952
https://github.com/ctran/annotate_models/blob/786394947c041f781df2ee0ea003e09452fa9dba/lib/annotate/annotate_models.rb#L42
@yskkin I found a workaround by modifying some lines. Check my fork.
@ctran Any chance of having @hdamico fork merged? We'd really like to use this gem but since it removes all Sorbet # typed.. comments it's a blocker.
Happy to help if you need to. Thanks!
I added the following to config/initializers/annotate_override.rb, this way I don't have to maintain a fork:
if Rails.env.development?
require "annotate"
module AnnotateModels
MAGIC_COMMENT_MATCHER = Regexp.new(/(^#\s*encoding:.*(?:\n|r\n))|(^# coding:.*(?:\n|\r\n))|(^# -\*- coding:.*(?:\n|\r\n))|(^# -\*- encoding\s?:.*(?:\n|\r\n))|(^#\s*frozen_string_literal:.+(?:\n|\r\n))|(^# -\*- frozen_string_literal\s*:.+-\*-(?:\n|\r\n))|(^#\s*typed:.+(?:\n|\r\n))/).freeze
end
end