Elixir Compilation Cycles with `--fail-above`
Elixir 1.13.0
introduced a --fail-above
flag for the mix xref
task which will fail that task execution under a certain criteria.
With that we can verify, for example, that our code is ok to have 1 cycle that goes over length of 4, but not 2 cycles. Let's see how it works:
$ mix xref graph --format cycles --min-cycle-size 4 --fail-above 1
2 cycles found. Showing them in decreasing size:
Cycle of length 6:
lib/my_app_web/endpoint.ex
lib/my_app_web/router.ex
lib/my_app_web/views/layout_view.ex
lib/my_app_web/live/components/sorting_link.ex
lib/my_app_web/live/components/icon.ex
lib/my_app_web/endpoint.ex
Cycle of length 5:
lib/my_app_web/live/components/sorting_link.ex
lib/my_app_web/live/components/icon.ex
lib/my_app_web/router.ex
lib/my_app_web/views/layout_view.ex
lib/my_app_web/live/components/sorting_link.ex
** (Mix) Too many cycles (found: 2, permitted: 1)
In this case xref
found 2 cycles with a length greater than 4, and as I allowed only 1 then we can see the error.