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

Add documentation for each sniff #1722

Open
34 of 61 tasks
jrfnl opened this issue Jun 15, 2019 · 10 comments
Open
34 of 61 tasks

Add documentation for each sniff #1722

jrfnl opened this issue Jun 15, 2019 · 10 comments

Comments

@jrfnl
Copy link
Member

jrfnl commented Jun 15, 2019

All sniffs should be accompanied by documentation in the form of a SniffNameStandard.xml file.
A SniffNameStandard.xml file contains a (short) description of each rule(s) the sniff checks and a code comparison for each check.

Examples can be found in the PHP_CodeSniffer repository:

The sniff documentation for the complete standard can be shown using the following command:

vendor/bin/phpcs --standard=WordPress --generator=Text

The sniff documentation for an individual sniff can be shown using the following command:

vendor/bin/phpcs --standard=WordPress --generator=Text --sniffs=WordPress.Category.SniffName

Aside from the text generator, there are also generators available for HTML and Markdown, which will allow us to use these documentation files to auto-generate documentation about the sniffs to be placed in, for instance, the wiki.

At this time, none of the WPCS native sniffs have this kind of documentation available.

This issue is intended to track progress for adding this documentation.

Adding this documentation is a focus-task for the WCEU contributor day 2019.
During the WCEU Contributor day Gary (@GaryJones ) and Juliette (@jrfnl) will be available to help contributors get set up and answer any questions they may have.

Process

  • When you start working on the documentation for one of these sniffs, please mention it in the WP Slack #core-coding-standards channel and mention your GitHub nickname (during the WCEU contributor day) or leave a comment in this issue (after WCEU Contributor day).
  • Gary or Juliette will update this issue to show you have claimed that sniff.

Creating the documentation

Preparation

For each sniff:

Note: where in the below text it says Category, replace this with the category (folder name) of the sniff. And where it says SniffName, replace it with the name of the sniff.

  • Create a new branch off develop and name it docs/sniffname.
    git checkout -b "docs/sniffname" "develop"
  • Create the XML file and place it in the correct WordPress/Docs/Category/ directory.
    You may need to create the directory if it doesn't yet exist.
  • To verify what the sniff is checking for, look for addWarning() and/or addError() function calls in the sniff file in the WordPress/Sniffs/Category/ directory to see the error messages the sniff generates.
  • To get inspiration for code examples, open the sniff's WordPress/Tests/Category/SniffNameUnitTest.inc file.
    Correct code will generally be marked with // OK., incorrect code will be marked with // Bad or // Error.
    If the sniff generates several error messages and you are unsure which error applies to which code, you can run the following command to get a better understanding of which code triggers which error/warning:
    vendor/bin/phpcs -s ./WordPress/Tests/Category/SniffNameUnitTest.inc --standard=WordPress --sniffs=WordPress.Category.SniffName
  • Important: Guidelines for the documentation and the code samples:
    • Keep it as simple as possible.
    • Don't use code which can be traced back to a specific project.
    • Each line within the code sample should be max 48 characters.
    • The title of a "good" code sample should start with Valid: .
      The title of a "bad" code sample should start with Invalid: .
    • To highlight the "good" and the "bad" bits in the code examples, surround those bits with <em> ...</em> tags.
      These will be removed automatically when using the text generator, but ensure highlighting of the code in Markdown/HTML.
    • Also note: The indentation in the XML file should use spaces only. Four spaces for each indent.
      This applies not only to the code samples, but throughout the file.
    • And aside from the issue which the sniff is about, the rest of the code in each code sample should follow the WP Coding Standards.
  • Once you've created the documentation, test it by running:
    vendor/bin/phpcs --standard=WordPress --generator=Text --sniffs=WordPress.Category.SniffName
  • If all is OK, commit your changes to the branch you created, push the branch upstream to your fork and create a pull request in this repo.
    Please mention this issue in your pull request description Related to #1722 so your pull request will show up in this issue.
  • Gary and/or Juliette will review your PR and either approve and merge it or leave feedback on the pull request.
  • Once a PR has been merged, this issue should be updated and the sniff action item moved to the "Finished" list and marked as complete.

To Do

  • WordPress.DB.PreparedSQLPlaceholders
  • WordPress.Security.EscapeOutput
  • WordPress.Security.NonceVerification
  • WordPress.Security.ValidatedSanitizedInput
  • WordPress.Utils.I18nTextDomainFixer
  • WordPress.WP.GlobalVariablesOverride
  • WordPress.WP.I18n

Claimed

Finished

Not needed

GaryJones added a commit that referenced this issue Jun 20, 2019
GaryJones added a commit that referenced this issue Jun 20, 2019
@jrfnl
Copy link
Member Author

jrfnl commented Jun 23, 2019

@Mike-Hermans, @marconmartins, @Ipstenu, @NielsdeBlaauw, @fkeijzer, @GaryJones, @ckanitz Just wanted to drop you all a note that I'm sorry that I haven't managed to review your PRs yet, even though I'm so incredibly happy with them all.
Too many interesting conversations during this #WCEU kept me away from my computer.
I promise that I will get to them all within the week once I'm back home in a few days.

jrfnl pushed a commit that referenced this issue Jul 5, 2019
Adds documentation for the WordPress.WhiteSpace.CastStructureSpacing

Related to #1722
jrfnl pushed a commit that referenced this issue Jul 5, 2019
Adds documentation for the WordPress.WhiteSpace.PrecisionAlignmentSniff

Related to #1722
jrfnl pushed a commit that referenced this issue Jul 18, 2019
Adds documentation for the WordPress.WhiteSpace.DisallowInlineTabs sniff

Related to #1722
jrfnl pushed a commit that referenced this issue Oct 13, 2019
Adds documentations for the WordPress.Arrays.ArrayIndentation sniff

Related to #1722
jrfnl pushed a commit that referenced this issue Oct 13, 2019
…#1737)

Adds documentations for the `WordPress.Arrays.ArrayKeySpacingRestrictions` sniff and the `WordPress.Arrays.MultipleStatementAlignment` sniff.

Related to #1722
GaryJones added a commit that referenced this issue Jun 2, 2022
paulgibbs added a commit to paulgibbs/WordPress-Coding-Standards that referenced this issue Jun 13, 2024
paulgibbs added a commit to paulgibbs/WordPress-Coding-Standards that referenced this issue Jun 13, 2024
paulgibbs added a commit to paulgibbs/WordPress-Coding-Standards that referenced this issue Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants