Feature request: sniff to check that deprecation is properly handled
In https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/979#issuecomment-310235942 :
Just thinking.... maybe we should create a sniff that checks for calls to any of the deprecated....() functions and ensures that there is a @deprecated tag and visa versa ?
Some ideas for what the sniff should check:
- That a
_deprecated_...()function is called whenever a@deprecatedtag is encountered. - That a
@deprecatedtag is used whenever a_deprecated_...()function is called. - That the correct flavour of
_deprecated_...()function is called. - That the version nrs in the tag and the function parameter are in line.
- That the alternative listed in the tag and the function parameter are in line.
- That
__METHOD__is used for methods,__FUNCTION__for functions.
I propose the sniff be added to core based on all the issues related to this we've identified in PR #979.
Related #663
I've been working on this and got quite a lot ready already, but would like to wait to pull this until WPCS 3.0.0 for two reasons:
- The sniffs could benefit from the PHPCSUtils utility functions and the associated code re-organisation within WPCS once PHPCSUtils gets implemented.
- I've been testing the sniffs on WP Core and have found quite a lot of inconsistencies in Core. I'll be opening issues with patches to get all of that fixed and pulling the sniffs a little later will allow for those patches to be committed before that time.
Status overview:
- [x] FileDeprecation sniff
- [x] HookDeprecation sniff
- [x] PHP4Constructors Deprecation sniff
- [ ] FunctionDeprecation sniff
- [ ] FunctionArgumentDeprecation sniff
- [x] VersionNrs sniff for
_doing_it_wrong()as per #663 (the version nr checks for the_deprecated_...()functions will be contained within the above mentioned sniffs.
Related WP Core tickets:
- https://core.trac.wordpress.org/ticket/41121 (deprecated functions)
- https://core.trac.wordpress.org/ticket/48252 (deprecated constructors)
- https://core.trac.wordpress.org/ticket/48254 (deprecated files)
- https://core.trac.wordpress.org/ticket/48255 (deprecated hooks)
Also related:
- https://core.trac.wordpress.org/ticket/48251