Skip to content

Support glob patterns in files.included/files.excluded#175

Open
fschoenfeldt wants to merge 1 commit into
emkguts:mainfrom
fschoenfeldt:fix/files-glob-support
Open

Support glob patterns in files.included/files.excluded#175
fschoenfeldt wants to merge 1 commit into
emkguts:mainfrom
fschoenfeldt:fix/files-glob-support

Conversation

@fschoenfeldt

@fschoenfeldt fschoenfeldt commented Jun 30, 2026

Copy link
Copy Markdown

Description

quokka.files.excluded/included only matched via String.starts_with? on the relative path, so glob patterns such as "config/*.exs" silently matched nothing while looking like the globs used by mix format's :inputs. Users had to discover that only bare directory prefixes work.

Expand each entry with Path.wildcard/2 (mirroring how mix format resolves :inputs/:excludes) into a cwd-relative MapSet, and match a file if it is either prefixed by an entry (legacy behaviour, kept for bare dir prefixes like "config/") or a member of the expanded set. Fully backward compatible.

resolves #174

Authored with assistance from Claude Code.

PR Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests pass
  • If there are changes to installation, usage, or project overview, I have updated README.md
  • If there are changes to styling, I have updated the relevant /docs/*.md file
  • I have run mix format and committed any changes

`quokka.files.excluded`/`included` only matched via `String.starts_with?`
on the relative path, so glob patterns such as `"config/*.exs"` silently
matched nothing while looking like the globs used by `mix format`'s
`:inputs`. Users had to discover that only bare directory prefixes work.

Expand each entry with `Path.wildcard/2` (mirroring how `mix format`
resolves `:inputs`/`:excludes`) into a cwd-relative MapSet, and match a
file if it is either prefixed by an entry (legacy behaviour, kept for
bare dir prefixes like `"config/"`) or a member of the expanded set.
Fully backward compatible.

Fixes emkguts#174

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@s3cur3 s3cur3 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is lovely! One minor comment, but otherwise looks good. The main blocker is getting the fix for CI (#168) merged so we can run it on this branch.

Comment thread test/config_test.exs
Comment on lines +204 to +209
test "exclusion wins over inclusion" do
assert :ok = set!(quokka: [files: %{included: ["lib/**/*.ex"], excluded: ["lib/quokka/*.ex"]}])

refute Quokka.Config.allowed_directory?("lib/quokka/config.ex")
assert Quokka.Config.allowed_directory?("lib/styler.ex")
end

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great test 👍

Comment thread lib/quokka/config.ex
defp expand_file_globs(patterns) do
patterns
|> List.wrap()
|> Enum.flat_map(&Path.wildcard(Path.expand(&1, File.cwd!()), match_dot: true))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we gain anything from doing the expansion? I'm not sure we do. If there would be duplicates, I think doing the MapSet relative to the current working directory would take care of them, right?

Suggested change
|> Enum.flat_map(&Path.wildcard(Path.expand(&1, File.cwd!()), match_dot: true))
|> Enum.flat_map(&Path.wildcard(&1, match_dot: true))

@s3cur3

s3cur3 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

@fschoenfeldt, wanna merge main/rebase off main to pick up the CI fixes, and then we can get this merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config: files.included / excluded – support glob pattern

2 participants