Hive Hive
Sign in

feat(server, cache): credo — flag directives inside ExUnit block macros

GitHub issue · Closed

Metadata
Source
tuist/tuist #10895
Updated
Jun 26, 2026
Details

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 for describe, test, setup, setup_all. When one is encountered the do: body is run through the same collect_directives/1 walk as def/defp bodies, and the existing quote skip still applies. Updated the moduledoc, explanation, and issue message to read “function or block body”.
  • Configsserver/.credo.exs, cache/.credo.exs, and processor/.credo.exs now apply this check to test/ as well as lib/.
  • Sweep — fixed the six pre-existing violations the broadened check surfaced:
    • server/test/support/tuist_test_support/fixtures/projects_fixtures.eximport Ecto.Query lifted from project_fixture/1 to the module
    • server/test/tuist/tests_test.exsimport Ecto.Query lifted from a test to the module
    • server/test/tuist_web/live/test_run_live_test.exsalias TuistTestSupport.Fixtures.CommandEventsFixtures lifted from a test to the module
    • cache/test/cache/registry/lock_test.exsimport ExUnit.CaptureLog lifted from a test to the module
    • cache/test/cache/sqlite_buffer_test.exs — two redundant import Ecto.Query inside test blocks removed (already imported at module level)

How to test locally

  • cd server && mix credo --strict — passes, no DisallowDirectivesInFunction violations.
  • cd cache && mix credo --strict — passes.
  • Synthetic verification: dropped a one-off _sample_check_test.exs with alias inside describe/setup/test and 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 pass
    • cd server && mix test test/tuist/tests_test.exs:2110 test/tuist_web/live/test_run_live_test.exs — 16/16 pass
  • mix format --check-formatted is clean on every touched file.
Comments

No GitHub comments yet.