Sorbet "typed" comment being deleted
Opened this issue · 5 comments
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
sorbet/sorbet#952
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