From d4bc52b8cdbe5a6c5eaab45973d024161fc6fb86 Mon Sep 17 00:00:00 2001 From: ohbarye Date: Fri, 19 Nov 2021 00:39:49 +0900 Subject: [PATCH 1/2] Add test file that has global offense --- test/rdjson_formatter/testdata/global_offenses.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/rdjson_formatter/testdata/global_offenses.rb diff --git a/test/rdjson_formatter/testdata/global_offenses.rb b/test/rdjson_formatter/testdata/global_offenses.rb new file mode 100644 index 0000000..e69de29 From c609128b8c92b89a6f21d699d222a7a091c6e9e0 Mon Sep 17 00:00:00 2001 From: ohbarye Date: Fri, 19 Nov 2021 00:41:35 +0900 Subject: [PATCH 2/2] Skip global offense that does not have any location --- rdjson_formatter/rdjson_formatter.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rdjson_formatter/rdjson_formatter.rb b/rdjson_formatter/rdjson_formatter.rb index 630e608..2026a5d 100644 --- a/rdjson_formatter/rdjson_formatter.rb +++ b/rdjson_formatter/rdjson_formatter.rb @@ -16,6 +16,8 @@ def started(_target_files) def file_finished(file, offenses) offenses.each do |offense| + next if offense.location == RuboCop::Cop::Offense::NO_LOCATION + @rdjson[:diagnostics] << build_diagnostic(file, offense) end end