Hive
feat(server, cache): credo — flag directives inside ExUnit block macros
GitHub issue · Closed
Source
tuist/tuist #10895
Updated
Jun 26, 2026
Summary
Originally raised in https://github.com/tuist/tuist/pull/10878#discussion_r3273526712 — an alias inside a describe body slipped through review. We had Credo.Checks.DisallowDirectivesInFunction that catches import/alias/require inside def/defp, but it only ran on lib/ and only matched function definitions, so it never looked at ExUnit block macros.
What changed
- Check (
tuist_common/credo/checks/disallow_directives_in_function.ex) — added a traversal clause fordescribe,test,setup,setup_all. When one is encountered thedo:body is run through the samecollect_directives/1walk asdef/defpbodies, and the existingquoteskip still applies. Updated the moduledoc, explanation, and issue message to read “function or block body”. - Configs —
server/.credo.exs,cache/.credo.exs, andprocessor/.credo.exsnow apply this check totest/as well aslib/. - Sweep — fixed the six pre-existing violations the broadened check surfaced:
server/test/support/tuist_test_support/fixtures/projects_fixtures.ex—import Ecto.Querylifted fromproject_fixture/1to the moduleserver/test/tuist/tests_test.exs—import Ecto.Querylifted from atestto the moduleserver/test/tuist_web/live/test_run_live_test.exs—alias TuistTestSupport.Fixtures.CommandEventsFixtureslifted from atestto the modulecache/test/cache/registry/lock_test.exs—import ExUnit.CaptureLoglifted from atestto the modulecache/test/cache/sqlite_buffer_test.exs— two redundantimport Ecto.Queryinsidetestblocks removed (already imported at module level)
How to test locally
cd server && mix credo --strict— passes, noDisallowDirectivesInFunctionviolations.cd cache && mix credo --strict— passes.- Synthetic verification: dropped a one-off
_sample_check_test.exswithaliasinsidedescribe/setup/testand confirmed the check reports all three sites. - Re-ran the touched tests:
cd cache && mix test test/cache/registry/lock_test.exs test/cache/sqlite_buffer_test.exs— 27/27 passcd server && mix test test/tuist/tests_test.exs:2110 test/tuist_web/live/test_run_live_test.exs— 16/16 pass
mix format --check-formattedis clean on every touched file.
No GitHub comments yet.