Skip to content

Commit

Permalink
Avoid use of each_comment
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre authored and bbatsov committed Aug 10, 2020
1 parent d31b664 commit 7fd90a4
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/comment_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def directive_on_comment_line?(comment)
def each_directive
return if processed_source.comments.nil?

processed_source.each_comment do |comment|
processed_source.comments.each do |comment|
directive = directive_parts(comment)
next unless directive

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/comment_indentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CommentIndentation < Cop
'instead of %<correct_comment_indentation>d).'

def investigate(processed_source)
processed_source.each_comment { |comment| check(comment) }
processed_source.comments.each { |comment| check(comment) }
end

def autocorrect(comment)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/leading_comment_space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LeadingCommentSpace < Cop
MSG = 'Missing space after `#`.'

def investigate(processed_source)
processed_source.each_comment do |comment|
processed_source.comments.each do |comment|
next unless /\A#+[^#\s=:+-]/.match?(comment.text)
next if comment.loc.line == 1 && allowed_on_first_line?(comment)
next if doxygen_comment_style?(comment)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/migration/department_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DepartmentName < Base
DISABLING_COPS_CONTENT_TOKEN = %r{[A-z]+/[A-z]+|all}.freeze

def on_new_investigation
processed_source.each_comment do |comment|
processed_source.comments.each do |comment|
next if comment.text !~ DISABLE_COMMENT_FORMAT

offset = Regexp.last_match(1).length
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/ascii_comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AsciiComments < Base
MSG = 'Use only ascii symbols in comments.'

def on_new_investigation
processed_source.each_comment do |comment|
processed_source.comments.each do |comment|
next if comment.text.ascii_only?
next if only_allowed_non_ascii_chars?(comment.text)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/block_comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BlockComments < Base
END_LENGTH = "\n=end".length

def on_new_investigation
processed_source.each_comment do |comment|
processed_source.comments.each do |comment|
next unless comment.document?

add_offense(comment) do |corrector|
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/commented_keyword.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CommentedKeyword < Cop
'`%<keyword>s` keyword.'

def investigate(processed_source)
processed_source.each_comment do |comment|
processed_source.comments.each do |comment|
add_offense(comment) if offensive?(comment)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/inline_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InlineComment < Base
MSG = 'Avoid trailing inline comments.'

def on_new_investigation
processed_source.each_comment do |comment|
processed_source.comments.each do |comment|
next if comment_line?(processed_source[comment.loc.line - 1]) ||
comment.text.match?(/\A# rubocop:(enable|disable)/)

Expand Down

0 comments on commit 7fd90a4

Please sign in to comment.