Skip to content

Commit

Permalink
Output line numbers instead of Infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas054 committed Nov 2, 2014
1 parent c81f510 commit 1716d4e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion lib/rubocop/cop/style/disable_cop_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def investigate(processed_source)
column_range)
line_ranges.each do |disabled_range|
next unless disabled_range.include?(comment.loc.line)
add_offense(r, r, format(MSG, cop, disabled_range))

add_offense(r, r, format(MSG, cop,
tweaked_range(disabled_range,
processed_source)))
end
end
end
Expand All @@ -38,6 +41,15 @@ def column_range(comment, cop)
column += comment.loc.column
column...(column + cop_name.length)
end

# Replace Infinity with the line number of the last line.
def tweaked_range(range, processed_source)
if range.end == Float::INFINITY
(range.begin..processed_source.lines.size)
else
range
end
end
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/style/disable_cop_comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'def m',
'end'])
expect(cop.messages)
.to eq(['Cop Metrics/MethodLength disabled on lines 1..Infinity.'])
.to eq(['Cop Metrics/MethodLength disabled on lines 1..3.'])
expect(cop.highlights).to eq(['Metrics/MethodLength'])
end

Expand All @@ -19,8 +19,8 @@
'def m',
'end'])
expect(cop.messages)
.to eq(['Cop Metrics/MethodLength disabled on lines 1..Infinity.',
'Cop Metrics/ClassLength disabled on lines 1..Infinity.'])
.to eq(['Cop Metrics/MethodLength disabled on lines 1..3.',
'Cop Metrics/ClassLength disabled on lines 1..3.'])
expect(cop.highlights).to eq(%w(MethodLength ClassLength))
end

Expand Down

0 comments on commit 1716d4e

Please sign in to comment.