Class: RuboCop::Cop::Style::BlockComments
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Style::BlockComments
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/style/block_comments.rb
Overview
Looks for uses of block comments (=begin…=end).
Constant Summary collapse
- MSG =
'Do not use block comments.'
- BEGIN_LENGTH =
"=begin\n".length
- END_LENGTH =
"\n=end".length
Instance Method Summary collapse
Methods included from AutoCorrector
Instance Method Details
#on_new_investigation ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rubocop/cop/style/block_comments.rb', line 27 def on_new_investigation processed_source.comments.each do |comment| next unless comment.document? add_offense(comment) do |corrector| eq_begin, eq_end, contents = parts(comment) corrector.remove(eq_begin) unless contents.empty? corrector.replace( contents, contents.source.gsub(/\A/, '# ').gsub("\n\n", "\n#\n").gsub(/\n(?=[^#])/, "\n# ") ) end corrector.remove(eq_end) end end end |