annotate_models icon indicating copy to clipboard operation
annotate_models copied to clipboard

Sorbet "typed" comment being deleted

Open hdamico opened this issue 4 years ago • 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 image After running annotate for the first time and before adding new column image After adding new column image

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

hdamico avatar Sep 14 '21 20:09 hdamico

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?

hdamico avatar Sep 14 '21 20:09 hdamico

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 avatar Jan 07 '22 03:01 yskkin

@yskkin I found a workaround by modifying some lines. Check my fork.

hdamico avatar Jan 10 '22 11:01 hdamico

@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!

matteolc avatar Aug 04 '22 10:08 matteolc

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

ccarse avatar Jan 26 '23 14:01 ccarse