Sha256: 89bedf3eadf3af390c0c1da67f558a3542f1cff51bc7a60ffd82f40b37330f26
Contents?: true
Size: 1.38 KB
Versions: 8
Compression:
Stored size: 1.38 KB
Contents
# encoding: utf-8 module RuboCop module Cop module Style # This cop looks for uses of block comments (=begin...=end). class BlockComments < Cop MSG = 'Do not use block comments.' def investigate(processed_source) processed_source.comments.each do |comment| add_offense(comment, :expression) if comment.document? end end def autocorrect(comment) expr = comment.loc.expression eq_begin = expr.resize("=begin\n".length) eq_end = Parser::Source::Range.new(expr.source_buffer, expr.end_pos - "\n=end".length, expr.end_pos) contents = Parser::Source::Range.new(expr.source_buffer, eq_begin.end_pos, eq_end.begin_pos) @corrections << lambda do |corrector| corrector.remove(eq_begin) unless contents.length == 0 corrector.replace(contents, contents.source .gsub(/\A/, '# ') .gsub(/\n\n/, "\n#\n") .gsub(/\n(?=[^\z#])/, "\n# ")) end corrector.remove(eq_end) end end end end end end
Version data entries
8 entries across 8 versions & 2 rubygems