-
Notifications
You must be signed in to change notification settings - Fork 1
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
@file in a file containing a class triggers the "Namespaced classes, interfaces and traits should not begin with a file doc comment" error #10
Comments
@kiamlaluno funny, if I paste your example into a file and check with phpcs, it passes here with the Backdrop ruleset. What else is missing to trigger the error? Can you provide a full example, please? And can you also run it with the |
I edited the core/includes/anonymous.inc file to add the following lines, but I did not get any error from /**
* @file
* Contains \AnonymousUser.
*/ I was just creating a class file, and the editor I use, which automatically run This is the full content of the file causing that report. <?php
/**
* @file
* Contains \MyModule\Iid.
*/
namespace MyModule;
/**
* Handles a unique identifier associated to user accounts.
*/
class Iid implements IidInterface {
/**
* {@inheritoc}
*/
public static function loadFromCookies() {
}
/**
* {@inheritoc}
*/
public static function loadFromDatabase($uid) {
}
/**
* Constructs a \MyModule\Iid instance.
*/
protected function __construct() {
}
} The report from
|
I tried changing namespace, removing the |
I am not sure this is relevant, but I was first getting an error about a empty line that should not be put between |
If I remove the namespace, I do not get the Namespaced classes, interfaces and traits should not begin with a file doc comment error anymore (which is expected), but I get a There must be no blank lines before the file comment error. If I re-add the namespace, I get the first error, but not the second. |
So it actually seems to be related to the namespace declaration... Again, can you please report the full output of Edit: all good, that just happened. 😸 |
There is another "issue," but I would leave that for another report: If the class name is namespaced, I can put an empty line before the |
If I do it as follows, I get no errors:
In the code you posted, there's also an indent error, BTW - the closing So... sorry for the question, but ... |
I use the namespace to avoid conflicts with other modules. |
The relevant code used by FileCommentSniff.php is the following one (line 61 and following). // Files containing exactly one class, interface or trait are allowed to
// ommit a file doc block. If a namespace is used then the file comment must
// be omitted.
$oopKeyword = $phpcsFile->findNext([T_CLASS, T_INTERFACE, T_TRAIT], $stackPtr);
if ($oopKeyword !== false) {
$namespace = $phpcsFile->findNext(T_NAMESPACE, $stackPtr);
// Check if the file contains multiple classes/interfaces/traits - then a
// file doc block is allowed.
$secondOopKeyword = $phpcsFile->findNext([T_CLASS, T_INTERFACE, T_TRAIT], ($oopKeyword + 1));
// Namespaced classes, interfaces and traits should not have an @file doc
// block.
if (($tokens[$commentStart]['code'] === T_DOC_COMMENT_OPEN_TAG
|| $tokens[$commentStart]['code'] === T_COMMENT)
&& $secondOopKeyword === false
&& $namespace !== false
) {
if ($tokens[$commentStart]['code'] === T_COMMENT) {
$phpcsFile->addError('Namespaced classes, interfaces and traits should not begin with a file doc comment', $commentStart, 'NamespaceNoFileDoc');
} The first comment makes sense to me, but it does not match with what the coding standards say. |
Interesting... that rule has been forked from Drupal, so we might need to further adapt. However, as I read that part of our docs, the standard is still WIP. https://docs.backdropcms.org/doc-standards#classes So not sure, if we now should adapt the sniff or wait for a core decision. |
That is because the class is not put in a namespace. |
I'm aware of that. 😁 Our phpcs sniffs are - just like our coding standards - WIP. The question here is: what has to happen next. Core (doc) discussion or sniff adaption? |
Starting a class file with the following lines causes
phpcs -s --standard="~/.config/phpcs_rulesets/Backdrop" ./
to report an error.The error the following. (I changed the absolute filename to relative and shorted the separation lines.)
The Backdrop coding standards say
@file
should be used with file containing a class too.The text was updated successfully, but these errors were encountered: