Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndentationWidth auto-correct breaks block comments #1117

Closed
andreaseger opened this issue May 27, 2014 · 5 comments
Closed

IndentationWidth auto-correct breaks block comments #1117

andreaseger opened this issue May 27, 2014 · 5 comments
Assignees
Labels

Comments

@andreaseger
Copy link
Contributor

So I currently starting to use rubocop on a huge and quite old codebase(>4k files) and as usually thats when bugs starting to appear.
This one is about the IndentationWidth auto-correct code. Have a look at this minimal example:

Before:

module Foo
class Bar
=begin
This is a nice long
comment
which spans a few lines
=end
  def baz
    do_something
  end
end
end

Then I run this command on the file rubocop --only IndentationWidth --auto-correct block_comment_rubocop_example.rb
After the file looks like this and is obviously broken.

module Foo
  class Bar
  =begin
  This is a nice long
  comment
  which spans a few lines
  =end
    def baz
      do_something
    end
  end
end
> rubocop -V
0.22.0 (using Parser 2.1.9, running on ruby 2.1.2 x86_64-linux)

(I don't want to discuss the use of block comments, as mentioned old and huge codebase)

@bbatsov
Copy link
Collaborator

bbatsov commented May 27, 2014

I haven't seen those in a while. :-) @jonas054 Would you, please, handle this? I'm also thinking we should add auto-correct support to our block comments cop to convert them to regular comments.

@bbatsov bbatsov added the bug label May 27, 2014
@andreaseger
Copy link
Contributor Author

Found a similar issue with heredoc

Before:

module Foo
module Bar
  SOMETHING = <<GOO
text
more text
foo
GOO
  def baz
    do_something
  end
end
end

After rubocop --only IndentationWidth --auto-correct heredoc_rubocop_bug.rb

module Foo
  module Bar
    SOMETHING = <<GOO
  text
  more text
  foo
  GOO
    def baz
      do_something
    end
  end
end

Tell me if I should create a separate issue for this one. For me this seems to be the same core issue.

@andreaseger
Copy link
Contributor Author

Another one related to heredoc, this time AlignArray introduced the problems - I still think its the same issue as all these cops use the AutocorrectAlignment module.

Before

var = [
       { :type => 'something',
         :sql => <<EOF
Select something
from atable
EOF
       },
      { :type => 'something',
        :sql => <<EOF
Select something
from atable
EOF
      }
]

After rubocop --only AlignArray --auto-correct heredoc_rubocop_bug2.rb

var = [
       { :type => 'something',
         :sql => <<EOF
Select something
from atable
EOF
       },
       { :type => 'something',
         :sql => <<EOF
 Select something
 from atable
 EOF
       }
]

jonas054 added a commit to jonas054/rubocop that referenced this issue May 28, 2014
Make ordinary comments from block comments. Related to rubocop#1117.
@andreaseger
Copy link
Contributor Author

thanks for the quick fix for the block comment issue. shall I open a new issue for the two heredoc issues I listed here?

@bbatsov
Copy link
Collaborator

bbatsov commented May 29, 2014

Yes. Probably @jonas054 missed those. —
Sent from Mailbox

On Thu, May 29, 2014 at 1:06 PM, Eger Andreas notifications@github.com
wrote:

thanks for the quick fix for the block comment issue. shall I open a new issue for the two heredoc issues I listed here?

Reply to this email directly or view it on GitHub:
#1117 (comment)

buehmann added a commit to buehmann/rubocop that referenced this issue Jul 6, 2019
The earlier solution simply avoided auto-correcting every node that
contains a block comment. This solution indents as usual but leaves
block comments untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants