diff --git a/test/credo/check/warning/unused_enum_operation_test.exs b/test/credo/check/warning/unused_enum_operation_test.exs index da8aaaa4b..0e820a436 100644 --- a/test/credo/check/warning/unused_enum_operation_test.exs +++ b/test/credo/check/warning/unused_enum_operation_test.exs @@ -125,6 +125,22 @@ defmodule Credo.Check.Warning.UnusedEnumOperationTest do |> refute_issues() end + test "it should NOT report a violation when inside a catch" do + """ + defmodule CredoSampleModule do + defp category_body(nil) do + throw [1, 2, 3, 4] + catch + values -> + Enum.map(values, &(&1 + 1)) + end + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report a violation when inside of assignment" do """ defmodule CredoSampleModule do diff --git a/test/credo/check/warning/unused_file_operation_test.exs b/test/credo/check/warning/unused_file_operation_test.exs index 2d046f8fc..6b59174d3 100644 --- a/test/credo/check/warning/unused_file_operation_test.exs +++ b/test/credo/check/warning/unused_file_operation_test.exs @@ -125,6 +125,22 @@ defmodule Credo.Check.Warning.UnusedFileOperationTest do |> refute_issues() end + test "it should NOT report a violation when inside a catch" do + """ + defmodule CredoSampleModule do + defp category_body(nil) do + throw [1, 2, 3, 4] + catch + values -> + File.stat(values) + end + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report a violation when inside of assignment" do """ defmodule CredoSampleModule do diff --git a/test/credo/check/warning/unused_keyword_operation_test.exs b/test/credo/check/warning/unused_keyword_operation_test.exs index 578424af6..a53afa938 100644 --- a/test/credo/check/warning/unused_keyword_operation_test.exs +++ b/test/credo/check/warning/unused_keyword_operation_test.exs @@ -132,6 +132,22 @@ defmodule Credo.Check.Warning.UnusedKeywordOperationTest do |> refute_issues() end + test "it should NOT report a violation when inside a catch" do + """ + defmodule CredoSampleModule do + defp category_body(nil) do + throw [1, 2, 3, 4] + catch + values -> + Keyword.take(values, 2) + end + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report a violation when inside of assignment" do """ defmodule CredoSampleModule do diff --git a/test/credo/check/warning/unused_list_operation_test.exs b/test/credo/check/warning/unused_list_operation_test.exs index 03e980d1f..c5a1c0ad5 100644 --- a/test/credo/check/warning/unused_list_operation_test.exs +++ b/test/credo/check/warning/unused_list_operation_test.exs @@ -125,6 +125,22 @@ defmodule Credo.Check.Warning.UnusedListOperationTest do |> refute_issues() end + test "it should NOT report a violation when inside a catch" do + """ + defmodule CredoSampleModule do + defp category_body(nil) do + throw [1, 2, 3, 4] + catch + values -> + List.delete_at(values, 2) + end + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report a violation when inside of assignment" do """ defmodule CredoSampleModule do diff --git a/test/credo/check/warning/unused_path_operation_test.exs b/test/credo/check/warning/unused_path_operation_test.exs index eb43d76e7..5f3f52295 100644 --- a/test/credo/check/warning/unused_path_operation_test.exs +++ b/test/credo/check/warning/unused_path_operation_test.exs @@ -151,6 +151,22 @@ defmodule Credo.Check.Warning.UnusedPathOperationTest do |> refute_issues() end + test "it should NOT report a violation when inside a catch" do + """ + defmodule CredoSampleModule do + defp category_body(nil) do + throw [1, 2, 3, 4] + catch + values -> + Path.join(values) + end + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report a violation when inside of assignment" do """ defmodule CredoSampleModule do diff --git a/test/credo/check/warning/unused_regex_operation_test.exs b/test/credo/check/warning/unused_regex_operation_test.exs index 511fb1364..4c00ac0f0 100644 --- a/test/credo/check/warning/unused_regex_operation_test.exs +++ b/test/credo/check/warning/unused_regex_operation_test.exs @@ -125,6 +125,22 @@ defmodule Credo.Check.Warning.UnusedRegexOperationTest do |> refute_issues() end + test "it should NOT report a violation when inside a catch" do + """ + defmodule CredoSampleModule do + defp category_body(nil) do + throw [1, 2, 3, 4] + catch + values -> + Regex.delete_at(values, 2) + end + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report a violation when inside of assignment" do """ defmodule CredoSampleModule do diff --git a/test/credo/check/warning/unused_string_operation_test.exs b/test/credo/check/warning/unused_string_operation_test.exs index dd0931d65..d7fd73cfc 100644 --- a/test/credo/check/warning/unused_string_operation_test.exs +++ b/test/credo/check/warning/unused_string_operation_test.exs @@ -127,6 +127,22 @@ defmodule Credo.Check.Warning.UnusedStringOperationTest do |> refute_issues() end + test "it should NOT report a violation when inside a catch" do + """ + defmodule CredoSampleModule do + defp category_body(nil) do + throw [1, 2, 3, 4] + catch + values -> + String.to_atom(values) + end + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report a violation when inside of assignment" do """ defmodule CredoSampleModule do diff --git a/test/credo/check/warning/unused_tuple_operation_test.exs b/test/credo/check/warning/unused_tuple_operation_test.exs index cf6c29896..f018b220f 100644 --- a/test/credo/check/warning/unused_tuple_operation_test.exs +++ b/test/credo/check/warning/unused_tuple_operation_test.exs @@ -125,6 +125,22 @@ defmodule Credo.Check.Warning.UnusedTupleOperationTest do |> refute_issues() end + test "it should NOT report a violation when inside a catch" do + """ + defmodule CredoSampleModule do + defp category_body(nil) do + throw [1, 2, 3, 4] + catch + values -> + Tuple.delete_at(values, 2) + end + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report a violation when inside of assignment" do """ defmodule CredoSampleModule do