Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine include/exclude patterns in phpcs.xml.dist #59712

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

anton-vlasenko
Copy link
Contributor

@anton-vlasenko anton-vlasenko commented Mar 8, 2024

What?

This PR refines patterns used in <exclude-pattern> and <include-pattern> statements.

Why?

According to the documentation on ignoring files and folders, the patterns in include/exclude statements are essentially regular expressions.

Therefore, beginning a pattern with a . (dot) is redundant since . doesn't match the root folder.

How?

  • removed unnecessary dots at the start of include/exclude patterns to avoid ambiguity;
  • added leading slashes to patterns to ensure they match the intended paths without accidentally including unintended ones;
  • escaped dots as \. to match literal dots in file paths, enhancing the precision of the patterns, as advised by PHP_CodeSniffer's documentation;
  • added $ to the end of patterns targeting .php files to ensure they match only at the end of file paths.

Testing Instructions

  1. Review the changes.
  2. Make sure that GitHub CI jobs pass.

Testing Instructions for Keyboard

Screenshots or screencast

@anton-vlasenko anton-vlasenko force-pushed the fix/phpcs-xml-dist-php-extension branch 3 times, most recently from 1abba1a to cd91a11 Compare March 14, 2024 14:30
Make regexp patterns more distinrns with /.

1. Don't use . before / in exclude/include pattern as it doesn't change anything.
2. Prepend exclude/include patterns with /.
@anton-vlasenko anton-vlasenko force-pushed the fix/phpcs-xml-dist-php-extension branch from 2a51c44 to 61d2a6f Compare March 14, 2024 19:11
@anton-vlasenko anton-vlasenko changed the title Fix phpcs.xml.dist's include/exclude patterns Refine include/exclude patterns in phpcs.xml.dist Mar 14, 2024
@anton-vlasenko anton-vlasenko added the [Type] Code Quality Issues or PRs that relate to code quality label Mar 14, 2024
@anton-vlasenko anton-vlasenko marked this pull request as ready for review March 14, 2024 19:44
Copy link

github-actions bot commented Mar 14, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

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: anton-vlasenko <[email protected]>
Co-authored-by: ironprogrammer <[email protected]>
Co-authored-by: scruffian <[email protected]>

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

Copy link
Contributor

@ironprogrammer ironprogrammer left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for this cleanup/refinement 🧹

Copy link
Contributor

@scruffian scruffian left a comment

Choose a reason for hiding this comment

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

This matched the approach we use in core too which is good.

@anton-vlasenko anton-vlasenko merged commit 6c86365 into trunk Mar 18, 2024
68 checks passed
@anton-vlasenko anton-vlasenko deleted the fix/phpcs-xml-dist-php-extension branch March 18, 2024 23:31
@github-actions github-actions bot added this to the Gutenberg 18.0 milestone Mar 18, 2024
@anton-vlasenko
Copy link
Contributor Author

Thank you for the review and approval, @ironprogrammer and @scruffian!

carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Mar 27, 2024
…ordPress#59712)

1.  removed unnecessary dots at the start of include/exclude patterns;
2.  added leading slashes to patterns to ensure they match the intended paths without accidentally including unintended ones;
3.  escaped dots as `\.` to match literal dots in file paths, enhancing the precision of the patterns, as advised by PHP_CodeSniffer's [documentation](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders);
4.  added `$` to the end of patterns targeting `.php` files to ensure they match only at the end of file paths.

Co-authored-by: anton-vlasenko <[email protected]>
Co-authored-by: ironprogrammer <[email protected]>
Co-authored-by: scruffian <[email protected]>
Co-authored-by: azaozz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants