From 766bd80fa8585fff92d75f7d9c799170d1c662a4 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 30 Dec 2020 14:00:12 -0500 Subject: [PATCH] fix: avoid emitting warnings when ruby is run with `-w` 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 --- .rspec | 1 + lib/simplecov_json_formatter/source_file_formatter.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .rspec diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..372b5ac --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--warnings diff --git a/lib/simplecov_json_formatter/source_file_formatter.rb b/lib/simplecov_json_formatter/source_file_formatter.rb index 3564c79..6f44f52 100644 --- a/lib/simplecov_json_formatter/source_file_formatter.rb +++ b/lib/simplecov_json_formatter/source_file_formatter.rb @@ -4,6 +4,7 @@ module SimpleCovJSONFormatter class SourceFileFormatter def initialize(source_file) @source_file = source_file + @line_coverage = nil end def format @@ -17,7 +18,7 @@ def format private def line_coverage - @line_coverage || { + @line_coverage ||= { lines: lines } end