Skip to content

Stop removing blank line after magic comments on replacing old_content with new_content #578

Closed
@kovalevsky

Description

@kovalevsky

Despite of several PRs related to magic comment and a blank line after the comment (#491, #524) each run of annotate removes blank line after magic comment in my models.
Before running annotate:

# frozen_string_literal: true

# == Schema Information
...

after:

# frozen_string_literal: true
# == Schema Information

A blank line is required by ruby style guides and current behavior produces endless war rubocop vs. annotate.

After a short locking into the sources, I've figured out unclear part of a regexp inside annotate_pattern method: https://github.com/ctran/annotate_models/blame/26142667a1da560e681fc0621857a160edf26007/lib/annotate/annotate_models.rb#L90

As far as I see the code removes blank line after a magic comment (according to ^(\n|\r\n)?#) and doesn't restore it.
I'd be glad to fix the regexp or another part of the code. Could you point me, why that part of the regexp is needed? Annotate works well in my cases without ^(\n|\r\n)?# part of regexp inside annotate_pattern method.

Version

  • annotate version
    2.7.4
  • rails version
    5.2.0
  • ruby version
    5.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions