Add script to validate code examples in sniff documentation #185
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new script that verifies code examples in PHPCS sniff documentation. The script checks that "Valid" examples don't trigger the sniff and "Invalid" examples do trigger the sniff, ensuring code examples correctly demonstrate the behavior of the sniff.
Noteworthy implementation decisions:
phpcs-check-sniff-doc-code-examples
.token_get_all()
with the flag TOKEN_PARSE. This means that PHP >= 7.0 is required to run this script while the rest of the repository requires PHP >= 5.4. A requirement check was added tophpcs-check-sniff-doc-code-examples
to alert users if they are running PHP < 7.0, and a warning was added to the top of the file informing thatphpcs-check-sniff-doc-code-examples
must remain compatible with PHP 5.4 for the requirement check to work.<code>
block. This means that for invalid examples, the script might miss ones that don't trigger the sniff if, in the same<code>
block, there is at least one example that does trigger the sniff.How it works
The script:
How to use the script
The script will search for all sniff documentation files and check their code examples. For other ways to run the script check the help page:
Related issues
Closes #142