Skip to content

Commit 2300b17

Browse files
authored
fix: avoid emitting warnings when ruby is run with -w (#1)
I've also turned on warnings for this gem's tests, to make it more obvious when this is happening in the future. Without this fix, users will see repeated messages like this: > source_file_formatter.rb:20: warning: instance variable @line_coverage not initialized
1 parent 76cc7b4 commit 2300b17

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

.rspec

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--warnings

lib/simplecov_json_formatter/source_file_formatter.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module SimpleCovJSONFormatter
44
class SourceFileFormatter
55
def initialize(source_file)
66
@source_file = source_file
7+
@line_coverage = nil
78
end
89

910
def format
@@ -17,7 +18,7 @@ def format
1718
private
1819

1920
def line_coverage
20-
@line_coverage || {
21+
@line_coverage ||= {
2122
lines: lines
2223
}
2324
end

0 commit comments

Comments
 (0)