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

Adds documentation for PregQuoteDelimiter #2487

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

tikifez
Copy link

@tikifez tikifez commented Sep 17, 2024

Related to #1722

@jrfnl jrfnl mentioned this pull request Sep 17, 2024
61 tasks
@rodrigoprimo
Copy link
Collaborator

Just documenting here that I chatted in person with @tikifez and he will add valid and invalid examples. No need to review this PR yet.

@tikifez
Copy link
Author

tikifez commented Sep 17, 2024

Added code comparison with valid and invalid examples.

1 similar comment
@tikifez
Copy link
Author

tikifez commented Sep 17, 2024

Added code comparison with valid and invalid examples.

Copy link
Collaborator

@rodrigoprimo rodrigoprimo left a comment

Choose a reason for hiding this comment

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

Thanks for working on this PR, @tikifez! I'm not a maintainer of the project so take my review with a grain of salt. That being said, I left some comments based on my own experience creating PHPCS and WPCS sniffs.

Also, please make sure to include a reference to the parent issue as mentioned in the description of #1722:

Please mention this issue in your pull request description Related to #1722 so your pull request will show up in this issue.

title="Preg Quote Delimiter"
>
<standard>
<![CDATA[
Copy link
Collaborator

Choose a reason for hiding this comment

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

<![CDATA should be aligned with <standard>. Here is an example of a recently added documentation: https://github.com/rodrigoprimo/WordPress-Coding-Standards/blob/694bdf514d518004cefc0a22923fedeb0091eaca/WordPress/Docs/WP/GetMetaSingleStandard.xml#L7

Here and in the other places where <![CDATA is used.

Copy link
Author

Choose a reason for hiding this comment

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

Aligned items.

Passing the $delimiter parameter to preg_quote() is strongly recommended to ensure the delimiter required by the PCRE functions are escaped.
]]>
</standard>

Copy link
Collaborator

Choose a reason for hiding this comment

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

This newline is not necessary.

Copy link
Author

Choose a reason for hiding this comment

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

Removed unnecessary newlines.

>
<standard>
<![CDATA[
Passing the $delimiter parameter to preg_quote() is strongly recommended to ensure the delimiter required by the PCRE functions are escaped.
Copy link
Collaborator

Choose a reason for hiding this comment

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

to ensure the delimiter required by the PCRE functions are escaped.

I haven't looked deeply into this so I might be missing something, but I'm not sure this is the reason to recommend that the $delimiter parameter is passed.

I got this from the issue where this sniff was introduced:

Verify that the optional second parameter $delimiter of preg_quote() is always passed.
Too often I come across code where it is missing and unless it is passed, the default / delimiters are presumed, which is often wrong.

Copy link
Author

Choose a reason for hiding this comment

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

Updated the description and changed the example valid code to be one from WordPress core.

]]>
</code>
</code_comparison>
</documentation>
Copy link
Member

Choose a reason for hiding this comment

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

Add a clear line at the end of the file please.

<code_comparison>
<code title="Valid: The delimiter is included.">
<![CDATA[
preg_quote( $dir, '#' )
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
preg_quote( $dir, '#' )
preg_quote( $dir, <em>'#'</em> )

Use the <em>...</em> to highlight the focus of the code snippet.

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

Successfully merging this pull request may close these issues.

3 participants