From ac76775a37bceea6afe66c00d1647fe60c46d755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Tue, 30 Jan 2024 08:26:28 +0100 Subject: [PATCH] Fix files doing files => included/excluded themselves --- .../check/design/skip_test_without_comment.ex | 6 +++-- .../refactor/pass_async_in_test_cases.ex | 2 +- .../warning/wrong_test_file_extension.ex | 24 +++++++------------ 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/credo/check/design/skip_test_without_comment.ex b/lib/credo/check/design/skip_test_without_comment.ex index aa9cc78f7..22592142b 100644 --- a/lib/credo/check/design/skip_test_without_comment.ex +++ b/lib/credo/check/design/skip_test_without_comment.ex @@ -2,6 +2,9 @@ defmodule Credo.Check.Design.SkipTestWithoutComment do use Credo.Check, id: "EX2003", base_priority: :normal, + param_defaults: [ + files: %{included: ["test/**/*_test.exs"]} + ], explanations: [ check: """ Skipped tests should have a comment documenting why the test is skipped. @@ -24,8 +27,7 @@ defmodule Credo.Check.Design.SkipTestWithoutComment do While the pure existence of a comment does not change anything per se, a thoughtful comment can improve the odds for future iteration on the issue. """ - ], - param_defaults: [included: ["test/**/*_test.exs"]] + ] @tag_skip_regex ~r/^\s*\@tag :skip\s*$/ @comment_regex ~r/^\s*\#.*$/ diff --git a/lib/credo/check/refactor/pass_async_in_test_cases.ex b/lib/credo/check/refactor/pass_async_in_test_cases.ex index dfab01d80..58c2beda5 100644 --- a/lib/credo/check/refactor/pass_async_in_test_cases.ex +++ b/lib/credo/check/refactor/pass_async_in_test_cases.ex @@ -3,7 +3,7 @@ defmodule Credo.Check.Refactor.PassAsyncInTestCases do id: "EX4031", base_priority: :normal, param_defaults: [ - files: %{included: ["**/*_test.exs"]} + files: %{included: ["test/**/*_test.exs"]} ], explanations: [ check: """ diff --git a/lib/credo/check/warning/wrong_test_file_extension.ex b/lib/credo/check/warning/wrong_test_file_extension.ex index df0d2d72b..b90ee7ded 100644 --- a/lib/credo/check/warning/wrong_test_file_extension.ex +++ b/lib/credo/check/warning/wrong_test_file_extension.ex @@ -2,7 +2,9 @@ defmodule Credo.Check.Warning.WrongTestFileExtension do use Credo.Check, id: "EX5025", base_priority: :high, - param_defaults: [included: ["test/**/*_test.ex"]], + param_defaults: [ + files: %{included: ["test/**/*_test.exs"]} + ], explanations: [ check: """ Invoking mix test from the command line will run the tests in each file @@ -14,21 +16,14 @@ defmodule Credo.Check.Warning.WrongTestFileExtension do """ ] - @test_files_with_ex_ending_regex ~r/test\/.*\/.*_test.ex$/ - alias Credo.SourceFile @doc false - def run(%SourceFile{filename: filename} = source_file, params \\ []) do - issue_meta = IssueMeta.for(source_file, params) - - if matches?(filename, @test_files_with_ex_ending_regex) do - issue_meta - |> issue_for() - |> List.wrap() - else - [] - end + def run(%SourceFile{} = source_file, params \\ []) do + source_file + |> IssueMeta.for(params) + |> issue_for() + |> List.wrap() end defp issue_for(issue_meta) do @@ -39,7 +34,4 @@ defmodule Credo.Check.Warning.WrongTestFileExtension do trigger: "" ) end - - defp matches?(directory, path) when is_binary(path), do: String.starts_with?(directory, path) - defp matches?(directory, %Regex{} = regex), do: Regex.match?(regex, directory) end