Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There is a new release of the Coder module. Some new sniffs were added. Let's fix them.
Comment | File | Size | Author |
---|---|---|---|
#42 | 2803779-42.patch | 54.93 KB | alexpott |
Comments
Comment #2
pfrenssenI tried autofixing the new rules that were added. It looks good overall. There are two new rules that are not autofixable, but this is fine, they actually require human intervention because it is not possible to automate these fixes. I've excluded them and will make followups to fix these:
Drupal.Commenting.FunctionComment.ParamTypeSpaces
- a parameter type declaration contains a space. This can be because two types were separated by a space instead of a pipe, or it might be documentation that crept into it. Needs human judgement.Drupal.Commenting.FunctionComment.ReturnTypeSpaces
- the same case, but for a return type declaration. Needs human intervention.There are two instances which are not correctly autofixed, in
HandlerBase
andArgumentPluginBase
the following code is wrongly autofixed:I think this case of using a slash instead of a pipe might be a good candidate to add as a dedicated sniff to Coder. We only have 2 instances of this in core, but I can imagine this to be a common occurrence in contrib or custom code.
Comment #3
pfrenssenIn this patch I hand-fixed the two instances of
@return TRUE/FALSE
to@return bool
. I think this should be OK, since this pattern is so exceedingly rare in the code base. The sniff correctly detects this too, so we can rest assured that if new patches would add this bad return value it will be detected.Comment #4
dawehnerAre you sure we don't have issues for those new sniffs already? I'm just wondering, because I would have expected that those more or less quite fundamental bits have been fixed already.
Comment #5
pfrenssenThese are the sniffs that are throwing errors now with the new version of Coder on the latest 8.3.x:
I had a look for issues mentioning these sniffs. Two already had issues but they were already fixed:
It appears that these sniffs have been improved in the new release of Coder so they found some more instances that needed to be fixed.
Comment #6
dawehnerwow, I would have not expected that coder can handle that complex case well, cool!
Should we go with array[] for all those 3 cases instead?
Comment #7
pfrenssenGood eye, those are indeed arrays of arrays. I agree it would be nice to update this now that we are touching those lines.
Comment #8
dawehnerThank you @pfrenssen!
Comment #9
dawehnerOne thing I'm wondering though is whether we should add coder to the require-dev bit first and then update the version there.
Comment #10
pfrenssenCreated followups for the two new sniffs that need to be fixed manually:
Comment #11
pfrenssenWell this issue is blocking all other coding standards related issues at the moment, and we already have a separate issue about the require-dev: #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core. I would rather not block this on the composer dependency update.
Comment #12
dawehner@pfrenssen
Well, we can keep using 8.2.7 on our global composer.json file, and be fine with that, can't we?
Comment #14
Mile23We fixed all the 'regressions' for coder 8.2.8 in #2747073: Fix Drupal CS regressions for Coder 8.2.8, so #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core will be OK if we stick to 8.2.8 there.
This issue could update the dependency to 8.2.9 and be patched against core 8.3.x.
Comment #15
pfrenssenOk I like this approach, but then this is blocked by #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core. Postponing on that issue.
Comment #16
pfrenssenRerolled against latest 8.3.x and latest version of #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core. This is still postponed on that issue, the patch only applies after that is in.
Interdiff only contains manual changes made, it excludes automatic code style fixes. I wasn't able to rebase the previous patch easily, there have been too many commits in the meanwhile.
Comment #17
pfrenssenHere is a patch containing only the manual work. This will make it easy to reroll this patch if needed. Just apply this, run
../vendor/bin/phpcbf -p
from thecore/
folder and post the result.Comment #18
pfrenssenForgot one part, in Coder 8.2.9 the test files are no longer part of the distribution build so they don't need to be excluded any more. This is also a manual change.
Comment #19
klausi#2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core is a bit derailed now and probably needs more time, so I think we can continue here with just the fixes. Can you reroll the patch without composer changes?
Comment #20
tstoecklerShouldn't we still leave them in in cased people install with
--prefer-source
?Comment #21
pfrenssenI personally think not, why would people use the
--prefer-source
option for a distribution build? It will have a lot more baggage than just the test files, it will even have the entire git history present for every project.Also, if you specify you want the source, you probably are about to start some development and you most likely want the full source, including tests :)
Comment #22
klausiFull patch of automated fixes and manual fixes from above.
Comment #24
xjmAs I understand this is blocking #2794567: Make core comply with new standard spacing for anonymous functions and enable the rule in phpcs.xml.dist and blocked by #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core, is that correct?
Comment #25
Mile23Sort of. The idea here was that since #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core locked us into then-recent Coder 8.2.8, we'd pick up the latest fixes here afterwards.
#2794567: Make core comply with new standard spacing for anonymous functions and enable the rule in phpcs.xml.dist requires a version of Coder >=8.2.9, which this issue doesn't supply any more, though it could.
Comment #26
pfrenssenI think updating to Coder 8.2.9 would be nicely in scope of this issue.
Comment #27
Mile23Rerolled and updated to bring us up to fixed for 8.4.x and Coder 8.2.9.
The only real problem is this one:
Comment #28
Mile23Comment #29
pfrenssenAs you mentioned, this is now incorrect.
This has been incorrectly documented. We don't allow specific values as parameter types. So actually there's no need to improve Coder for this, we just need to fix the documentation.
This parameter declaration should read:
I don't particularly like seeing this foreach() split on two lines. I think it is less readable, but it is technically allowed within the coding standards so let's give it a pass.
Comment #30
pfrenssenCoding standards fixes are still allowed in the RC phase.
Comment #31
naveenvalechaDrupal Coder 8.x-2.10 has been out on 14th December . Do we need a new followup issue for fixing 8..x-2.10?
Comment #32
pfrenssen@naveenvalecha I think that would be a good idea to do it in a separate issue, taking it one step at a time.
Comment #33
klausiRerolled + fixed BigPipe method as suggested.
Manually confirmed that phpcs output is clean and does not show errors after this patch.
Comment #34
klausiJust tested Coder 8.2.10 and it has 0 new errors with this patch, so we can update straight to that.
Fixing title, we are not fixing new sniffs here but existing sniffs that got better :-)
Comment #35
Mile23Checked that these constants are int, and they are: https://github.com/symfony/http-kernel/blob/master/HttpKernelInterface.p...
These are excluded as per #2, with follow-ups: #2803891: Fix 'Drupal.Commenting.FunctionComment.ReturnTypeSpaces' coding standard #2803893: Fix 'Drupal.Commenting.FunctionComment.ParamTypeSpaces' coding standard
Applies to both 8.3.x and 8.4.x, and phpcs passes for both.
Rawk.
Comment #36
naveenvalecha#34,
Awesome klausi to update the coder to 8.2.10
Patch looks good. However, it's still showing the warnings https://dispatcher.drupalci.org/job/drupal_patches/451/checkstyleResult/...
//Naveen
Comment #37
Mile23@naveenvalecha, those are *fixed* warnings. They're warnings fixed by the patch.
Comment #39
pfrenssenComment #40
klausidrupalci fail, queuing again.
Comment #41
xjmI'm sorry. I think I broke your patch by accidentally running 8.2.10 locally and overfixing a different commit.
That said, maybe we can fix the standards in separate issues first? Since 8.2.10 is just a patch-level update, it can go into a patch release or RC.
Comment #42
alexpottRerolled.
When I originally read the patch I thought why are we adding new rules - but of course we're not we're excluding new rules. So all the changes are due to fixes to existing rules that are applying. Hopefully. And yes if phpcbf can apply the fixes then it is probably okay just to run that.
Comment #45
alexpottComment #46
pfrenssenYes that is the idea. There have been some improvements to existing sniffs, but the newly added ones in 8.2.10 are excluded since they should be tackled in separate issues, to keep this manageable.
I'm setting this to RTBC. I have worked on earlier versions of this patch, but since this is 99% machine generated and I have not worked on it since the last RTBC I hope this is OK.
Comment #47
pfrenssenBTW these are the followups to fix the two new sniffs which are excluded here, they can be worked on when this is in: #2803891: Fix 'Drupal.Commenting.FunctionComment.ReturnTypeSpaces' coding standard, #2803893: Fix 'Drupal.Commenting.FunctionComment.ParamTypeSpaces' coding standard.
Comment #48
pfrenssenComment #49
alexpottCommitted and pushed fea11b6 to 8.4.x and 71fa660 to 8.3.x. Thanks!
I've tested this locally on both 8.3.x and 8.4.x everything passes PHPCS nice.
Comment #51
alexpottComment #53
klausiNext Coder update: #2857714: Upgrade Coder to 8.2.11