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 @trigger_error() function calls to adhere to standards.
Ideally wait for #3041983: Fix unused imports and update Coder to 8.3.4 so that testing the new sniff will be simpler, but we can use the new coder code by patching it via drupalci - see comment #28. The patch in #28 can be used now to start fixing the standards.
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.Semantics.FunctionTriggerError"/>
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.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3048495
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3048495-d10.1-fix-function-trigger-error-standard
changes, plain diff MR !3930
- 3048495-fix-function-trigger-error-standard
changes, plain diff MR !1894
- 3048495-d11.x-fix-function-trigger-error-standard
changes, plain diff MR !4216
- 3048495-d10-fix-function-trigger-error-standard
changes, plain diff MR !2294
Comments
Comment #2
jonathan1055 commentedAdded parent issue and related issue.
Comment #3
naveenvalechaComment #4
naveenvalechaRetitling to better reflect the issue.
Updating issue summary.Attaching the file which only includes the coding standard rule change
Comment #5
jonathan1055 commentedThanks naveenvalecha.
Here's a patch which runs just the TriggerError sniff, and does not do any phpunit testing. "Build Sucessful" is what it will show when done.
Comment #6
jonathan1055 commented798 @trigger_error standards messages. Not too bad. 3mins run time.
Many of the messages contain text like "and will be removed in 9.0.0". As this is not part of the required standard for trigger_error, but is very useful info. I suggest that this is simply moved into the %extra-info% part of the message. Even though this is free text, it would be helpful to change "in" to "from" so that we start getting used to the standard which is used in @deprecated comment tags.
Comment #7
lendudeSome reporting weirdness, probably caused by sprintf() inside the trigger_error ?
FILE: /Applications/MAMP/htdocs/d8/drupal/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php
-----------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------------
77 | ERROR | The deprecation message ) does not match the standard format: %thing% is deprecated in %in-version%. %extra-info%. See %cr-link%
-----------------------------------------------------------------------------------------------------------------------------------------------
Might need a tweak in the regex? Didn't investigate too deeply
Comment #8
jonathan1055 commentedThanks for the feedback. I'll check
core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.phpand see what I can do.Comment #9
jonathan1055 commentedI have created #3049093: Cater for sprintf() inside @trigger_error call to fix this.
Comment #10
jonathan1055 commented@Lendude I've identified the problem and added a patch to fix it, plus test data coverage, on #3049093: Cater for sprintf() inside @trigger_error call
Comment #11
xjmHmmmm I was massively confused by #6 until I read through #2908391: Add a rule for expected format of @deprecated and @trigger_error() text again and saw that the IS of that issue is not accurate... or, at least, does not correspond to the coder rule that was committed. The rule that was committed is instead an implementation of an alternate proposal in #3024461-56: Adopt consistent deprecation format for core and contrib deprecation messages (that I actually think I disagree with).
Edit: Actually, looks like the IS is internally inconsistent, and that's caused the issue.
Comment #12
xjmSo under the proposal that the rule was implemented for, everything should become
instead of
Comment #13
xjm...OK so it looks like the trigger error format and deprecated docblock format don't match, which I think is totally wrong. Hrmmmmm....
Thanks @jonathan1055 for investigating this!
Comment #14
jonathan1055 commentedHi xjm,
I think you have answered your question in your comment in #13. The issue summaries of #2908391: Add a rule for expected format of @deprecated and @trigger_error() text and #3024461: Adopt consistent deprecation format for core and contrib deprecation messages do both match the new coder rules added. However, the agreed standard was that @trigger_error() would not force the second part of the text "and will be removed" whereas the docblock @deprecated tag does force this. I drew attention to this question in #71 before the consultation period started, but no further objections were raised.
No Core work has been committed to fix the messages, and I'd be quite happy to add that extra part into the sniff I wrote. But it would need full discussion on #3024461: Adopt consistent deprecation format for core and contrib deprecation messages before we did that.
Comment #15
lendudeFILE: core/modules/taxonomy/src/Entity/Term.php
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
276 | ERROR | The deprecation message '::bundle() instead to get the vocabulary ID.' does not match the standard format: %thing% is deprecated in %in-version%. %extra-info%. See %cr-link%
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Another one where at least the reporting is missing part of the actual trigger_error(). Again didn't dig too deep.
Comment #16
jonathan1055 commentedThanks for the alert. The fix for sprintf has been committed on #3049093-7: Cater for sprintf() inside @trigger_error call
Are you using the full release of coder, or can you try the -dev release which may have fixed this.
Comment #17
jonathan1055 commentedJust checked and the existing fix does not cater for this, so could you open a new issue on the coder queue please
https://www.drupal.org/project/issues/coder
Comment #18
lendude@jonathan1055 thanks for checking, opened #3050697: FunctionTriggerError does not extract the full error message when it contains concatenations
Comment #19
jonathan1055 commentedHere's a re-roll, due to a committed change in phpcs.xml.dist
This patch is not to be committed, it will just show the current state of core with regard to the new TriggerError sniff.
Comment #20
jonathan1055 commentedThere are now 826 warning messages for TriggerError 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 #21
jonathan1055 commentedIn preparation for resuming this issue, here is the same patch as #19 but with composer.json changed to load coder 8.x-3.x-dev not 8.3.2
Not sure if this will work, but it it needed for Klausi's suggested next steps in #2908391-53: Add a rule for expected format of @deprecated and @trigger_error() text
Comment #22
jonathan1055 commentedThat did not load the dev version, it just ran with 8.3.2. The patch to composer.json seemed to be applied ok but did not trigger a rebuild of the dependencies. Maybe the composer.lock file also needs to be updated? I don't have the means to do that currently.
Comment #23
jonathan1055 commentedAnother try
Comment #24
jonathan1055 commentedThe acual testbot build .yml file contained my change
but coder 8.3 - dev was still not loaded.
Comment #25
jonathan1055 commentedHere's an attempt to require the specific commit in Coder which has the latest changes. Not sure if this is going to work though ...
Comment #26
jonathan1055 commentedSo the patch to composer.json did not affect the build environment. We get
with no change to coder. Maybe within crupalci.yml I can apply a patch to coder 8.3.2 to get the latest changes.
Comment #27
jonathan1055 commentedBefore working on drupalci.yml I thought it may be that test dependencies are not recalculated if only /core/composer.json is changed, maybe it needs a change to the root level composer.json, Here's the patch in #25 with an additional (dummy) change to composer.json just to see what happens.
Comment #28
jonathan1055 commentedSo that made no difference. Now, try to patch coder in drupalci.yml
Comment #29
jonathan1055 commentedSuccess! This is now running the latest version of the trigger_error sniff, patched during the host_command section of the drupalci build. The results show 765 coding standards violations, compared to 855 with the old code.
Comment #30
jonathan1055 commentedCorrect issue summary copy/paste typo to reference
@trigger_errorfunction not@deprecateddoc tag.Comment #31
gábor hojtsyOk #3041983: Fix unused imports and update Coder to 8.3.4 just landed, so this can be updated to just enable the rule and see the fails.
Comment #32
gábor hojtsyThere is also a 103k patch on #3033332: [META] Fix language and consistency of deprecation messages and annotations that I created and may be possible to update to get a jumpstart on this issue :) I am not sure this is doable in one patch but if it is, then that should be closed as duplicate of this one.
Comment #33
jonathan1055 commentedOK here is an updated version of the #63 patch with the drupalci.yml coder patch removed. It should give the same results now that core uses coder 8.3.4
I will have a look at that other issue and see. Many of the fixes need "Drupal 8.4.0" changing to "drupal:8.4.0" etc, so a script could be developed for that kind of change.
I may even see if I can utilise the phpcs automatic fixing to assist in making some of the changes, not to add this into coder permenantly, but use it to generate patches which we then apply manually to kick-start the fixing process.
The results above show 767 @deprecated messages, up from 765 yesterday. The sooner we can get this into core the better.
Comment #34
gábor hojtsyOk then. Closing #3033332: [META] Fix language and consistency of deprecation messages and annotations in favor of this one. If the 103k patch is any use from there, please do use it :) If not, then such is life. Carrying over related issues and tags.
Comment #35
jonathan1055 commentedTaking Gábor's patch as a starter, modifying for the current standard and adding a few more fixed trigger_error messages, here's a first attempt at fixing some of the violations. This only checks the new trigger_error standard, and I know that the full tests will need to be run to ensure that the tests for expected deprecations also match the new messages. But that can be done when the main work is complete, as the full test run takes much longer than just running phpcs.
[edit]
This patch has reduced the errors by 52, from 767 to 715, a reduction of 7%. Lots more work needed.
Comment #36
gábor hojtsyYeah the reason I made #3033332: [META] Fix language and consistency of deprecation messages and annotations a meta originally was that the total patch for fixing this would be a megabyte possibly :D I don't think maintaining that patch is sensible. So we probably want to break this down to smaller tasks.
Then we should figure out how to define if a part succeeded. This 123k patch reducing fails by 52 is useful.
I would lean to this later method. That said, I was never involved with a coding style update in core of this magnitude. Its big, but its very useful also for building tooling around the resulting standard messages.
It makes automation of a report like http://hojtsy.hu/blog/2019-may-24/analysis-top-uses-deprecated-code-drup... a piece of cake :)
Comment #37
jonathan1055 commentedYes the patch will be huge, so I would also lean towards your option 2. Get some fixes committed, then it is easier to see the remaining ones.
We need to remember to run the legacy tests that check expected deprecation messages before any commit, to make sure that we have fixed both the source and the test at the same time. Maybe I can add that into the drupalci.yml change. Don't want to run the entire test suite as that uses unnecessary resource (and is slow)
I have had sucess on #3048498-17: [≈Nov. 11] Fix Drupal.Commenting.Deprecated coding standard where I have automated the fixing of common faults using the PHPCS fixable error functionality. 389 fixed out of 960 = 40.5% and I expect be able to use that functionality for the Trigger_error fixes too.
Comment #38
gábor hojtsy@jonathan1055: thanks, running test would be important yeah otherwise we risk breaking branch tests.
This patch also fixes a bunch of @deprecated, so if we are to split along those lines, we need to make sure the two messages end up being the same across different patches and then remove those from this patch.
Comment #39
gábor hojtsy@jonathan1055 can you help break out a portion to an issue, maybe our current portion and make sure the core test suite also runs on it, then I can review and RTBC :D Thanks!
Comment #40
jonathan1055 commentedOK yes I could do. However, I have done more work on #3048498-20: [≈Nov. 11] Fix Drupal.Commenting.Deprecated coding standard and that automated patch now fixes 55% of the problems (520 / 930). Would you like me to break out that issue so we can fix that 55% first? I will also work on developing automated fixes for this trigger_error issue, but I've not started it yet. We'd have a bigger win with that other issue. Happy either way, just wanted to point it out.
[edit - unintentional change of status, that seems to happen a lot on d.o. when an issue page is refreshed to view a new comment]
Comment #41
jonathan1055 commentedUnintentional change of status above, that seems to happen a lot on d.o. when an issue page is refreshed to view a new comment.
Putting back to Needs Work.
Comment #42
jonathan1055 commentedRe-ran patch #33 (the plain one with no code fixes) which now shows core is up to 793 trigger_error faults. I am going to work on automating the fixes for these.
Comment #44
gábor hojtsyNow that #3048498: [≈Nov. 11] Fix Drupal.Commenting.Deprecated coding standard is in, this could be fixed too :)
Comment #45
jonathan1055 commentedI am working on writing some automated fixes for @trigger_error like I did for @deprecated.
Changing parent issue to the general coding standards issue, as the original parent was a one-off, is closed, and is no longer the best parent.
Comment #46
jonathan1055 commentedPatch #46 will show all the @trigger_error coding standards messages.
Comment #47
jonathan1055 commentedIgnore #46, it produced no phpcs output due to
because I missed the trailing backslash in the tag.
Comment #48
jonathan1055 commentedRight, now have something to work with: 876 trigger_error messages, split as follows:
TextLayout - 640
See Url - 72
Deprecation-version - 90
Removal-version - 74
Comment #50
jonathan1055 commentedHere's a patch, same as #47, but for Core 9.1 and 9.0
There are some @trigger_error coding standards faults in D9 as we have not fixed any of these yet, in any core version.
Comment #51
andypostOnly 41 left and all of them are deprecated formatting
Comment #52
andypostchecking now
Comment #53
andypostFix wording and messages to have less remains
Comment #54
andypostOne more patch to make sure nothing broken (full CI tests run)
Comment #55
andypostAdded remaining 30 places to ignore (inline) and tuned messages for methods
Comment #56
jungleThanks @andypost!
Ends with a full stop?
Ends with a full stop? If you agree, to search "phpcs:ignore Drupal.Semantics.FunctionTriggerError" and replace with "phpcs:ignore Drupal.Semantics.FunctionTriggerError." would be quick probably.
Comment #57
jonathan1055 commentedWhy is this being ignored?
It should be fixed properly, and all it needs is a seperate sentence for the 'See %url%'
passes the standard.
Same goes for the other two messages in that file.
Comment #58
kishor_kolekar commentedWorking on it
Comment #59
jonathan1055 commentedThanks kishor_kolekar,
Just a reminder, please add back the temporary change to /core/drupalci.yml which you can find in patch #53. This will mean your tests run only the code validation section, much quicker and save d.o. resource. Then only when we agree that the changes are good, we can remove that temp change and run the full phpunit suite.
Comment #60
jonathan1055 commentedAlso, re @jungle in #56
Before you go too far adding the periods at the end, are we sure we actually want this? Core does not currently adhere to that rule anyway, and you can see in phpcs.xml.dist
<exclude name="Drupal.Commenting.InlineComment.InvalidEndChar"/>Does phpcs understand the sniff if it has a period at the end? Maybe try it with just one of the
// phpcs:ignorelines first, don't change them all until we agree. Thanks.Comment #61
kishor_kolekar commentedAddressed comment #56,#57,#59
Thanks, jonathan1055
please review the patch.
Comment #62
kishor_kolekar commentedupdated inter diff
Comment #63
kishor_kolekar commentedComment #64
jonathan1055 commentedYour change to core/drupalci.yml does not look right. Please see how it was done in patch #53
Comment #65
kishor_kolekar commentedplease review the patch.
Comment #66
jonathan1055 commentedI will when it applies OK ;-)
Comment #67
rajandro commentedChecking the failed issue for the current(latest) version.
Comment #68
rajandro commentedReroll the last patch (3048495-65.patch) to apply it with the current version.
Please find the attached patch for more details.
Thanks
Rajandro
Comment #69
cburschkaSet to NR to trigger the test.
Comment #70
jonathan1055 commentedNice work @Rajandro now we can see what work needs to be done.
Look back to my comment in #60 and compare patch #55 to #58. You will see my hunch was right that we should not add a period at the end of each of the // phpcs:ignore comments, as that means they are not picked up by phpcs and the line is not ignored. I did try to save @kishor_kolekar from doing this unnecessary work.
When that is done, you can address the three messages which should not be ignore, from #57
Comment #71
rajandro commentedThank you @jonathan1055 for such detailed input, I have update the patch, let's have a look on this and let me know if you find any discrepancies.
Thanks
Rajandro
Comment #72
rajandro commented@jonathan1055, Please review it once and let me know if I reset drupalci.yml for a complete CI process to test the patch.
Thanks
Rajandro
Comment #73
jonathan1055 commentedThanks @Rajandro this is much better. You have removed the period from the end of 30 'phpcs:ignore' tags, fixed a couple of spaces after // and moved one :ignore to the correct place in SkippedDeprecationTest.php. Good work.
However, there are a few things that still need to be done before you remove the drupalci.yml temporary change:
// phpcs:ignorelines in that file.core/tests/Drupal/Tests/Core/Theme/RegistryLegacyTest.phpandcore/tests/Drupal/KernelTests/Core/Theme/RegistryLegacyTest.phpthe @expectedDeprecation text has been changed (in some earlier patch above) from 'Unsilenced deprecation: Theme functions are deprecated in drupal:8.0.0' but the text is not changed anywhere else. The original message passes standards so there is no need for this change, and it is out of scope and should be removed.core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.phpthe @expectedDeprecation text is changed from "Passing a 'transactions' connection option to Drupal\Core\Database\Connection::__construct" but only adds '()'. This message did not fail standards before. However there is no actual @trigger_error for this message in any other D91 file. Has the actual deprecation already been removed? Either way, we do not need to make this change.Thanks for working on this.
Comment #74
rajandro commentedThank you jonathan1055 again for your guided response. I will work on this and update the patch soon.
Comment #75
rajandro commentedHi @jonathan1055,
I have addressed point 1, 2, 4 and 5 as per your comment #73. Point 3 is still pending, this needs some time to update. I am checking this however meantime if someone has already done this then he/she can take this up.
Please find the updated patch and interdiff with the last patch.
Thanks
Rajandro
Comment #76
rajandro commentedComment #77
jonathan1055 commentedThanks @rajandro. I've compared the patches and checked the interdiff, and #73 points 1, 2, 4 and 5 have all been addressed.
Regarding #73.3 I am now not sure about this. The version may not be specific as this is a generic function which looks like it is used for many deprecations. I have queued the patch for testing.
Comment #78
jonathan1055 commentedThat's good.
ViewsConfigUpdater.phpcore/lib/Drupal/Core/Theme/Registry.phpwhere the text has been changedThe message followed standards before, so we should not be changing it here. Sorry I did not spot that before.
Thanks.
Comment #79
munish.kumar commentedComment #80
munish.kumar commentedHi @jonathan1055
#78 feedback has been addressed, Please review the patch
Comment #81
rajandro commentedWorking on the error will apply the final patch
Comment #82
rajandro commentedComment #83
jonathan1055 commentedThanks munish.kumar.
@Rajandro you can't just add
// phpcs.ignoreto get round the problem. If you look closely it is because the standard requires "is" not "are". This is possibly a failing of the 'relaxed' standard, and that could be improved. However, for this issue maybe we should go back to the changed message that was in patch #75 (that is, forget my point #78.2 and put back the change as it was in patch #75)Comment #84
rajandro commentedYou are right @jonathan1055, It's my bad that I was thinking this is an addition as it was throwing in my local as well. When I deep dive after your comment I noticed this error. Let me work on it.
Comment #85
rajandro commentedPlease review the update patch, I have readded the changes for drupalci.yml to save the test time resources.
Thanks
Rajandro
Comment #86
rajandro commentedComment #87
jonathan1055 commentedThanks @Rajandro this looks good. Comparing #75 to #85 is as expected. All clean regarding coding standards now.
So now looking at the 156 test failures from #82
Most (if not all) must be to do with this change:
It would be worth trying to fix those in the next patch which runs the full test without the drupalci.yml changes. I have just searched for 2869168 in the entire 9.1.x code source and you'll find it mentioned in
core/modules/views/tests/src/Kernel/ViewsConfigUpdaterTest.phpand incore/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php. Same goes for 2857891. Those messages need to be altered to match the same changes as the new @trigger_error text.Interesting that this shows 156 places where core 9.1 is using the deprecated code but hiding the messages.
Comment #88
rajandro commentedLet me check those failed test cases now.
Comment #89
jonathan1055 commentedThanks. It should be easy, it is just a case of altering the expected deprecation text, as explained in #87
Comment #90
rajandro commentedI am updating the patch for test case fixing as per findings on #82 and addressing #87 and #89, It will cover the deprecation notice though some Failure cases are still there and I am still working on it.
Comment #91
jonathan1055 commentedThanks @rajandro. Yes you fixed the messages for 2857891 and 2869168 in
/DeprecationListenerTrait.phpand that has had a big improvement, 156 failures down to just 4. It looked like those two were going to cover the majority of the failures.Done a quick scan of the test failures.
You can search for those numbers to find the places in the codebase where the expected deprecation messages need to be altered to match the new text. Hope that helps to give you a starter for where to find the lines to change.
Comment #92
rajandro commentedHi @jonathan1055, I have done this fixing and updating the patch now. Though now checking your message with all details, thank you.
PS: In addition to your comment of #91, the period at the end of the line was throwing error on my local, I have updated it as well
Let's see how this patch works for this fixing.
Comment #93
rajandro commentedFixing those two errors. Let's check the updated patch.
Comment #94
rajandro commentedSeems everything looks fine now, moving this to NR
Comment #95
jonathan1055 commentedThanks @rajandro, this is good. I presume the interdiff is just named wrong, I've compared and I think it is from 85 to 93 (not 92)
The only thing I want to check is
I don't know exactly how the DeprecationListener works, but it would appear that the period after the two urls should be removed to match the actual message. But then, I don't know why the tests did not fail, unless of course those listeners are not actually checked for. The % is just a wild-card and I do not think that the period in
.%is part of the pattern matching. Needs someone with more knowledge of DeprecationListenerTrait to answer this.Comment #96
rajandro commentedSounds fine to me jonathan1055. Let's see if this needs any changes.
I am adding the interdiff of #85 to #93
Thanks
Rajandro
Comment #97
jonathan1055 commentedI re-tested patch #93 and it needs a re-roll
Comment #98
ravi.shankar commentedComment #99
jonathan1055 commentedHi ravi.shankar
When you do the re-roll, please can you also include add in the changes to drupalci.yml that are at the top of patch #85. This will mean we get quicker test results and do not waste resources on drupal.org testbot. Then only when the coding standards all pass, we can re-run without the drupalci.yml changes, to actually run the full test suite. Thanks.
Comment #100
ravi.shankar commentedHi jonathan1055
Here I have added the reroll of patch #94 and also included the changes of drupalci.yml file from patch #85 as you suggested in comment #99.
Comment #101
jonathan1055 commentedThanks for the re-roll, that's great. At least the patch applies now and with the drupalci changes we get quick coding standards output and do not waste resources.
However, you can see there are 12 trigger_error coding standards. These must be new faults in the core source code, added since patch #93 on 17 June. This shows the benefit of trying to get these coding standards fixed and then the Coder sniff enabled for Core. We now have to fix these 12 messages here, instead of on the various issues where they were introduced.
To test this sniff locally, you can run
Without any patch, we get
and with patch #100 we get
So at least we are fixing 39 messages. Just these 12 new ones to sort out. Who wants to take this on? Just assign yourself, so that we don't double up and duplicate effort.
Comment #102
ankithashettyMade the required changes mentioned by @jonathan1055 in #101 in the following patch. Kindly review. Attached an interdiff as well.
Thank you!
Comment #103
jonathan1055 commentedHi ankithashetty, thanks for the new patch, which fixes the 12 new warnings from #101. I have made some changes and decided to show them in three separate interdif files, to make it easier to see what has been done.
1. Your changes are all good apart from two, where you have added
// phpcs:ignore Drupal.Semantics.FunctionTriggerErrorwhen in fact the message can be corrected and we do not need to ignore it. I have made these corrections (in FormattableMarkup.php and TaxonomyIndexTid.php) and this is shown in 3048495-103.interdif-102-103-do-not-ignore.txt2. Since your patch on 9th September there are now four new coding standards warning (one can be fixed, the other three have to be ignored). I've done this - see 3048495-103.interdif-102-103-four-new-warnings-corrected.txt
3. I have also spotted some other minor things, grammar improvements, making messages consistent, etc, and these are shown in 3048495-103.interdif-102-103-grammar-fixes.txt
There are a couple of other points outstanding, but I want to test this patch first, so let's see how it runs on drupal.org.
Comment #104
jonathan1055 commentedThere's a lot going on at 9.1.x My branch was up-to-date as at 15 Oct 13:53, but the very next commit 15 Oct 14:00 (just 7 minutes later) was on #3172438: Since symfony/phpunit-bridge 5.1: Using "@expectedDeprecation" annotations in tests is deprecated, use the "ExpectDeprecationTrait::expectDeprecation()" method instead. which caused the re-roll work. Talk about close timing!
Comment #105
andypostSniffers returns 1 error but while patch changes mostly all constructors with this mamba
I think wording needs change to "is required in drupal:10.…"
+ @trigger_error('Calling ' . __METHOD__ . '() without the $file_system argument is deprecated in drupal:9.1.0 and will throw an error in drupal:10.0.0. See https://www.drupal.org/node/2630230',Comment #106
jonathan1055 commentedThanks for the review.
Yes, but confusingly that is nothing to do with this patch, and I have reported it on #3008028-112: Migrate D7 i18n menu links where the fault originated. This is odd, because the core/drupalci.yml file has
sniff-all-files: falseand that file was not touched in the patch, so should not have been checked.OK, I have changed that.
Also now that all texts pass the standards patch #106 will run the full set of tests, to check for any place where expected deprecations in tests are not matching the new messages.
Comment #109
jonathan1055 commentedPatch #109 fixes the message in the four failed tests from 106. Also I have removed two dynamic exception messages from DeprecationListenerTrait
isDeprecationSkipped()as these are tested explicitly. Those were added in 9.0 but they may not be needed to be ignored anymore in 9.1+Comment #111
jonathan1055 commentedOK those dynamic deprecations definitely do still need to be ignored, sorry for the noise. I have put them back in DeprecationListenerTrait.php
isDeprecationSkipped(). The pattern was causing confusion earlier (see #95) where the final dot looked like part of the deprecation message but was actually useless as it was a single match-anything character. So I have removed them, and also changes the delimiter to ~ which is very obviously not a wildcard or anything in these two deprecation messages.For info, to test these locally I used
--filter=PathPluginTestwhich is quick and contains both of the deprecations.Comment #112
jonathan1055 commentedComment #113
jonathan1055 commentedAll the tests pass, but we now have four new @trigger_error deprecation messages to fix, all in a recent commit in #3174662-89: Encapsulate \PDOStatement instead of extending from it. It shows the benefit of getting this patch committed.
Note that I fixed two of the warning messages by changing the string variable interpolation into using sprintf(). There is an open issue in Coder to allow variable interpolation within the trigger_error text - #3178199: Cater for variable interpolation strings in @trigger_error sniff
Comment #115
jonathan1055 commentedI missed altering two expected deprecations in the tests.
Comment #116
jonathan1055 commentedAll @trigger_error messages adhere to coding standards and all tests pass, so I consider this ready for review by someone else now.
The one coding standard messsage is unrelated and I've reported it on #3178338: Fix coding standard fail committed to core 9.1 and 9.2
Comment #117
longwaveThanks for fixing this up, this is a great help to standardise these messages.
Should we just use
phpcs:disableto ignore this sniff across this entire file?The string interpolation is a bit weird here, why not just say
sprintf('StatementWrapper:$%s...', $name)?bindColumnandbindParamare methods and so should both end in(), as we are touching these lines let's fix this here too.Not sure this is quite correct, it's the declaration of theme functions that is the trigger here. Does "Declaring theme functions..." sound better?
Comment #118
jonathan1055 commentedThanks @longwave, great review.
Yes definitely. I had not noticed that the single ignore had been added 8 times and that there are no other deprecations that should be checked. Fixed
I agree. I think it ended up that way because initially I just took what was inside the main string in double quotes. Fixed.
Agreed. Done. For accuracy and completeness I have also added
()to the deprecation message infunction __call($method, $arguments)because that $method argument will only be the plain stringYes it does. Fixed.
I've made these required changes to the expected deprecation tests, but only run those specific tests locally (and they pass). Running the full core test suite locally takes too much time and resource, but hopefully all should pass on d.o.
Comment #119
longwaveGood spot on the
__call()for #118.3.This looks great now, RTBC from me.
Comment #120
alexpottWhy the change to ~ as opposed to %? Looks unnecessary. I don't agree with justification in #111. Yes the . was confusing but actually that's the same ALL the dots in these dynamic deprecation messages. The other dynamic messages have dots properly escaped. Imo using % is fine and inline with the other dynamic messages... but we should escape all the other dots here.
Capital T should lowercased.
Comment #121
ayushmishra206 commentedMade the changes requested in #120
Comment #122
alexpottThe final character here should be a % too. Plus all the dots should be escaped. See the other dynamic messages skipped above in the code.
Comment #123
kishor_kolekar commentedworked on comment #122
Comment #124
jonathan1055 commentedIn addition to escaping the dots, there should be no final dot for these two messages.
That was the source of confusion in #95 and #111 above. The deprecation standard requires no dot at the end of the url (so that the actual usable url could be parsed out if required). The message now has no trailing dot (see core/modules/views/src/ViewsConfigUpdater.php) but the deprecation tests were not failing even when the expected message had a trailing dot. Then I realised that this ending dot simply matches any character as in standard regex syntax.
Comment #125
Pooja Ganjage commentedHi,
Creating a patch as per the #124 comment.
Please review the patch.
Thanks.
Comment #126
Pooja Ganjage commentedComment #127
jonathan1055 commentedFrom #122
Please can you escape the dots as per Alexpott's request in #122 and mentioned again in #124
Comment #128
Pooja Ganjage commentedHi,
Creating a patch as per the #127 comment.
Please review the patch.
Thanks.
Comment #129
alexpottThe dots in these strings are still not escaped. Escaped in this instance means
drupal:10.0.0.becomesdrupal:10\.0\.0\.Also can an interdiff from #123 to the next patch be created so we can see what's changed. This is a large patch.
Comment #130
Pooja Ganjage commentedComment #131
Pooja Ganjage commentedinterdiff provided for above patch.
Comment #132
jonathan1055 commentedHi Pooja,
In #125 the test failed because you have lost one of the changes in core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
In #128 the additional four test failures was because you removed dots from the messages unnecessarily, and then these did not match with the expected deprecation messages in the tests.
In #130
The dots in the actual @trigger_error calls should not be escaped. You only need to escape the two dynamic text messages as explained in #120, #124 and #127. You have done it for every @trigger_error call. Also the patch does not apply, but I've not investigated exactly what is wrong.
Are you happy to continue with this task? That's fine if you do want to, but it is taking a lot of your time, and if you'd prefer me to help get it back to a working patch with all tests passing, just let me know. Or if you want to ask questions, please do, instead of just posting another patch which is not going to work. Happy to help you get this sorted :-)
Jonathan
Comment #133
msutharsComment #134
Pooja Ganjage commentedUpdated patch.
Comment #135
Pooja Ganjage commentedComment #136
msutharsComment #137
jonathan1055 commentedThank you Pooja and msuthars. This looks nearly right, although the interdiff was no help, as I could not see from which point it was diff'd from. I was expecting only a small set of changes. I manually compared the patches and I think you have fixed the problems introduced since #125.
However, as alexpott said in #122 and I repeated in #124:
You need to escape all the dots, so it should be:
For the next patch, please could you create your interdiff against #123, as requested by alexpott, as that was the last full-reviewed patch. If you have difficulty in making interdiffs, please let me know and I can help, but I don't want to take the work from you if you are doing it.
Comment #138
msuthars@jonathan1055 I made changes in the patch as mentioned in #129 by @alexpott.
Comment #139
alexpott#138 looks correct and I've run phpcs locally and it reports no warnings or errors.
Comment #140
jonathan1055 commentedYes, the patch #138 looks good. I'm happy for this to be RTBC based on @longwave's RTBC from #119 everything has been addressed that was raised since then.
The interdiff was slightly odd with that single deletion and addition in core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php. I checked the actual patch and there is only one change, and that matches what we had before, so I think it was just a bug in how the interdiff was created, because that code block is repeated incorrectly in the interdiff.
Comment #141
Pooja Ganjage commentedHi,
@jonathan, I have provided interdiff for the #138 comment as showing only one change into the interdiff file.
Please review the interdiff.
Thanks.
Comment #142
longwaveI have reviewed all the changes since #118 and all looks good to me, so this is RTBC.
Comment #143
catchThe number of phpcs:ignore lines in this patch, in our own home-grown code as opposed to forked stuff, makes me think we shouldn't add this rule at all. Or if we do, find some way to make it target only @trigger_error() calls with the word 'deprecated' in. This isn't really enforcing code style as it currently is.
Comment #144
alexpottOne potential improvement would be to update the rule to only check strings... so if it detects a variable then admit defeat and move on.
Comment #145
andypostI think if it detects variable in trigger error, it should complain as well but with different message because otherwise we'll never start catch proper messages for it
Comment #146
jonathan1055 commentedJust to get some perspective on this, using a quick search in /core there are 227 calls to @trigger_error.*E_USER_DEPRECATED over 84 files. This patch fixes 26 of those and ignores another 26 (over 19 files). That means the standard is already being followed for 77% of the calls and we can increse this to 88% with the patch, and only have to ignore 12%
The individual ignored lines are probably ignored for a variety of different reasons. Some may be able to be changed to follow the standards - the 'ignore' lines were added possibly casually by a variety of developers contributing to the above patches, where the easy fix was not possible. Some of these might be able to be fixed.
IIRC, one of the main points of this rule, when Gabor encourged its introduction, was to make it easy to exract deprecation data for analysis of versions, etc. In those 88% of calls this will be useful and can be done. In the remaining 12% there woud not be any info to gain anyway, because the drupal version is not included.
Should we start to look in detail at those 19 files which have the ignore, to see what can be done to improve the 88% level?
Comment #147
longwaveSymfony has added a new single-function package to generate deprecation messages in a standard format: https://github.com/symfony/deprecation-contracts/blob/main/function.php
Maybe we should consider adopting this or something similar?
Comment #150
quietone commentedI've closed #3191426: Change 'will be' to 'is' in deprecation error message as a duplicate. Adding credit here for adityasingh
Comment #151
longwaveI think the idea in #144 will let us fix most of the ignored cases here. While @andypost has a point in #145 we hopefully will catch most cases of variables being used where they could be fixed strings in code review. The case pointed out in #143 probably should be switched to use fixed strings.
I opened #3226902: @trigger_error deprecation sniff is too strict - allow the message to start with a variable to explore this change.
Comment #153
jonathan1055 commentedThe last patch was at 9.2 and the issue is now at 9.4. Also #3226902: @trigger_error deprecation sniff is too strict - allow the message to start with a variable is fixed, so here is a plan:
Comment #155
jonathan1055 commented:-( There are 39 new deprecation failures since the last patch. This is getting tedious to stay on top of.
#153 steps 1,2 and 3 done. Added step 4 to correct new deprecation messages.
Comment #156
jonathan1055 commentedThe current 9.4.x branch has
With the commit as at patch #138 (which was clean) we get
I have now fixed the 39 new failures.
Comment #157
jonathan1055 commentedThis commit fixes the messages I missed earlier. For some as-yet unknown reason running phpcs on my local machine ignores the
file.modulefile completely and does not attempt to check it. Renaming tofile.module.incdetected the problems, so could fix them. Then I renamed the file back tofile.module. That needs investigation, but its a distraction for now.Comment #158
jonathan1055 commentedOK. That's clean, so #153 step 4 is done. Now remove some of the
phpcs:ignore Drupal.Semantics.FunctionTriggerErrorlines where the message is just a variable. This will show some failures because we are still using Coder 8.3.14 which does not have the that latest fix yet.Comment #159
jonathan1055 commented#153 step 5 is done.
As expected we get failures where the message is a variable. Now to atempt to run with the latest Coder 8.3.x dev
Comment #160
berdirIs it really worth doing that for D9? Wouldn't it be a lot easier to enforce the rule for new deprecations in D10 and onward? It would have to land there first anyway, no?
Comment #161
yogeshmpawarComment #162
longwaveAgree with @Berdir that we have to do this in 10.0.x first, and the patch there will be mostly completely different - we could decide after that whether it is worth pulling this back to 9.4.x as well.
Comment #163
spokje#3262874: Update Coder to 8.3.15 landed, which means Core now comes with
drupal/coder8.3.15 which includes the fix in sniffDrupal.Semantics.FunctionTriggerError#3226902: @trigger_error deprecation sniff is too strict - allow the message to start with a variableComment #164
bbrala#3024461: Adopt consistent deprecation format for core and contrib deprecation messages also landed which makes it official i guess? :)
Comment #165
spokjeComment #167
spokjeNew MR for
10.0.x-devbased on MR!1894, with significant less changes (since significant less deprecations left in D10) and nodrupal/coder:devtrickery needed any more.Comment #168
bbralaWent through the changes. I understand why we need to ignore a set of errors in the tests. It might be an option to change them to fit the sniff, but I understand the reasoning to keep them as is.
Changes look good, tests are green. Changing to rtbc :)
Comment #169
daffie commentedFor the 2 nitpicks.
Comment #170
bbralaHmm, think you are right, nice catch.
Comment #171
longwaveWe relaxed the sniff a bit over in https://github.com/pfrenssen/coder/pull/154/files so I think/hope some of the skips can be removed.
Comment #172
spokjeThanks @daffie and @longwave.
I've now used
Drupal.Semantics.FunctionTriggerErrorsuppression only where it is needed now.Looking into specific cases as we speak (or rather: as you read).
Any thoughts on if and how we should backport this into the land of
9.x.x-dev?- Only backport the changed deprecation errors and _not_ the PHPCS sniff?
- Add PHPCS sniff and change all deprecation errors?
- Something completely different?
Comment #173
longwaveI would go for either "add the sniff and change all errors" or "do nothing in 9.x, make this 10.x only" - core committers tend not to like doing only part of the work and leaving it open for things to be undone later, which could happen in the first option.
Comment #174
jonathan1055 commentedI would definitely recommend backporting to 9.x otherwise things like #3033165: Parse more information out of deprecation messages will have less value.
Comment #176
quietone commentedOnce again I can't push after rebasing. I am uploading a patch.
Comment #177
spokjeWhen that happens to me, I always have success withgit push --set-upstream drupal-3048495 HEAD -fSo basically the command from "Or push your current local branch from your Git clone" followed by a -f (for force, use it Luke...)
Probably to late for this occasion, but you might wanna give it a go next time.Nvm, changing branches is another matter.
Comment #179
smustgrave commentedWasn't terrible to review as most of the files were 1 line.
Changes look good and like that it will capture good trigger_error messages.
I haven't seen it before for other coding standard tickets but would a change record be worth it?
Comment #182
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #184
quietone commentedI am assigning to myself because I have local changes that I am not able to push. I'll un-assign once that is fixed.
In the meantime there are two new errors that need a link to the CR. The issue, #2551419: Abstract RenderCache into a separate service that is capable of cache redirects in a non-render array-specific way has two CR's but neither of them directly address the removal of the constructor parameter. I'm not sure if one of the CR's should change or a new one is needed. Suggestions?
Here are the errors,
Comment #185
quietone commentedTests are passing so time for reviews.
Comment #186
spokjeI'm afraid the commit of #3375454: Fix version number in deprecation messages for #2551419, ironically an issue by @quietone, now clashes with this MR and it needs Yet Another Rebase (Yar!....)
Comment #187
quietone commentedRebased the MR
Comment #188
smustgrave commentedAll green with the new rule added. So assuming this is good.
Comment #189
longwaveAdded some feedback.
Comment #190
quietone commentedTests are passing, back to NR.
Comment #191
quietone commentedComment #192
smustgrave commentedThreads appear to be addressed.
Comment #193
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #194
spokjeRebased MR, back to RTBC
Comment #196
lauriiiLooks like new non-compliant deprecation messages sneaked in 😅
Comment #197
spokjeSince I was responsible for the faulty new ones, it seems fitting to fix those myself.
Think this can go back to RTBC, since the changes are checked by the new PHPCS rule?
Comment #198
quietone commentedYes, that make sense. And I read the last 3 commits to confirm. This is still RTBC.
Comment #199
quietone commentedThis needed a rebase. Because there were a lot of conflicts, I am setting back to Needs Review.
Comment #200
smustgrave commentedReading the commits after 198 and changes still look good.
Comment #201
alexpottCommitted fd2c134 and pushed to 11.x. Thanks!
I'm not sure we need to enable the new coding standard in 10.1.x but we might choose to backport the fixed strings for consistency. Not sure.
Comment #203
jonathan1055 commentedGreat to see this committed. Thank you everyone who contributed.
As someone who worked on the original coding standard, the Coder sniff and the early patches on this issue, I would recommend back-porting the strings and enabling the rule in 10.1. One of the original purposes of the standard was to be able to scan source code and get metrics on how many things are deprecated and how many cause triggerError in a particular version of core. That would help with 10 -> 11 upgrades.
Comment #204
alexpott@jonathan1055 10.2.x will be cut from the 11.x branch (which really should be named "main" but we can't do that cause reasons).
Comment #205
longwaveI think we should backport the message changes - usually we do not backport string changes due to translations but these messages do not get translated, and it will make other backports easier.
We don't usually enable new coding standards in patch releases and I see no need to do so here, given any new deprecations will only appear in 11.x.
Comment #206
jonathan1055 commentedOK, thanks for explaining that. Yes, therefore fix the strings in 10.1 but no need to implement the Coder rule.
Comment #207
jonathan1055 commentedThe commit in #201/202 did not make any changes to phpcs.xml.dist. Earlier patches and MRs contained
but this is not present in the commit. So the new Coder rule has not yet been implemented in Core 11.x
What was the source of the commit in #201? Was it MR4216? That had 56 changed files but the commit seems to have only 20.
Comment #208
jonathan1055 commentedActually the rule is enabled in core
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/phpcs.xml.dis...
It's just that it was not in the commit shown in #201. Sorry for the noise.
Comment #209
longwave@jonathan1055 GitLab only shows 20 files changed per page, if you go to page 3 then you can see the changes to phpcs.xml.dist: https://git.drupalcode.org/project/drupal/-/commit/fd2c13413a20941c10dd0...
Comment #210
jonathan1055 commented@longwave Thank you. I should have spotted that.
Comment #211
longwaveCoding standards changes go in the release notes.
Comment #212
longwaveProbably too late to consider backporting this now, let's just mark this as fixed in 10.2.0.