-
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
Add Squiz.Commenting.DocCommentAlignment sniff #8
Comments
Hmm, but then that sniff flags the following code:
It says the
So might need to make our own sniff for this... |
Ah ha! Worked out how to exclude that one sniff message that was causing issues:
I also re-arranged the ruleset.xml slightly so that all Squiz sniffs are listed together, rather than having regular ones up top and then overridden ones below (makes it easier to find what you're looking for if they're all together). |
I'll try to test ASAP. Yes, some of the Squiz rules overlap with the one(s) forked from Drupal, so extra care has to be taken. At least, we don't want to produce false positives. 😉 |
@BWPanda are you sure this behaves as intended? If I'm doing it wrong like:
I get:
That seems a bit misleading, as the problem is in line 7 (indented one space, but shouldn't be). |
This addresses issues where the docblock's opening tag is aligned properly but the rest of the docblock isn't. For issues like your example where the opening tag of a docblock is misaligned to the function, we'll need to find a sniff for that too I guess. But that could be a separate issue and doesn't mean this PR doesn't work. |
I partly agree, we should figure out how to address this docblock misalignment. But ... as your PR only partly addresses it, this leads to a WTF with misleading messages. Maybe we can fix that in a way, that doesn't introduce confusion? Here's the source code of that sniff: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php Maybe we find something in Drupal-land: https://github.com/pfrenssen/coder |
@indigoxela Thanks for the tip. I found that running Drupal's sniffs on a test file flagged the error we're having. The related sniff was one of their custom ones (that they've forked from squizlabs). So I copied it to our sniffs and it seems to work (PR updated): <?php
/**
* @file
* A test file for PHPCS.
*/
/**
* This function returns 'blah'.
*/
function tester() {
return 'blah';
}
/**
* This function returns 'yada'.
*/
function tester2() {
return 'yada';
} Returns:
It doesn't flag the other lines in the same docblock, unless you fix just the first one then run it again. But I think that's fine (most people would notice the issue and just fix the entire docblock). |
At first I was exited, but then... this flags more than just comments. An example:
Do we have definitions for that in Backdrop coding standards? It might be that it actually makes sense that this is an error, but ... Re the misleading nagging with misaligned function comments: if I get it right, we do not need Squiz.Commenting.DocCommentAlignment.SpaceAfterStar anymore? Or do we? |
@indigoxela So I was a bit confused by all this, and decided to try building a standard from scratch to see what sniffs we needed and which we didn't. Here's what I've spent some time over the last few weeks doing:
This eventually helped me to come up with a list of good and bad sniffs. Of the ~119 sniff messages in the Generic standard, I excluded ~55 bad ones. So as you can see, it seems to be better to include the full Generic and Squiz standards, then exclude specific sniffs/messages that don't match our coding standards (rather than just including specific sniffs as we do now). Would you like my new Standard as a PR here, or in a new issue? I think it addresses the issues here we've been discussing here: <?php
/**
* @file
* A test file for PHPCS.
*/
/**
* This function returns 'blah'.
*/
function tester() {
return 'blah';
}
/**
* This function returns 'yada'.
*/
function tester2() {
return 'yada';
}
function foo() {
db_update('i18n_string')
->fields($update + array(
'type' => $source->type,
'objectid' => $source->objectid,
'property' => $source->property,
'objectindex' => $source->objectindex,
))
->condition('lid', $source->lid)
->execute();
}
|
Wow, thank you so much, to put all that effort here. 🙏 If you prefer to attach your PR here, it might make sense to adapt the issue description. Or start a new one - whatever seems better. |
I decided a new issue might be better, since this is a fairly significant change. We can always close this issue later if it's no longer necessary if/when the other PR is merged. |
I saw this issue in a file that wasn't picked up by any of the current sniffs:
This will be flagged if we add the 'Squiz.Commenting.DocCommentAlignment' sniff.
The text was updated successfully, but these errors were encountered: