Skip to content

Commit

Permalink
Fix files doing files => included/excluded themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Jan 30, 2024
1 parent a282f82 commit ac76775
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
6 changes: 4 additions & 2 deletions lib/credo/check/design/skip_test_without_comment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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*\#.*$/
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/check/refactor/pass_async_in_test_cases.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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: """
Expand Down
24 changes: 8 additions & 16 deletions lib/credo/check/warning/wrong_test_file_extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit ac76775

Please sign in to comment.