3.0 KiB
3.0 KiB
id, title, status, assignee, created_date, updated_date, labels, dependencies, priority, ordinal
| id | title | status | assignee | created_date | updated_date | labels | dependencies | priority | ordinal | |
|---|---|---|---|---|---|---|---|---|---|---|
| ML-195 | Add Credo check for LiveComponent toast helper usage | Done |
|
2026-05-21 06:57 | 2026-05-21 07:05 | medium | 38000 |
Description
Add a custom Credo check that flags calls to put_toast/3 from LiveComponent modules so contributors use the LiveComponent-safe put_toast!/2 helper instead.
Acceptance Criteria
- #1 Credo fails when a LiveComponent module calls
put_toast/3. - #2 Credo does not flag allowed
put_toast!/2calls inside LiveComponents. - #3 Credo does not flag
put_toast/3usage outside LiveComponent modules. - #4 Automated tests cover the new check behavior.
Implementation Plan
- Review Credo configuration and any existing custom checks/tests to match project conventions.
- Add a custom Credo check that detects modules using
use MusicLibraryWeb, :live_componentand reports calls toput_toast/3, including pipeline form when applicable. - Register the check in Credo config so
mix credoruns it. - Add focused tests for disallowed LiveComponent usage, allowed
put_toast!/2, and allowed non-LiveComponentput_toast/3usage. - Run the relevant test file and Credo check to validate behavior.
Implementation Notes
Implemented MusicLibrary.Credo.NoLiveComponentPutToast, registered it in .credo.exs, and updated existing RecordForm LiveComponent toast calls to put_toast!/2 so the new rule can be enabled cleanly. Validation: mix test test/music_library/credo/no_live_component_put_toast_test.exs; mix test test/music_library_web/live/collection_live/show_test.exs --max-failures 1; mix test test/music_library_web/live/collection_live/index_test.exs --max-failures 1; mix credo --strict.
Final Summary
Summary:
- Added
MusicLibrary.Credo.NoLiveComponentPutToast, a custom Credo warning that detectsput_toast/3calls inside LiveComponent modules and covers direct, piped, qualified, and captured call forms. - Registered the custom check in
.credo.exs. - Cleaned up existing
RecordFormLiveComponent toast usage by switching toput_toast!/2before returning/pushing patches. - Added focused Credo check tests for disallowed LiveComponent usage and allowed LiveComponent/non-LiveComponent cases.
Validation:
mix test test/music_library/credo/no_live_component_put_toast_test.exsmix test test/music_library_web/live/collection_live/show_test.exs --max-failures 1mix test test/music_library_web/live/collection_live/index_test.exs --max-failures 1mix credo --strict
Docs:
- No documentation update needed;
docs/project-conventions.mdalready documents the LiveView vs LiveComponent toast helper rule.