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

CS: remove unnecessary ignore annotations [2] (Trac 59650) #5518

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Oct 17, 2023

It is perfectly possible to write a commented regex with layout for readability by using the x modifier.

As per the manual:

x (PCRE_EXTENDED)
If this modifier is set, whitespace data characters in the pattern are totally ignored except when escaped or inside a character class, and characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored. This is equivalent to Perl's /x modifier, and makes it possible to include commentary inside complicated patterns.
Note, however, that this applies only to data characters. Whitespace characters may never appear within special character sequences in a pattern, for example within the sequence (?( which introduces a conditional subpattern.

Ref: https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

This commit rewrites these two regexes to use the x modifier and gets rid of the unnecessary phpcs:disable comments.

The tests in the tests/phpunit/tests/db/dbDelta.php file cover this change.

Trac ticket: https://core.trac.wordpress.org/ticket/59650


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@jrfnl jrfnl changed the title CS: remove unnecessary ignore annotations [2] CS: remove unnecessary ignore annotations [2] (Trac 59650) Oct 17, 2023
It is perfectly possible to write a commented regex with layout for readability by using the `x` modifier.

As per the manual:
>  x (PCRE_EXTENDED)
>     If this modifier is set, whitespace data characters in the pattern are totally ignored except when escaped or inside a character class, and characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored. This is equivalent to Perl's /x modifier, and makes it possible to include commentary inside complicated patterns.
>     Note, however, that this applies only to data characters. Whitespace characters may never appear within special character sequences in a pattern, for example within the sequence (?( which introduces a conditional subpattern.

Ref: https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

This commit rewrites these two regexes to use the `x` modifier and gets rid of the unnecessary `phpcs:disable` comments.

The tests in the `tests/phpunit/tests/db/dbDelta.php` file cover this change.
@SergeyBiryukov
Copy link
Member

Thanks for the PR! Merged in r57061.

@jrfnl
Copy link
Member Author

jrfnl commented Nov 4, 2023

Thanks @SergeyBiryukov !

@jrfnl jrfnl deleted the trac-59650/no-need-for-ignore-annotation-2 branch November 4, 2023 01:23
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.

2 participants