Skip to content

Commit

Permalink
Fix error in ModuleDependencies
Browse files Browse the repository at this point in the history
Refs #1067
  • Loading branch information
rrrene committed Dec 18, 2023
1 parent dea11ac commit a9f1d70
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/credo/check/refactor/module_dependencies.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Credo.Check.Refactor.ModuleDependencies do

max_deps = Params.get(params, :max_deps, __MODULE__)
dependency_namespaces = Params.get(params, :dependency_namespaces, __MODULE__)
excluded_namespaces = Params.get(params, :excluded_namespaces, __MODULE__)
excluded_namespaces = params |> Params.get(:excluded_namespaces, __MODULE__) |> Enum.map(&to_string/1)
excluded_paths = Params.get(params, :excluded_paths, __MODULE__)

case ignore_path?(source_file.filename, excluded_paths) do
Expand Down
55 changes: 43 additions & 12 deletions test/credo/check/refactor/module_dependencies_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ defmodule Credo.Check.Refactor.ModuleDependenciesTest do
|> refute_issues()
end

#
# cases raising issues
#

test "it should report a violation" do
test "it should NOT report a violation on non-umbrella test path" do
"""
defmodule CredoSampleModule do
def some_function() do
Expand All @@ -55,12 +51,12 @@ defmodule Credo.Check.Refactor.ModuleDependenciesTest do
end
end
"""
|> to_source_file
|> to_source_file("test/foo/my_test.exs")
|> run_check(@described_check)
|> assert_issue()
|> refute_issues()
end

test "it should not report a violation on non-umbrella test path" do
test "it should NOT report a violation on umbrella test path" do
"""
defmodule CredoSampleModule do
def some_function() do
Expand All @@ -80,12 +76,12 @@ defmodule Credo.Check.Refactor.ModuleDependenciesTest do
end
end
"""
|> to_source_file("test/foo/my_test.exs")
|> to_source_file("apps/foo/test/foo/my_test.exs")
|> run_check(@described_check)
|> refute_issues()
end

test "it should not report a violation on umbrella test path" do
test "it should NOT report a violation with excluded namespaces" do

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [24.3/1.13.4] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [24.3/1.11.4] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [24.3/1.12.3] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [24.3/1.14.5] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [25.3/1.15.7] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [26.1/1.15.7] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [26.1/1.16.0-rc.0] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [25.3/1.13.4] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [23.3/1.14.5] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [23.3/1.11.4] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [23.3/1.13.4] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)

Check failure on line 84 in test/credo/check/refactor/module_dependencies_test.exs

View workflow job for this annotation

GitHub Actions / [23.3/1.12.3] CI Tests on Credo [OTP/Elixir]

test it should NOT report a violation with excluded namespaces (Credo.Check.Refactor.ModuleDependenciesTest)
"""
defmodule CredoSampleModule do
def some_function() do
Expand All @@ -105,8 +101,43 @@ defmodule Credo.Check.Refactor.ModuleDependenciesTest do
end
end
"""
|> to_source_file("apps/foo/test/foo/my_test.exs")
|> run_check(@described_check)
|> to_source_file
|> run_check(@described_check,
excluded_namespaces: [
DateTime,
Kernel,
GenServer
]
)
|> refute_issues()
end

#
# cases raising issues
#

test "it should report a violation" do
"""
defmodule CredoSampleModule do
def some_function() do
[
DateTime,
Kernel,
GenServer,
GenEvent,
File,
Time,
IO,
Logger,
URI,
Path,
String
]
end
end
"""
|> to_source_file
|> run_check(@described_check)
|> assert_issue()
end
end

0 comments on commit a9f1d70

Please sign in to comment.