Page MenuHomePhabricator

PHP Codesniffer errors and warnings misleading for phpunitannotations sniff
Closed, ResolvedPublic

Description

I'm not sure but I find this MW Codesniffer warnings/errors a little misleading to me;

14:17:28 ----------------------------------------------------------------------
14:17:28 FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
14:17:28 ----------------------------------------------------------------------
14:17:28  6 | WARNING | The phpunit annotation @group should only be used
14:17:28    |         | inside classes or traits.
14:17:28    |         | (MediaWiki.Commenting.PhpunitAnnotations.NotClassTrait)
14:17:28  7 | WARNING | The phpunit annotation @coversDefaultClass should only
14:17:28    |         | be used inside classes or traits.
14:17:28    |         | (MediaWiki.Commenting.PhpunitAnnotations.NotClassTrait)
14:17:28 ----------------------------------------------------------------------

So it's saying that the @group annotation should be inside a class or trait declaration but it's not the case, it should instead say "One new line expected after the /** @group */ comment block but two given" as this annotation should be immediately above the class declaration.

See https://integration.wikimedia.org/ci/job/wmf-quibble-vendor-mysql-hhvm-docker/10134/console for more info.

MediaWiki Codesniffer accepts the below;

/**
 * @group Foo
 */
class Bar {
}

but error out, see below;

/**
 * @group Foo
 */

class Bar {
}

If there are 2 new lines after the group annotation, php codesniffer produces that message. Maybe I'm wrong!

Event Timeline

The comment must placed directly before the class to be a class comment.
A comment not before the class are file comments and in a file comment the annoation is useless, because phpunit does not read it.

So I would say the text needs some adjustment when it is a file comment and not a class or function comment.

But the text must also match when there is a file comment and a class comment. So a hint with the newline would not be correct for:

/**
 * @group Foo
 */

/**
 * Test for Bar
 */
class BarTest {
}

What about "The PHPUnit annotation @group should only be used in comments describing a class or trait"?

Change 481650 had a related patch set uploaded (by Umherirrender; owner: Umherirrender):
[mediawiki/tools/codesniffer@master] Adjust warning text for PhpunitAnnotations.NotClassTrait sniff

https://gerrit.wikimedia.org/r/481650

Umherirrender renamed this task from PHP Codesniffer errors and warnings misleading(?) to PHP Codesniffer errors and warnings misleading for phpunitannotations sniff.Dec 31 2018, 6:07 PM
Umherirrender claimed this task.
Umherirrender triaged this task as Medium priority.

Change 481650 merged by jenkins-bot:
[mediawiki/tools/codesniffer@master] Adjust warning text for PhpunitAnnotations.NotClassTrait sniff

https://gerrit.wikimedia.org/r/481650