-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
XSD docs schema #80
XSD docs schema #80
Conversation
@jrfnl Can we silence the Without array alignment: With the array alignment: The second one just looks... odd :S Also, I'm always for loosening the 120 line length character limit (I'm getting the phpcs errors for 121 or 123 line lenght 😅). |
Yup, Already have a commit lined up to silence the line length sniff for the test directory. The array double arrow alignment sniff will be replaced by a better sniff in due course. For the time being, feel free to silence it in the troublesome file by using the following in the class docblock (I'm doing the same elsewhere): * @phpcs:disable Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned -- If needed, fix once replaced by better sniff. |
@dingo-d Thanks for getting this set up! I'll have a look at this a little later. Will probably ask you to rebase after I've pulled (and merged) the other test PRs, which contain the full test setup. |
Oh, one point of feedback already: would be good to add this new feature to the README with some code samples of how to:
|
Oh and another thing before I forget again: let's add the XSD file to the website files array - that way the XSD file can be referred to using a canonical URL. |
Add the test for the docs schema
Added a few test cases, modify the assertions to accomodate the output of the command - check for valid message and part of the error message in case of the failure.
Added lax contents processing for any attribute in the standards type. Without it, the attributes must be explicitly defined in the xsd, and we don't know which attribute(s) some standard may want to add to their documentation.
* Install `xmllint` in the test workflows to allow PHPUnit to run it.
Add the test for the docs schema
Partal fix. Some things will still fail for the current rules (array items alignment and line lenght in some cases).
Add the instructions on how to use the xsd file in the sniff documentation file.
@jrfnl I've added the changes you've suggested. Can you check the PR to see if I missed anything? If all is ok, you can just squash and merge the PR 🙂 |
From what I've googled, it's not possible to enforce CDATA. They already have to be a string type by using the I've addressed I think most of the issues you've mentioned. One thing I'm not sure I understood was the debugging of the message with I still ned to add additional test cases you've mentioned in the comment. I've created a small bash script for myself that looks like this #!/bin/bash
# PHPCS
for file in /home/dzoljom/Projects/Personal/phpcs/vendor/squizlabs/php_codesniffer/src/Standards/*/Docs/*/*Standard.xml;
do
xmllint --noout --schema /home/dzoljom/Projects/Personal/PHPCSDevTools/DocsXsd/phpcsdocs.xsd $file
done
# PHPCSExtra
for file in /home/dzoljom/Projects/Personal/PHPCSExtra/*/Docs/*/*Standard.xml;
do
xmllint --noout --schema /home/dzoljom/Projects/Personal/PHPCSDevTools/DocsXsd/phpcsdocs.xsd $file
done
# PHPCSDevTools
for file in /home/dzoljom/Projects/Personal/PHPCSDevTools/*/Docs/*/*Standard.xml;
do
xmllint --noout --schema /home/dzoljom/Projects/Personal/PHPCSDevTools/DocsXsd/phpcsdocs.xsd $file
done
# WPCS
for file in /home/dzoljom/Projects/Personal/WordPress-Coding-Standards/*/Docs/*/*Standard.xml;
do
xmllint --noout --schema /home/dzoljom/Projects/Personal/PHPCSDevTools/DocsXsd/phpcsdocs.xsd $file
done (the path is obviously specific for my use-case but that can be changed easily) I've gotten the following failures, only in phpcs itself: .../php_codesniffer/src/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml:21: element code: Schemas validity error : Element 'code': This element is not expected.
.../php_codesniffer/src/Standards/Generic/Docs/Classes/OpeningBraceSameLineStandard.xml fails to validate
.../php_codesniffer/src/Standards/Generic/Docs/Formatting/SpaceAfterNotStandard.xml:18: element code: Schemas validity error : Element 'code': This element is not expected.
.../php_codesniffer/src/Standards/Generic/Docs/Formatting/SpaceAfterNotStandard.xml fails to validate
.../php_codesniffer/src/Standards/Generic/Docs/WhiteSpace/ArbitraryParenthesesSpacingStandard.xml:18: element code: Schemas validity error : Element 'code': This element is not expected.
.../php_codesniffer/src/Standards/Generic/Docs/WhiteSpace/ArbitraryParenthesesSpacingStandard.xml fails to validate All of those have more than two Other issues
I can add it, but if I add it to one, I'd add it to all, and to the examples in the readme.
Maybe after this PR is merged, and the
I'd also do this in the PR after this one, once we have the xsd file live on the URL. EditThe phpcs checks are failing, I think on the XML validation for the fixtures that have intentional parse errors, should we silence those somehow, or exclude them from parsing? |
Fix issues not covered by the new tests.
Add more cases.
🎉 That means it works and confirms the need for the XSD! I've lined up a PR to send to PHPCS itself to fix those (looking back, I probably introduced those errors... 🙈 ) and I will suggest PHPCS start validating docs in CI too.
Sounds like a good idea.
Why can't it be added already even though the location is (not yet) valid ? The website deploy - including the XSD file - will happen on the 2.0 release, so otherwise those changes would have to wait until a 2.0.1 release.
It's actually failing on two PHPCS errors on the test file (unnecessary use of double quotes). See the code view ;-) |
The output of Or is that not what you meant ? How can I help explain this more clearly ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some very very minor final things ;-) (aside from the replies I posted Saturday).
Co-authored-by: Juliette <[email protected]>
Co-authored-by: Juliette <[email protected]>
Co-authored-by: Juliette <[email protected]>
Co-authored-by: Juliette <[email protected]>
Co-authored-by: Juliette <[email protected]>
@jrfnl Fixed all the outstanding issues. I've added a reference to the schema like this: <?xml version="1.0"?>
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd" title="Some sniff docs"> Is this correct (URL)? |
🙌🏻
Is is based on how the file has been added to the website deploy setup, so yeah 👍🏻 |
... to a working minimal example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dingo-d You sir, are an absolute hero! Well done!
* Introduces an XSD schema file to allow for validating PHPCS XML docs files, i.e. the `Standard/Docs/Category/*Standard.xml` files. * Adds this file to the website build script so the file will also be available at a canonical URL via the website. * Adds validation of the XSD file against the schema for XSD to the CI/GH Actions workflows. * Adds validation of the PHPCSDebug XML docs against the new XSD schema file to the CI/GH Actions workflows. * Adds documentation about the XSD schema and how to use it to the README. * Adds extensive tests for the XSD schema to the integration test suite. * Adds a reference to the schema to the existing XML doc for the PHPCSDebug standard. Notes: * The XSD allows for multiple sets of `<standard>` elements, with each optionally having one or more `<code_comparison>`s. * The XSD allows for additional arbitrary attributes on select elements in the XML files. These use `lax` contents processing, as without it, the attributes must be explicitly defined in the XSD, and we don't know which attribute(s) some standard may want to add to their documentation. * The XSD has also been real-world tested against XML documentation files from PHPCS itself, WordPressCS, PHPCSExtra and more. Those all pass, except for a few were the XML doc actually contained errors, which confirms that the XSD will work in real-life situations. Co-authored-by: Juliette <[email protected]>
* Introduces an XSD schema file to allow for validating PHPCS XML docs files, i.e. the `Standard/Docs/Category/*Standard.xml` files. * Adds this file to the website build script so the file will also be available at a canonical URL via the website. * Adds validation of the XSD file against the schema for XSD to the CI/GH Actions workflows. * Adds validation of the PHPCSDebug XML docs against the new XSD schema file to the CI/GH Actions workflows. * Adds documentation about the XSD schema and how to use it to the README. * Adds extensive tests for the XSD schema to the integration test suite. * Adds a reference to the schema to the existing XML doc for the PHPCSDebug standard. Notes: * The XSD allows for multiple sets of `<standard>` elements, with each optionally having one or more `<code_comparison>`s. * The XSD allows for additional arbitrary attributes on select elements in the XML files. These use `lax` contents processing, as without it, the attributes must be explicitly defined in the XSD, and we don't know which attribute(s) some standard may want to add to their documentation. * The XSD has also been real-world tested against XML documentation files from PHPCS itself, WordPressCS, PHPCSExtra and more. Those all pass, except for a few were the XML doc actually contained errors, which confirms that the XSD will work in real-life situations. Co-authored-by: Juliette <[email protected]>
This PR adds the docs schema defined in WordPress Coding Standards.
The initial test setup and folder structure were done by @jrfnl.
I added the test cases, and also found one small issue in the schema (prooving why tests are necessary and awesome 😄).