Problem/Motivation
Following from #2908391: Add a rule for expected format of @deprecated and @trigger_error() text we need to fix core to adhere to the two new coding standards.
This issue will fix the @deprecated
doc tag to adhere to the main Deprecated.IncorrectTextLayout
standard. Follow-up issues will fix the version formats, missing @see tag and missing extra-info.
Proposed resolution
Do an automated conversion with a work-in-progress PHPCS fixer (see #3057988: Automatically fixing @deprecated doc text). This creates quite a huge patch and we want to commit this as a first chunk to make reviewing easier.
Remaining tasks
Commit the first huge automated conversion chunk- Follow-up with patches to fix the rest (manually)
- Enable the new Drupal.Commenting.Deprecated in phpcs.xml
See #3094454: Fix remaining @deprecated manually and enable the coding standard for stesp 2 and 3.
Process to check and fix this coding standard
Step 1: Preparation
Open the file core/phpcs.xml.dist
and add a line for the sniff of this ticket. The sniff name is in the issue title. Make sure your patch will include the addition of this line.
Step 2: Install & configure PHPCS
Install PHP CodeSniffer and the ruleset from the Coder module:
$ composer install
$ ./vendor/bin/phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer
Once you have installed the phpcs package, you can list all the sniffs available to you like this:
$ ./vendor/bin/phpcs --standard=Drupal -e
This will give you a big list of sniffs, and the Drupal-based ones should be present.
Step 3: Prepare the phpcs.xml file
To speed up the testing you should make a copy of the file phpcs.xml.dist
(in the core/
folder) and save it as phpcs.xml
. This is the configuration file for PHP CodeSniffer.
We only want this phpcs.xml file to specify the sniff we're interested in. So we need to remove all the rule items, and add only our own sniff's rule. Rule items look like this:
<rule ref="Drupal.Commenting.Deprecated"/>
Remove all of them, and add only the sniff from this issue title. This will make sure that our tests run quickly, and are not going to contain any output from unrelated sniffs.
Step 4: Run the test
Now you are ready to run the test! From within the core/
folder, run the following command to launch the test:
$ cd core/
$ ../vendor/bin/phpcs -p
This takes a couple of minutes. The -p
flag shows the progress, so you have a bunch of nice dots to look at while it is running.
Step 5: Fix the failures
When the test is complete it will present you a list of all the files that contain violations of your sniff, and the line numbers where the violations occur. You could fix all of these manually, but thankfully phpcbf
can fix many of them. You can call phpcbf like this:
$ ../vendor/bin/phpcbf
This will fix the errors in place. You can then make a diff of the changes using git. You can also re-run the test with phpcs and determine if that fixed all of them.
Comment | File | Size | Author |
---|---|---|---|
#58 | interdiff-3048498-50-57.txt | 15.95 KB | Lendude |
#57 | 3048498-57.fix-@deprecated.patch | 274.21 KB | jonathan1055 |
#56 | 3048498-56.fix-@deprecated.patch | 284.89 KB | jonathan1055 |
Comments
Comment #2
naveenvalechaComment #3
naveenvalechaRetitling to better reflect the issue.
Updating issue summary to add what needs to be done so that we could get more contributors
Attaching the file which only includes the coding standard rule change
Comment #4
naveenvalechapostponing it on #3048244: Update the stable version of drupal/coder to ˆ8.3.2
Comment #5
naveenvalechaback to Active #3048244: Update the stable version of drupal/coder to ˆ8.3.2 In the meanwhile, I updated the issue summary @alexpott committed the other issue.
Comment #6
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHere is a patch which add the single new sniff and removes all others. Also I am going to see if this works, making a change to drupalci.yml to not run the phpunit tests, which take a long time.
Obviously, these big changes are only so we can get quick test results on d.o.. The full set of phpunit tests will need to be run once the bulk of the standards work has been completed in a patch.
Comment #7
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedBetter patch
Comment #8
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThe patch in #7 ran nice and quickly, 1 min 28s compared to 50 mins for the full phpunit run.
It showed 3283 coding standards messages, but some were not for @deprecated. I took too much out of phpcs.xml.dist - some internal sniffs appear to be run by default even without having a specific include in the phpcs.xml file.
Comment #9
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedSo 946 coding messages is the starting point. Nice that it is under 1000!
Comment #10
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedRe-rolled.
This patch is not for committing, only to show the extent of warnings in core code.
Comment #11
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThere are now 948 warning messages for @deprecated tag in core.
However, work on fixing these should be postponed until any possible change in the standard is agreed and the sniff ammended. The standard was all agreed by 13 March at comment #68 on #3024461-68: Adopt consistent deprecation format for core and contrib deprecation messages but since implementaion of the coder rule there has been further disagreements - read from comment #86
Comment #12
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedWork can re-start on this now that we have agreement on the standards text on #3024461: Adopt consistent deprecation format for core and contrib deprecation messages
Core currently only uses Coder version 8.3.2 so here is a patch which runs the updated sniff (via applying a patch in drupalci.yml).
Comment #13
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedNow that Core uses Coder 8.3.4 the patch to Coder in drupalci.yml is not required, so here is a simplified version.
Comment #14
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedUsing a starter patch from #3033332: [META] Fix language and consistency of deprecation messages and annotations here is a first attempt at fixing some of the deprecated messages. There are many more to fix.
edit: This patch has reduced the errors and warnings from 960 down to 873, a drop of 87 or nearly 10%
Comment #15
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedI've done some work to get PHPCS to generate automatic fixes for the @deprecated text - see #3057988: Automatically fixing @deprecated doc text
The patch here updates Coder to have this new functionality and the test run should (hopefully) generate a patch to fix a large proportion of the messages.
Comment #16
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedNow with the generated phpcs patch added.
Edit: 778 warnings remaining so this fixed 182/960 = 19%
Comment #17
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedEnhanced to cover more common errors in the text. When a @deprecated tag failure is found, the following pattern is tried:
/(as of|in) (Drupal|drupal)( |:)(.+)(,| and) (will be|is) removed (from|before|in) (Drupal|drupal)( |:)([\d\.]+)\.(.*)$/
If this matches, then we know how to correct the text.
Patch generated locally, coder changes also uploaded and applied.
Edit: 571 warnings remain, so this now fixes 389 / 960 = 40.5%
Comment #18
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedFurther enhancements to catch some more common fails. Pattern is
474 warnings remain, so this patch now fixes 486 / 960 = 50.6% by automated correction
Comment #19
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedRe-run the base patch to check new total number of warnings and generate new phpcs patch.
Edit: 930 errors and warnings in the current core 8.8 dev
Comment #20
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedNow with the generated fixes
Edit: 410 warnings remain, so this now fixes 520 / 930 = 55.9%
Comment #21
klausiPatch looks good to me. It is getting quite huge already and hard to review. Do you want to continue converting here or should we commit this first set of automated conversions? It covers more than 50% already, so would be quite a substantial step already.
If we do that we also need a green test run with the default testing setup.
Comment #22
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHere's a patch which will run the full test suite. I think it would be good to get these committed, then the next steps will be smaller.
I have checked locally that the patch applies (had to make one change and re-rolled) but I have not run the core tests locally. This processes all the sniffs not just the new one.
Comment #23
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedSo the tests are green and there are 413 warnings remaining (compared to 410 in #20 7 days ago). I have compared the phpcs output and the new ones are only @deprecated so this patch does not introduce any other error.
I'd be happy if this could be committed now, and we tackle the rest in stages. I know that Garbor was also leaning towards that plan in #3048495-39: Fix Drupal.Semantics.FunctionTriggerError coding standard
Comment #24
klausiPatch looks clean, no other changes than converting those @deprecated messages.
Updated the issue summary with the current action plan.
Comment #25
alexpottWe shouldn't be committing a fix that results in errors whilst running
composer phpcs
- applying this patch makes that happen.If we change the phpcs.xml change to be something like
Then we can focus on only fixing (Drupal.Commenting.Deprecated.IncorrectTextLayout. And then followup patches do each of DeprecatedMissingSeeTag, DeprecatedVersionFormat and DeprecatedWrongSeeUrlFormat in turn.
Comment #26
klausiAh, good point - sorry, I overlooked the phpcs.xml.dist change.
Comment #27
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedYes you are right, but I was not intending the commit to include the addition of any of the new rules in the first instance. Klausi and I just wanted to get the first 520 fixes done (which is 55% of the whole) so that the manual changes are in a more manageable patch. The manual fixes will take a while and each time it is bound to involve a re-roll of that patch which fixes the 520 because of core commits elsewhere.
OK, here's the same patch, but using the change to phpcs.xml.dixt from #25 to only add the specific
Drupal.Commenting.Deprecated.IncorrectTextLayout
rule.Comment #28
alexpottSo I think a way forward here is to commit the changes without the phpcs.xml.dist change at all. It'll reduce the noise on an issue trying to do the rest.
One issue is that atm the moment this is doing changes like:
I do think that messages we fix here should comply with both
Drupal.Commenting.Deprecated.IncorrectTextLayout
andDrupal.Commenting.Deprecated.DeprecatedVersionFormat
so we don't end up changing the same lines twice.Comment #29
Gábor Hojtsy@jonathan1055 are you planning to continue working on this?
Comment #30
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedYes, I will work on this. Sorry, I've been busy on other things. If you think that Alexpott's request for ensuring that lines we change here also meet all the other deprecation standards (even though we are ignoring those rules at the moment) then I can alter the automated fixing to try to cover those.
Comment #31
Gábor HojtsyYeah I think we should fix all of them on the same lines if at all possible without needing to generate / review each as its own issue. Thanks so much for working on this!
Comment #32
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedRe-roll of #19 as core 8.8 has moved on a bit. No changes to Coder rules yet, but this will get current baseline and generate new phpcs patch.
Comment #33
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commented898 coding standards errors reported in #32
Here is the patch that was generated.
Comment #34
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedI had forgotten that the patch file generated by the druapl.org testbot has, for example:
Whereas for it to be actually useful here, it needs to be:
Rustled up a quick php script to make the changes on the patch file.
Comment #35
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedOK, so it also need
/core
adding in.edit: Of the 898 existing errors, 376 remain after this patch, so that implies 522 get fixed, which is 58% of the total.
Comment #36
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedNew patch to generate a higher proportion of fixes
Comment #37
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedFix xml syntax (one ending / not needed)
Comment #38
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedSo eliminating the noise of the other sniffs (missing @see, missing extra-info, wrong url format, which we can tackle subsequently) we have a clearer picture of the basic text to fix: There are 667 'IncorrectLayout' faults from #37, and the results of patch #38 will show the results of the auto-fixing work so far, and indicate what other types of auto-fixing might be possible.
Comment #39
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedMore work done to automatic fixing. This will use a newer patch #8 of coder to generate the fixes patch.
Comment #40
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedNow run the generated patch.
Comment #41
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedFrom #39 we see that there are 668 coding standards messages for Drupal.Commenting.Deprecated.IncorrectTextLayout, and a patch was generated to fix as many as possible.
In #40 this generated patch was run and there are only 58 coding standards messages, so the auto-fixing sorted out 610 of 668 which is 91%.
I'd like to request that this patch is reviewed and if OK then committed, as I do not think the remaining 58 can be fixed automatically. There are many which do not have a deprecation version. Lots can be fixed manually, which I will do after the main patch is committed.
I could then move on to looking at automatically fixing the warnings, but I want to leave that until the majority of the errors (the 610) have been committed.
@gabor, @alexpott, @klausi - what is the next step to getting the changes in #40 reviewed? I know that the actual full patch #40 shoud not be committed because it adds the new sniff. But the standards changes it includes are all ready for review and commit.
Jonathan
Comment #42
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHere is the actual patch to commit, i.e without the changes to drupalci.yml and phpcs.xml.dist. This will run the full phpcs (without the new sniffs) so should be clean.
The patch in #40 did not apply due to recent commits on #3069049: Properly deprecate View::fixTableNames and #3052233: Properly deprecate EntityFormInterface::setEntityManager() and trigger an error on use so I have removed those hunks from the patch. I am wary that I'll always be having to re-roll or regenerate this patch as it touches so many files, and even a few days between creation and review will likely mean it no longer applies. But at least I have the process and it is easily repeatable.
Comment #43
LendudeChecked that #42 changes nothing except the @deprecated tags.
Lets get this in quick, or plan a date to land this, so the constant rerolling isn't needed.
Comment #44
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks @lendude. Yes, as this currently touches 315 core files it would be nice to get it in, particularly as #3038170: Drupal core's own deprecation testing results is happening. If this can't be committed quickly, that's OK but we need a planned date. Then I will regenerate the patch on that date.
Comment #45
xjmAgreed. Let's do this at the start of the beta, the week of Nov. 11. Thank you!
Comment #46
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedOK. But just to make you aware, the automated fixing of the 610 currently only addresses the first basic layout sniff
Drupal.Commenting.Deprecated.IncorrectTextLayout
When this is committed, there will be some manual work on the 58 which could not be automated, then we can start on the other sniffs in this standard, as these are being excluded in the patch:
Comment #48
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedUnpostponing now that 11 Nov is here. This is a re-roll of patch #39 which will show how many errors we have for the main layout standard, and will generate the patch to fix those that are fixable.
Comment #49
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedSo patch #48 found 675 @deprecated faults on basic layout, slightly up on the 668 from 10th September.
Here is the generated patch + drupalci changes in #48. This won't fix all of the the 675 but should do a large proportion of them.
Comment #50
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedPatch #49 shows we have 58 faults which are not auto-fixed (looks like the same 58 we had in #40 back in September)
The patch alters 319 files and makes 617 corrections, so that is 91% auto-fixable. Nice that 617 + 58 = 675 which was the number of faults found in #48
This patch #50 is the actual one that can be committed (it does not include the changes to drupalci and phpcs.xml.dist) and hence will run the full test suite, not the shortcut.
Comment #51
LendudeScanned the diff again, and still looks great.
This should not go into D9 since all of this should be removed by then. As far as I can find only
\Drupal\FunctionalTests\AssertLegacyTrait
is scheduled for removal in D10 at the moment, so no part of this patch is relevant for D9 (since this patch doesn't touch that).Comment #52
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks @Lendude. I have just belatedly spotted how I can auto-fix another 36 of those 58 remaining failures, which will reduce the manual work even more. I can get a revised patch here today, if that is OK with you? Or do you want to go ahead now that you have marked this RTBC?
Comment #53
LendudeLet's get them in too! Less manual work === good
Comment #54
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedOK, this is a re-run of #48/#49/#50
Step 1 of 3 - patch #54 will check the single standard and generate the phpcs patch to fix them. This uses a new patch on the Coder issue #3057988-10: Automatically fixing @deprecated doc text
Comment #55
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedPatch #54 reported 837 coding standards messages. This time it has included the
Drupal.Commenting.Deprecated.MissingSeeTag
sniff even though drupalci.yml is excluding this. Nothing should have changed to cause this, but it does not really matter, it just confuses the totalsThe generated patch has the expected fixes, it now alters 348 files (up 29 from 319) and makes 653 corrections (up 36 from 617)
Here is step 2 of 3 - check the generated patch running only the new sniff.
Comment #56
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedFor some unknown reason the
Drupal.Commenting.Deprecated.MissingSeeTag
andDrupal.Commenting.Deprecated.VersionFormat
sniffs are being shown as having an extra 'Deprecated' word added e.g.Drupal.Commenting.Deprecated.DeprecatedMissingSeeTag
in the checkstyle.xml output in dispatcher. This should be changed by the latest Coder patch, and it worked fine yesterday in #48/#49 so I do not know why it is different today. Here's a repeat of patch #55 but with both versions of the sniff excluded. Now we should see a cleaner output (compared the the 220 messages shown in #55) of the remaining basic @deprecated standard violations that will need manual fixing.Comment #57
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThat's better. Only 22 @deprecated basic errors remaining with this patch. 675 existing in the code - 617 - 36 = 22 so that adds up.
Step 3 of 3 - the actual patch #57 for final review, which can be committed to core 8.9.
Comment #58
Lendude@jonathan1055 great work on this.
Here is the interdiff for 50-57, and that shows all the new changes are of the 8.?.? variety. Back to RTBC.
Comment #59
lauriiiShould we open a follow-up to do this in JavaScript as well?
Comment #60
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks @Lendude
Yes, those 36 extras did not have any deprecation version, so I catered for this in the corrected text by adding 8.?.?. I know these will need the actual version inserted when we come to working on the
Drupal.Commenting.Deprecated.VersionFormat
standard fix, but at least now the main text is correct and it only needs manual effort to find the version.Comment #62
alexpottCommitted and pushed 2a009c5edd to 9.0.x and 6b52bd3100 to 8.9.x and 9293166c27 to 8.8.x. Thanks!
Backported to 8.8.x as a docs only change.
Comment #65
Gábor HojtsyComment #66
Gábor HojtsyI quickly cross-checked that the 8.?.? format does not interfere with the version identification logic in deprecation_status or upgrade_status. Both identify versions from
(in|as of) [Dd]rupal[ :](8.\d)
which will not match 8.? (good, since in this case there is no version to match yet).Comment #67
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThis is not fixed yet. We have done part 1 of the issue summary, committing the large automated patch. Part 2 is to fix the remaining layout problems manually. There are only 22 of these (after the 653 have been fixed automatically) as listed in comment #56. Then the final part will be to enable the sniff to ensure we do not introduce new failures.
I will try to make a these corrections, and provide a patch here, but I expect there will be details that I do not know, and will require input/review from others.
Comment #68
alexpott@jonathan1055 - let's do the follow-up to manually fix the rest and enable the coding standard in another issue.
Comment #69
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedOK, I have created #3094454: Fix remaining @deprecated manually and enable the coding standard for the follow-up.
I noted that in #51 above @Lendude said that this should not go into core D9 but that the commit in #61 was at 9.0, then 8.9 and 8.8. I think this is fine, because with the standard fixed in 9.0 it means we can search and do analysis on the versions as part of the process of removing the code.
Comment #70
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedJust to let you know #3009848-5: Fully deprecate WorkflowDeleteAccessCheck is a blocker for fixing one final @deprecated tag.
Comment #72
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedSorry to post on a closed issue, I meant to do this a few days ago.
Fixing the final 22 @deprecated coding standards and then implementing the rule has stalled due to Core tests referencing one piece of deprecated code but the deprecation warning was not being flagged - see #3009848: Fully deprecate WorkflowDeleteAccessCheck
To get this moving again, all it needs is the message to be added to Tests/Listeners/DeprecationListenerTrait to show that we are aware of its usage. This will allow the @deprecated basic layout coding standard sniff to be added to Core. The full solution to deprecating WorkflowDeleteAccessCheck can then be worked on independently. Having the standard enforced in core will ensure that we wont get into this situation again, where deprecated code usage is being masked and we are unaware of its usage.
Please can anyone who is following this issue take a look at #3009848: Fully deprecate WorkflowDeleteAccessCheck, not for the final solution but my patches in #7 and #8 which will alllow us to progress. Thanks.
Comment #73
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedChanged parent.