Description
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:
- https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Docs/Formatting/MultipleStatementAlignmentStandard.xml
- https://github.com/squizlabs/PHP_CodeSniffer/tree/master/src/Standards/Generic/Docs
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
- Create a GitHub user account (if you haven't got one already).
- Fork this repository on GitHub.
- Make sure you have both git as well as Composer installed on your machine.
- Clone your fork to your local machine using your preferred git client.
- Run
composer install
from the command line in the root directory of your local clone of this repo.
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 saysSniffName
, replace it with the name of the sniff.
- Create a new branch off
develop
and name itdocs/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/oraddError()
function calls in the sniff file in theWordPress/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 withValid:
.
Thetitle
of a "bad" code sample should start withInvalid:
. - 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 descriptionRelated 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.PluginMenuSlug
- WordPress.Security.ValidatedSanitizedInput
- WordPress.Utils.I18nTextDomainFixer
- WordPress.WP.GlobalVariablesOverride
- WordPress.WP.I18n
Claimed
- WordPress.Arrays.ArrayDeclarationSpacing - @RafaelFunchal - Adding documentation for WordPress.Arrays.ArrayDeclarationSpacing #2489
- WordPress.CodeAnalysis.AssignmentInTernaryCondition - @Nic-Sevic - Add documentation for AssignmentInTernaryCondition sniff #2488
- WordPress.DB.DirectDatabaseQuery - @jaymcp - [Documentation]: WordPress.DB.DirectDatabaseQuery #2458
- WordPress.DB.RestrictedClasses - @paulgibbs - Add documentation for WordPress.DB.RestrictedClasses #2455
- WordPress.DB.RestrictedFunctions - @paulgibbs - Add documentation for WordPress.DB.RestrictedFunctions #2453
- WordPress.DB.SlowDBQuery - @petitphp - Docs: add documentation for
WordPress.DB.SlowDBQuery
#2464 - WordPress.Files.FileName - @Nic-Sevic - Add documentation for FileName sniff #2492
- WordPress.PHP.DevelopmentFunctions - @gogdzl - Add documentation for WordPress.PHP.DevelopmentFunctions #2490
- WordPress.PHP.DiscouragedPHPFunctions - @tikifez - adds documentation for sniff WordPress.PHP.DiscouragedPHPFunctions #2494
- WordPress.PHP.NoSilencedErrors - @gogdzl - Add documentation for WordPress.PHP.NoSilencedErrors #2495
- WordPress.PHP.POSIXFunctions - @jaymcp - [Documentation]: WordPress.PHP.POSIXFunctions #2460
- WordPress.PHP.PregQuoteDelimiter - @tikifez - Adds documentation for PregQuoteDelimiter #2487
- WordPress.PHP.RestrictedPHPFunctions - @gogdzl - Add documentation for WordPress.PHP.RestrictedPHPFunctions #2491
- WordPress.PHP.TypeCasts - @anukasha-mo
- WordPress.WP.AlternativeFunctions - @pamprn09 - Add documentation for WordPress.WP.AlternativeFunctions.xml #2496
- WordPress.WP.DiscouragedConstants - @RafaelFunchal - Adding documentation to WordPress.WP.DiscouragedConstants #2493
- WordPress.WP.DiscouragedFunctions - @Nic-Sevic
Finished
- WordPress.Arrays.ArrayIndentation - @Mike-Hermans
- WordPress.Arrays.ArrayKeySpacingRestrictions - @Mike-Hermans
- WordPress.Arrays.CommaAfterArrayItem - @marconmartins (moved to PHPCSExtra since, see Replace the WordPress.Array.CommaAfterArrayItem sniff #2310)
- WordPress.Arrays.MultipleStatementAlignment - @Mike-Hermans
- WordPress.Classes.ClassInstantiation - @FORTE-WP (moved to PHPCSExtra since, see Core: move rules related to object instantiations from Extra to Core #2133)
- WordPress.CodeAnalysis.EscapedNotTranslated - @jrfnl
- WordPress.DateTime.CurrentTimeTimestamp - @jrfnl
- WordPress.DateTime.RestrictedFunctions - @GaryJones
- WordPress.DB.PreparedSQL - @jaymcp
- WordPress.NamingConventions.PrefixAllGlobals - @Ipstenu
- WordPress.NamingConventions.ValidFunctionName - @richardkorthuis
- WordPress.NamingConventions.ValidHookName - @jrfnl
- WordPress.NamingConventions.ValidPostTypeSlug - @NielsdeBlaauw
- WordPress.NamingConventions.ValidVariableName - @richardkorthuis - Add documentation for WordPress.NamingConventions.ValidVariableName #2457
- WordPress.PHP.DontExtract - @aiolachiara - DontExtractStandard.xml file creation #2456
- WordPress.PHP.IniSet - @NielsdeBlaauw
- WordPress.PHP.StrictInArray - @marconmartins
- WordPress.PHP.YodaConditions - @Ipstenu
- WordPress.Security.SafeRedirect - @marconmartins / @NielsdeBlaauw
- WordPress.WhiteSpace.CastStructureSpacing - @ckanitz
- WordPress.WhiteSpace.ControlStructureSpacing - @ckanitz & @jrfnl
- WordPress.WhiteSpace.DisallowInlineTabs - @ckanitz (moved to PHPCSExtra since, see 3.0: Replace the
WordPress.WhiteSpace.DisallowInlineTabs
sniff #1912) - WordPress.WhiteSpace.ObjectOperatorSpacing - @jrfnl
- WordPress.WhiteSpace.OperatorSpacing - @ckanitz
- WordPress.WhiteSpace.PrecisionAlignment - @ckanitz (moved to PHPCSExtra since, see Replace the
WordPress.WhiteSpace.PrecisionAlignment
sniff #2129) - WordPress.WP.Capabilities - @dingo-d
- WordPress.WP.CapitalPDangit - @NielsdeBlaauw / @jrfnl
- WordPress.WP.ClassNameCase - @jrfnl
- WordPress.WP.CronInterval - @NielsdeBlaauw
- WordPress.WP.DeprecatedClasses - @fkeijzer
- WordPress.WP.DeprecatedFunctions - @fkeijzer
- WordPress.WP.DeprecatedParameters - @fkeijzer
- WordPress.WP.DeprecatedParameterValues - @fkeijzer
- WordPress.WP.EnqueuedResources - @NielsdeBlaauw
- WordPress.WP.EnqueuedResourceParameters - @NielsdeBlaauw
- WordPress.WP.PostsPerPage - @GaryJones
Not needed
WordPress.CodeAnalysis.EmptyStatementReplaced by PHPCS native sniff, see 3.0: Replace theWordPress.CodeAnalysis.EmptyStatement
sniff #1910