Skip to content

Commit

Permalink
fix: avoid emitting warnings when ruby is run with -w (#1)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
flavorjones committed May 2, 2021
1 parent 76cc7b4 commit 2300b17
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--warnings
3 changes: 2 additions & 1 deletion lib/simplecov_json_formatter/source_file_formatter.rb
Expand Up @@ -4,6 +4,7 @@ module SimpleCovJSONFormatter
class SourceFileFormatter
def initialize(source_file)
@source_file = source_file
@line_coverage = nil
end

def format
Expand All @@ -17,7 +18,7 @@ def format
private

def line_coverage
@line_coverage || {
@line_coverage ||= {
lines: lines
}
end
Expand Down

0 comments on commit 2300b17

Please sign in to comment.