An ignore that does nothing looks exactly like an ignore that works.
That sentence is the whole problem. phpcs:ignore leaves no trace when it misses. There is no warning, no unused-suppression notice, nothing in the report. The line is quiet, the build is green, and the annotation has been decorative for eighteen months.
On one codebase I audited, 9 of 169 annotations suppressed nothing at all — measured on 22 August 2026. Each had been written on a statement's closing line rather than the line the sniff actually reports. A further 21 named a sniff that fires nowhere near them, five of those from a ruleset the project does not even load. Seventeen named a family prefix rather than a sniff. And 117 carried no reason at all.
None of that was visible in review, because it is not visible at all.
The measurement
PHP_CodeSniffer has a flag that turns annotations off: --ignore-annotations. That is the whole trick. Run phpcs twice over the same ruleset and the same files, once honouring the annotations and once not, and the difference is the set of findings the annotations actually suppress — measured, not inferred from reading them.
function coffee_phpcs_findings( string $site, bool $honour ): array {
$command = sprintf(
'cd %s && vendor/bin/phpcs --standard=phpcs.xml.dist --report=json -q%s 2>/dev/null',
escapeshellarg( $site ),
$honour ? '' : ' --ignore-annotations'
);
$json = shell_exec( $command );
$start = strpos( $json, '{' );
$report = json_decode( substr( $json, $start ), true );
$out = array();
foreach ( $report['files'] as $path => $data ) {
foreach ( (array) ( $data['messages'] ?? array() ) as $message ) {
$out[ (string) $path ][] = array(
'line' => (int) $message['line'],
'source' => (string) $message['source'],
'type' => (string) $message['type'],
);
}
}
return $out;
}Code language: PHP (php)
Diff the two reports on line|source, and everything present in the unhonoured run but absent from the honoured one is a suppressed finding:
foreach ( $unhonoured as $path => $messages ) {
$live = array();
foreach ( $honoured[ $path ] ?? array() as $message ) {
$live[ $message['line'] . '|' . $message['source'] ] = true;
}
foreach ( $messages as $message ) {
if ( ! isset( $live[ $message['line'] . '|' . $message['source'] ] ) ) {
$suppressed[ $path ][] = $message;
}
}
}Code language: PHP (php)
Attribute each suppressed finding to the annotation covering its line, and an annotation with nothing attributed to it is inert by construction. No heuristics.
Seven verdicts, not one
Once you have that mapping, "does it work" is not the only question worth asking. The audit I run emits seven:
| Verdict | Meaning |
|---|---|
INERT |
suppresses no finding at all |
BARE |
names no sniff, so it suppresses everything on the line |
UNNAMED |
suppresses a sniff it does not name |
DEAD NAME |
names a sniff that suppresses nothing here |
FAMILY |
names a prefix rather than the exact message code |
NO REASON |
carries no -- why the sniff is wrong here |
REDUNDANT |
an ignore inside a disable block that is doing the work |
ORPHAN |
a suppressed finding no annotation accounts for |
FAMILY is the one people argue about, and it is the one I would keep. A prefix such as WordPress.DB.DirectDatabaseQuery silences whatever is later added underneath it. That is how a suppression written for one finding in 2023 quietly covers a different, real one in 2026:
if ( ! $exact && array() === $family ) {
$problems[] = sprintf( 'DEAD NAME %s names %s, which suppresses nothing here', $where, $sniff );
continue;
}
// "Name the exact sniff, not a family." A prefix silences whatever
// else is later added under it, which is how a suppression outlives
// the finding it was written for.
if ( ! $exact ) {
$problems[] = sprintf( 'FAMILY %s names %s, a prefix; say %s', $where, $sniff, implode( ', ', $family ) );
}Code language: PHP (php)
Find the annotations the way PHPCS finds them
The first version of this scanner used a regex over each line. It was wrong twice, and both failures are instructive.
It matched inside string literals. As soon as the tool's own bin/ directory was added to the ruleset's scope, it began reporting "annotations" inside its own source — the string 'phpcs:ignore' === $kind, and the prose in its own docblock explaining the syntax. PHP_CodeSniffer does not have this problem, because File::_addSuppression() only recognises the directive inside a real T_COMMENT or T_DOC_COMMENT token. So scan by token:
foreach ( token_get_all( $source ) as $token ) {
if ( ! is_array( $token ) ) {
$last_real_line = $current_line;
continue;
}
list( $id, $text ) = $token;
$current_line = $token[2];
if ( T_COMMENT !== $id && T_DOC_COMMENT !== $id ) {
$last_real_line = $current_line + substr_count( $text, "n" );
$current_line = $last_real_line;
continue;
}
// ... this is a comment; now look for the directive
}Code language: PHP (php)
And it matched anywhere in the comment. PHPCS only honours the directive at the start of a comment's content, after stripping the comment's own opening characters. A docblock that mentions phpcs:ignore in the third paragraph is prose, not a directive. Mirror the real rule exactly:
$stripped = ltrim( $text, " t/*#" );
if ( ! preg_match( '/^phpcs:(ignoreFile|ignore|disable|enable)b([^n]*)/', $stripped, $match ) ) {
continue;
}Code language: PHP (php)
The coverage rules matter too, and they are the reason for the original 9-of-169 finding: phpcs:ignore on a line of its own covers that line and the next; written at the end of a line of code it covers only that line. phpcs:disable runs to the matching phpcs:enable or the end of file.
$covers = array( $number );
if ( 'phpcs:ignore' === $kind && ! $inline ) {
$covers[] = min( $number + 1, $count );
}Code language: PHP (php)
Put an annotation on the closing ); of a multi-line call and it covers the closing line and the one after — neither of which is where the sniff reports. It reads as if it works.
Then the bigger fish: the check that was never running
While fixing the annotations, the audit turned up something the annotations were only the symptom of. A whole class of them reported as suppressing nothing — not because the annotations were wrong, but because the sniff they named could not fire at all under the combined ruleset, with or without them.
The cause is a documented but easily-missed resolution rule. WooCommerce-Core's own ruleset.xml excludes WordPress.DB.DirectDatabaseQuery.DirectQuery inside its own <rule ref="WordPress"> block, because WooCommerce core makes direct queries. That is a four-segment message code, and Ruleset::processRuleset() resolves a four-segment exclude as "set this exact message's severity to zero" against one shared, ruleset-wide table — not as a removal scoped to WooCommerce-Core's own inclusion.
So combining WordPress, WordPress-VIP-Go and WooCommerce-Core in one ruleset silenced the project's main direct-query check everywhere. Referencing the sniff again in a later <rule ref> does not undo it. Only an explicit severity does:
<rule ref="WordPress.DB.DirectDatabaseQuery.DirectQuery">
<severity>5</severity>
</rule>
<rule ref="WordPress.DB.DirectDatabaseQuery.NoCaching">
<severity>5</severity>
</rule>
<rule ref="WordPress.DB.DirectDatabaseQuery.SchemaChange">
<severity>5</severity>
</rule>Code language: HTML, XML (xml)
A second instance turned up the same week, found while verifying the first: WordPressVIPMinimum excludes WordPress.Security.ValidatedSanitizedInput.MissingUnslash the same way, and WordPress-VIP-Go pulls that ruleset in wholesale. Unslash-before-sanitise had been off project-wide. Restoring it surfaced three real findings, including a $_POST value being written straight into post meta.
Booting the ruleset instead of reading the XML
Two instances of the same defect is a pattern, and the pattern says: do not read the XML. Two hundred and seventy-one four-segment excludes are declared across the four combined standards, and which of them survive composition depends on ordering and on later re-inclusions. Boot PHP_CodeSniffer's own Ruleset and ask it:
require $site_dir . '/vendor/autoload.php';
require $site_dir . '/vendor/squizlabs/php_codesniffer/autoload.php';
use PHP_CodeSnifferConfig;
use PHP_CodeSnifferRuleset;Code language: PHP (php)
Dump every message code the composed standard resolves to severity zero, sort it, and diff it against a reviewed baseline on every CI run. On this project that baseline is 324 codes, each one reviewed once and either explained by a live replacement sniff or accepted as a documented divergence. A composer update that newly silences a code nobody reviewed now fails loudly instead of shipping unnoticed a third time.
What it reports now
Run today, against the same codebase:
$ php bin/phpcs-ignore-audit.php
331 annotation(s), 331 of them load-bearing; 579 finding(s) suppressed.
Every suppression suppresses something, names exactly what it suppresses, and says why.Code language: Shell Session (shell)
Three hundred and thirty-one annotations, every one of them doing something, every one naming what it does and why. That is a materially different codebase from the one with 169 annotations of which 9 were inert, 21 named dead sniffs and 117 had no reason — and the difference is not discipline. It is that the check now fails the build.
Prove the checker itself still fires
There is one more layer to this, and it is the layer that makes the rest trustworthy.
An audit that reports "331 of 331 load-bearing" is only meaningful if phpcs was actually scanning the files. A ruleset that is configured but not firing produces output indistinguishable from clean code, and the scope of a ruleset rots quietly: on this project scope is an explicit allow-list, so a new plugin or theme is invisible to the whole quality stack until someone adds its path.
So the same build runs a self-test. It plants a known violation of each ruleset family in a first-party file and asserts each comes back by name — one sniff per ruleset, so a missing line means that ruleset is not loaded rather than that the code improved:
for sniff in
"WordPress.PHP.YodaConditions.NotYoda"
"WordPressVIPMinimum.Performance.NoPaging"
"WooCommerce.Commenting.CommentHooks"
"PHPCompatibility.FunctionUse.RemovedFunctions"
do
if contains "$REPORT" "$sniff"; then
pass "$sniff reported"
else
fail "$sniff NOT reported — its ruleset is configured but not firing"
fi
doneCode language: Bash (bash)
Then it plants the same violations under vendor/ and asserts none of them is reported — and takes both assertions from the same run, because the positive one is what stops the negative one being satisfied by a phpcs that fell over and printed nothing.
Even the comparison operator in there is load-bearing. It is a bash substring test rather than the obvious printf … | grep -q, and the comment says why:
# Substring test in bash, deliberately not `printf … | grep -q`. Under
# `set -o pipefail` a grep that matches early kills the printf with SIGPIPE, the
# pipeline reports that failure, and a successful match reads as a miss.
contains() { [[ "$1" == *"$2"* ]]; }Code language: Bash (bash)
That turned a working leak-detector into a pair of false failures the first time the script was mutation-tested — which is the same class of bug the script exists to catch, one level up. If you write a checker, try to make it fail on purpose before you trust it passing.
The same reasoning applies to the static analysis baseline sitting next to it. A baseline file is a debt figure, not a fix, and regenerating it to make a run go green silently converts it into a suppression file — the identical failure to the inert annotation, one tool along. If the number is not going down, nobody is paying it off.
The rule I would write down
A phpcs:ignore is acceptable only when the sniff is genuinely wrong about that line, and then it must name the exact message code, sit on the line the sniff actually reports, and carry a -- reason explaining why the sniff is wrong there — not what the code does.
That rule is unenforceable by review. Nobody can see an inert annotation. It is enforceable by a script, in about five hundred lines, and the script is worth more than the rule.
If your build is green and you are not sure what it is checking, that is the kind of technical audit I do. The stack is on my CV, and the contact page says what to include if you want to talk about it.