Skip to content

Commit 4e045f2

Browse files
committed
✨ New feature: script to check that sniffs are "feature complete"
This adds a custom script which will check whether each and every sniff is accompanied by a documentation XML file (warning) as well as unit test files (error). The script will be available in the Composer `vendor/bin` directory as `phpcs-check-feature-completeness`. Notes: * To only show errors, the script can be run in `quiet` mode by passing the `-q` flag on the command line. See the included documentation in the `README.md` file for other available options. * The script has been set up in such a way that it can both be used by PHPCS itself, as well as by external standards which use the PHPCS native unit test suite. To use the tool, run it from the root of the external standards repo like so: `vendor/bin/phpcs-check-feature-completeness` or when not installed via Composer: `php -f "path/to/PHPCSDevTools/bin/phpcs-check-feature-completeness"` * The list of sniffs to check completeness for is determined by getting a list of all files in `Sniffs` directories, where the files have a name ending with `Sniff.php` and not prefixed with `Abstract`. * The "has tests" check verifies that a `UnitTest.php` file is present for each sniff in the standard's `Tests` directory and _at least_ one test case file. * The "has docs" check verifies that a `Standard.xml` file is present for each sniff in the standard's `Docs` directory. When implementing this check in CI, it only needs to be run on one build as the results won't change between PHP versions. An earlier version of this script was originally pulled to PHPCS itself in PR 2364.
1 parent bfc4899 commit 4e045f2

6 files changed

Lines changed: 666 additions & 0 deletions

File tree

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This is a set of tools to aid developers of sniffs for [PHP CodeSniffer](https:/
2323
+ [Composer Global Installation](#composer-global-installation)
2424
+ [Stand-alone Installation](#stand-alone-installation)
2525
* [Features](#features)
26+
+ [Checking whether all sniffs in a PHPCS standard are feature complete](#checking-whether-all-sniffs-in-a-phpcs-standard-are-feature-complete)
2627
+ [PHPCSDev ruleset for sniff repos](#phpcsdev-ruleset-for-sniff-repos)
2728
* [Contributing](#contributing)
2829
* [License](#license)
@@ -64,6 +65,52 @@ composer global require phpcsstandards/phpcsdevtools:^1.0
6465
Features
6566
------------------------------
6667

68+
### Checking whether all sniffs in a PHPCS standard are feature complete
69+
70+
You can now easily check whether each and every sniff in your standard is accompanied by a documentation XML file (warning) as well as unit test files (error).
71+
72+
To use the tool, run it from the root of the your standards repo like so:
73+
```bash
74+
# When installed as a project dependency:
75+
vendor/bin/phpcs-check-feature-completeness
76+
77+
# When installed globally with Composer:
78+
phpcs-check-feature-completeness
79+
80+
# When installed as a git clone or otherwise:
81+
php -f "path/to/PHPCSDevTools/bin/phpcs-check-feature-completeness"
82+
```
83+
84+
If all is good, you will see a `All # sniffs are accompanied by unit tests and documentation.` message.
85+
86+
If there are files missing, you will see errors/warnings for each missing file, like so:
87+
```
88+
WARNING: Documentation missing for path/to/project/StandardName/Sniffs/Category/SniffNameSniff.php.
89+
ERROR: Unit tests missing for path/to/project/StandardName/Sniffs/Category/SniffNameSniff.php.
90+
```
91+
92+
For the fastest results, it is recommended to pass the name of the subdirectory where your standard is located to the script, like so:
93+
```bash
94+
phpcs-check-feature-completeness ./StandardName
95+
```
96+
97+
#### Options
98+
```
99+
directories One or more specific directories to examine.
100+
Defaults to the directory from which the script is run.
101+
-q, --quiet Turn off warnings for missing documentation.
102+
--exclude Comma-delimited list of (relative) directories to exclude
103+
from the scan.
104+
Defaults to excluding the /vendor/ directory.
105+
--no-progress Disable progress in console output.
106+
--colors Enable colors in console output.
107+
(disables auto detection of color support)
108+
--no-colors Disable colors in console output.
109+
-h, --help Print this help.
110+
-V, --version Display the current version of this script.
111+
```
112+
113+
67114
### PHPCSDev ruleset for sniff repos
68115

69116
Once this project is installed, you will see a new `PHPCSDev` ruleset in the list of installed standards when you run `phpcs -i`.

0 commit comments

Comments
 (0)