Skip to content

Enable :module_directives rule in Quokka#1921

Merged
pehbehbeh merged 8 commits intodevelopfrom
feature/skip-module-directive-reordering
Apr 29, 2026
Merged

Enable :module_directives rule in Quokka#1921
pehbehbeh merged 8 commits intodevelopfrom
feature/skip-module-directive-reordering

Conversation

@pehbehbeh
Copy link
Copy Markdown
Member

Summary

Enables Quokka's :module_directives rule project-wide (previously excluded) so module directives get organized consistently. Files that intentionally define @config_schema before @moduledoc (to interpolate
schema docs into the moduledoc) are opted out with # quokka:skip-module-directive-reordering.

Changes

  • Remove exclude: [:module_directives] from the root and demo .formatter.exs.
  • Add skip comments to 19 field/adapter modules that must keep @config_schema before @moduledoc.
  • Manually hoist Phoenix.LiveView.Rendered / Socket aliases in Backpex.Field so @callback specs resolve under the preserved source order.
  • Apply the broader # quokka:skip-module-directives to post_live.ex and product_live.ex in the demo, where Quokka's alias lifting of Backpex.Fields.Number shadowed the Number Hex package used by
    Number.Delimit.
  • Absorb the resulting reformatting across demo modules and tests.

Remove the `:module_directives` exclusion from both formatter configs
so Quokka organizes module directives consistently across the project.

Files that intentionally place `@config_schema` before `@moduledoc` to
interpolate schema docs into the moduledoc opt out via
`# quokka:skip-module-directive-reordering`. `Backpex.Field` also gets
explicit `Rendered`/`Socket` aliases so `@callback` specs resolve under
the preserved source order.

The demo's `post_live.ex` and `product_live.ex` use the broader
`# quokka:skip-module-directives` since Quokka's alias lifting of
`Backpex.Fields.Number` shadowed the `Number` Hex package used by
`Number.Delimit`.
@pehbehbeh pehbehbeh requested a review from Flo0807 April 15, 2026 13:14
@pehbehbeh pehbehbeh self-assigned this Apr 15, 2026
@pehbehbeh pehbehbeh added the enhancement Changes that are not breaking label Apr 15, 2026
Quokka's reordering left some comments attached to the wrong directive,
so drop the now-misleading comments.
@pehbehbeh
Copy link
Copy Markdown
Member Author

@Flo0807 FYI: We can further improve this once emkguts/quokka#150 gets merged.

Comment thread demo/lib/demo_web/live/invoice_live.ex
Comment thread demo/lib/demo/invoice.ex Outdated
Configure Credo.Check.Design.AliasUsage to skip lifting modules under
Backpex.Fields and any module whose last name is Type, so field modules
and Ecto types like Money.Ecto.Amount.Type stay fully qualified.
Defaults are pulled from Credo via param_defaults/0 to keep stdlib
exclusions intact. De-lift existing usages accordingly.
The doctest module references each target exactly once, so alias
lifting just adds noise. Mark the file with the
`# quokka:skip-module-directives` magic comment so Quokka leaves the
fully qualified `doctest` calls alone.
The directive was a workaround for Quokka lifting `Backpex.Fields.Number`
and shadowing the `Number` Hex package used by `Number.Delimit`. With
`Backpex.Fields` now globally excluded from alias lifting via the Credo
`AliasUsage` config, the conflict cannot recur and the workaround is
unnecessary.
Set `if_nested_deeper_than: 2` and `if_called_more_often_than: 1` on
the Credo `AliasUsage` check so Quokka only lifts aliases for modules
with at least three segments and at least two usages. Keeps the
two-segment Phoenix/Backpex modules (e.g. `NimbleOptions.ValidationError`,
`Backpex.Field`) fully qualified, which avoids the broken
`use Field` / late-alias compile error in files that opt out of
directive reordering.

Restore the fully qualified `Backpex.Filter` references in
`test/adapters/ecto_test.exs` since that single-segment alias falls
below the new threshold.
Restore fully qualified `Backpex.Fields.*` references throughout the
demo. The `Backpex.Fields` namespace is excluded from alias lifting in
the Credo `AliasUsage` config, so leaving these aliased was an artifact
of an earlier directive-reordering pass — Quokka never removes existing
aliases on its own.
@pehbehbeh pehbehbeh added this pull request to the merge queue Apr 29, 2026
Merged via the queue into develop with commit 49c7496 Apr 29, 2026
7 checks passed
@pehbehbeh pehbehbeh deleted the feature/skip-module-directive-reordering branch April 29, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Changes that are not breaking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants