Skip to content

Add opt-in .distignore exclusions - #1560

Open
jakaria-istauk wants to merge 3 commits into
WordPress:trunkfrom
jakaria-istauk:add/distignore-exclusions
Open

jakaria-istauk wants to merge 3 commits into
WordPress:trunkfrom
jakaria-istauk:add/distignore-exclusions

Conversation

@jakaria-istauk

@jakaria-istauk jakaria-istauk commented Nov 29, 2026 •

Copy link
Copy Markdown

What?

Closes #1559
Refs #1159

Adds an opt-in, off-by-default option to leave out the files and directories a plugin's .distignore lists, the same files wp dist-archive keeps out of the production zip:

  • Admin scanner: an "Exclude files listed in .distignore" checkbox under Custom Exclusions. It's shown only when the selected plugin has a .distignore file.
  • WP-CLI: wp plugin check <plugin> --use-distignore.

It works the same way as the .pcpignore option from #1460, and reuses its exclusion code.

Why?

Running Plugin Check on a development checkout reports problems in files that never ship, such as test suites, build scripts, CI configuration, dotfiles and local build folders, so the real findings get lost. .pcpignore (#1460) fixed this, but a plugin that builds its zip with wp dist-archive already lists exactly those paths in .distignore. Without this option it has to copy them into .pcpignore, and the two files drift: a new dev folder added to only one of them is either scanned again or shipped without being checked.

This PR lets the scan use the list the plugin already keeps, with the same safety rules already accepted for .pcpignore:

  • It never runs on its own. Nothing reads .distignore unless asked. The checkbox is unchecked by default and only appears when the file exists, and the CLI flag defaults to off. So the WordPress.org scanner, which never passes the option, still inspects every file. This follows the requirement from the Implement includes, config file support & .distignore parsing (#1108, #1159) #1181 review that plugin authors must not be able to change the scanner's behaviour.
  • It matches what actually ships. Patterns follow .gitignore rules, as wp dist-archive does. The scan leaves out exactly what the zip leaves out, no more and no less. That answers the "false sense of safety" concern from Feature, add support for .distignore #692 as far as a local option can.
  • Small footprint. No new settings, no config file, no new matching engine.

How?

  • New Dist_Ignore_Utility (includes/Utilities/):
    • Parses .distignore with .gitignore rules: a pattern containing a slash (other than a trailing one) is anchored to the plugin root, a pattern without one matches at any depth, a trailing / means directory only, * and ? don't match /, ** matches any number of directories, and a leading ! re-includes a path.
    • Walks the plugin once and turns every match into a literal path anchored to the plugin root. Excluded directories are collected whole and not walked into. Directories the scan always skips (vendor, node_modules, ...) aren't walked either.
    • Because the output uses the same root-anchored format as .pcpignore entries, the existing Ignore_Matcher and PHPCS ignore patterns apply it unchanged, with the root anchoring the Add opt-in .pcpignore exclusions #1460 review asked for.
    • An unreadable file only produces a warning, and single-file plugins aren't supported, both like .pcpignore. The output is sorted, so it doesn't depend on filesystem order.
  • Admin: each plugin option in the dropdown carries data-has-distignore. The JS shows the checkbox only for those and unchecks it when hidden. Admin_AJAX::run_checks() reads the new use-distignore flag (any warning is returned as distignore_warning, like pcpignore_warning).
  • CLI: --use-distignore on Plugin_Check_Command, which prints any warning through WP_CLI::warning(). It's documented in docs/CLI.md.

The .pcpignore and .distignore options can be combined, since each only adds entries to the existing wp_plugin_check_ignore_directories / wp_plugin_check_ignore_files filters.

Commits:

  1. Add utility to resolve .distignore exclusions: the utility, PHPUnit tests and the test-plugin-distignore fixture
  2. Add a .distignore option to the Admin scanner
  3. Add --use-distignore to the plugin check command: CLI, Behat scenario and docs

Testing Instructions

Admin

  1. Add a .distignore to a test plugin, for example:
    /bin/
    tests
    *.map
    
    Put a PHP file with a known error (e.g. <?php echo $_GET['x'];) in bin/ and in includes/tests/.
  2. Go to Tools → Plugin Check and select that plugin. "Exclude files listed in .distignore" appears under Custom Exclusions, unchecked.
  3. Select a plugin without a .distignore. The option disappears.
  4. Check the plugin with the box unchecked: bin/ and includes/tests/ are reported. Check it again with the box checked: neither is reported, and shipped files still are.

CLI

  1. wp plugin check <plugin> reports files in bin/ and includes/tests/.
  2. wp plugin check <plugin> --use-distignore doesn't report them.

Automated: Dist_Ignore_Utility_Tests covers anchored and any-depth patterns, **, ! negation, a missing file, single-file plugins, and a full check run before and after applying the exclusions. The new Behat scenario Apply .distignore exclusions only when requested covers the CLI flag. The full suite passes on this branch on my fork, across PHP 7.4–8.4 and WP 6.3–trunk (checks). The only red step there is the Codecov upload, which fails on forks for lack of a token.

AI Usage Disclosure

  • This PR was created without the help of AI tools
  • This PR includes AI-assisted code or content

If AI tools were used, please describe how they were used:
I used Claude Code to help write the code, tests and this description. I reviewed every change, tested it by hand in the Admin UI and the CLI, and ran the full test suite.

Screenshots or screencast

Before After
Before: Custom Exclusions has only the .pcpignore option After: the .distignore option appears under Custom Exclusions
After, plugin without a .distignore (option hidden) After, 390px
After: option hidden for a plugin without .distignore After at 390px

If you'd rather ship only the CLI flag, or prefer a different label or position for the checkbox, I'm happy to adjust.

Open WordPress Playground Preview

Parses a plugin's .distignore with .gitignore semantics, as wp dist-archive does, and resolves it into literal exclusions anchored to the plugin root, so they are matched like .pcpignore entries. Opt-in only; nothing applies it yet.
Adds an "Exclude files listed in .distignore" checkbox under Custom Exclusions. It is shown only when the selected plugin has a .distignore file and is off by default.
Brings the WP-CLI command to parity with the Admin option, with docs and a Behat scenario.
@github-actions

Copy link
Copy Markdown
Contributor

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jakaria-istauk <jakariaistauk@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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.

Add opt-in .distignore exclusions for local and CI scans

1 participant