Problem/Motivation
When running PHPCS in our builds for the Governor, we ran into one mild issue with some doc commenting.
Steps to reproduce
Run PHPCS in your build, find the following:
+ vendor/bin/phpcs
.............................E.............................. 60 / 62 (97%)
.. 62 / 62 (100%)
FILE: ...tlassian/pipelines/agent/build/web/themes/custom/mytheme/mytheme.theme
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
43 | ERROR | [x] There must be exactly one blank line before the
| | tags in a doc comment
| | (Drupal.Commenting.DocComment.SpacingBeforeTags)
43 | ERROR | [x] Trailing punctuation for @see references is not
| | allowed.
| | (Drupal.Commenting.FunctionComment.SeePunctuation)
45 | ERROR | [ ] Parameter tags must be defined first in a doc
| | comment
| | (Drupal.Commenting.DocComment.ParamNotFirst)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
Time: 366ms; Memory: 14MB
Proposed resolution
Create and test patch to change the comments to avoid php code sniffer errors.
Comments
Comment #2
saltednutComment #3
saltednutComment #5
saltednutAs a followup, there is also PHPStan issue that we found but it'll require either rewriting a function or just renaming it in the sub-theme when one is generated.
The workaround, for now, is to rename the global function inside client.theme - but this could be fixed permanently perhaps if a service was provided by the base theme. If needed, I can file another issue for that.
Comment #6
indranil roy commentedHey @saltednut, I have added the patch please verify it.
Comment #7
indranil roy commentedComment #8
saltednutThanks @Indranil Roy, there is a merge request pending so we may not need a patch?
Comment #9
kurttrowbridgeHello! I tested this, first confirming that I saw the PHPCS errors mentioned when the patch was not yet applied. After applying the MR as a patch, the PHPCS errors are no longer present. Marking RTBC as a result.
(That said, I should note that line 60 in the
.themefile—the comment starting with "Calculate the minimum and maximum"—warns me, both before and after, that it's lengthier than the 80-character limit in Drupal's standards. Not sure why it doesn't appear in your testing, so I didn't flip back to Needs Work in case it's just something I'm doing differently on my end.)Comment #10
spicy.werewolf commentedSince I am picking this up cold, I ran phpcs before attempting to apply the fixes in the MR and found a bunch of other errors and warnings. (So @kurttrowbridge, it wasn't just a local quirk!) I'm curious to know why the same test is showing people different results, but not enough to dig into that part. Here's what I am seeing:
as @saltednut pointed out, we need an MR, not a patch, so I'm going to fix the rest of these errors, and get it all merged.
Comment #11
spicy.werewolf commentedComment #14
spicy.werewolf commentedComment #15
spicy.werewolf commentedPoint of clarification: I am running code tests both on the starterkit itself, and an instance of the theme that gets spun up from running the starterkit script.
Comment #16
spicy.werewolf commentedI am not able to replicate the PHPStan error mentioned in #5 but that is probably because my test config isn't set up to check
/themes/contrib/. It seems like if it did, this error would happen for every helper function, or functions that don't contain the theme name, as they would slip passed being renamed by the starterkit script.I can't think of a use case where you would have both the starterkit, and the generated project theme installed at the same time, so I can't think of an instance where you'd actually hit this error in the wild. That said, if I change the name of the function in the starterkit to include "governer" after the underscore like this:
_governor_is_page_link_visiblewhen I run the script the function name is updated as expected, so even if one did have both the starterkit and the generated theme installed at the same time, you wouldn't get this error. I'll add this update to the MR.Comment #17
spicy.werewolf commentedUpdate:
The errors and warnings above coming from
src/StarterKit.phpcan probably be ignored. Given all the work that has been done to spin up new custom themes using the Coregenerate-themescript with just the starterkit.yml file, it looks as though we might not need that file at all. And it is removed from the generated theme, so isn't problematic there, since, you know, it doesn't exist there.The error thrown by the missing description in the generated theme can be avoided by adding a default theme description in the starterkit.yml file. Something like:
The warning getting thrown about the "Version", however, appears to be a Core bug relating to how the
generate-themescript handles Version tracking. I am able to replicate the error using the Corestarterkit_theme. In order for thegenerate-themescript to run at all, a version must be specified in the starterkit theme's info.yml file. However, the script adds a generated version as well. As a result, the generated theme's info.yml file will have both. e.g.The generated version number gets pulled from
governor.starterkit.yml:Remove the Version key, the script won't run, leave it in, and it throws an error. Don't specify a version in code>governor.starterkit.yml and an error is thrown in the generated info.yml file.
The easiest way to get rid of the error is to manually delete "Version: 1.0.0" from the generated info.yml file in the newly minted custom theme. But the 'correct' solution is for the generate-theme script not to add the Version key to the generated info.yml file in the first place, since, "version" is special: we want to allow it in core, but not anywhere else." (See vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php line 78).
I'll open a core issue to address this. I just wanted to get all my thoughts out here first.
Comment #18
spicy.werewolf commented