Open jrfnl opened 5 years ago
@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.
@marconmartins, @Ipstenu, @NielsdeBlaauw, @GaryJones, @ckanitz I'm planning to release WPCS 2.2.0 in the very near future and I'd love to include as many of the docs as possible in that release.
Aside from the PRs @NielsdeBlaauw send in today, are there any open docs PRs which have been updated after review, but haven't had attention since ?
If so: my apologies. Please do leave a comment either here or on the PR itself to draw attention to it, so we can try to get the PR merged before the release.
Also - if a PR does still need an update, but you either don't have time to do so yourself or have lost interest, please leave a comment on the PR and we'll try and have someone else finish it off.
I really appreciate the work you've done on this and would love to have it go out in the world and help people when they are working with WPCS.
After about 2 hours of I figured out. How to make an exception for snake_case:
<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="customPropertiesWhitelist[]" value="hive_ID"/>
</properties>
</rule>
Now the question is where should this be documented. I did found the xml docs. I don't think the format matches, I might be wrong. Is there a place where this should be documented? Can someone nudge me in the right direction?
@janw-me Sorry it took you so long. Next time, you may want to have a look at the wiki (where it is already documented): https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#mixed-case-property-name-exceptions
Edit: Oh and please follow the format as per the example in the wiki. Your current format is not officially supported by PHPCS.
With googling I didn't find it... And on the github pageI was looking for some "documentation" link but I should have looked for the wiki. I probably should call it a day....
And of course I'll follow the wiki format. the []
is fugly.
@janw-me Well, the readme also contains a link to the wiki and mentions customizing sniff behaviour: https://github.com/WordPress/WordPress-Coding-Standards#customizing-sniff-behaviour But if there are other ways in which you think this can be done which will help people find it more easily, I'd welcome a PR ;-)
@GaryJones @dingo-d
Opinions ? Anyone up for creating the XSD ?
I went and played around with PhpStorm's automatic schema definitions and I got this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="documentation" type="documentationType"/>
<xs:complexType name="codeType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="title" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="code_comparisonType">
<xs:sequence>
<xs:element type="codeType" name="code" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="documentationType">
<xs:sequence>
<xs:element type="xs:string" name="standard"/>
<xs:element type="code_comparisonType" name="code_comparison"/>
</xs:sequence>
<xs:attribute type="xs:string" name="title"/>
</xs:complexType>
</xs:schema>
In one case (where I used ArrayIndentationStandard.xml
as a basis for xsd generation) I got a difference in the <xs:complexType name="documentationType">
part:
<xs:complexType name="documentationType">
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element type="xs:string" name="standard"/>
<xs:element type="code_comparisonType" name="code_comparison"/>
</xs:choice>
<xs:attribute type="xs:string" name="title"/>
</xs:complexType>
The xs:choice
vs xs:sequence
.
I'm not all too familiar with how xds needs to be structured. Do we need to just add that part inside the <xs:complexType name="documentationType">
tag?
@dingo-d Nice starting point, though it can probably be abstracted a little more. An XSD basically is a definition of what is elements and attributes are allowed within an XML document, how they can be nested and if they are expected in a certain order etc etc.
The W3Schools information is not bad to get a general impression of the definition language: https://www.w3schools.com/xml/schema_intro.asp Alternatively, for a deep dive, there are the official specs: https://www.w3.org/TR/xmlschema11-1/ ;-)
Oh and for inspiration, you could also have a look at the XSD for PHPCS rulesets: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xsd
All sniffs should be accompanied by documentation in the form of a
SniffNameStandard.xml
file. ASniffNameStandard.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:
The sniff documentation for an individual sniff can be shown using the following command:
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
#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).Creating the documentation
Preparation
composer install
from the command line in the root directory of your local clone of this repo.For each sniff:
develop
and name itdocs/sniffname
.WordPress/Docs/Category/
directory. You may need to create the directory if it doesn't yet exist.addWarning()
and/oraddError()
function calls in the sniff file in theWordPress/Sniffs/Category/
directory to see the error messages the sniff generates.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:title
of a "good" code sample should start withValid:
. Thetitle
of a "bad" code sample should start withInvalid:
.<em> ...</em>
tags. These will be removed automatically when using the text generator, but ensure highlighting of the code in Markdown/HTML.Related to #1722
so your pull request will show up in this issue.To Do
Claimed
Finished
Not needed
WordPress.CodeAnalysis.EmptyStatementReplaced by PHPCS native sniff, see #1910