-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Feature: handle deprecation of sniffs natively #164
Comments
I prefer standalone interface with just one method. |
I think it's also better to have a single interface. When a sniff is deprecated you can just implement multiple interfaces (which to me sounds like a better OOP practice anyhow - composition over inheritance). That way it's not directly coupled to the And some standardization in the message output would be beneficial IMO, as that would bring more consistency across the standards. Imagine using 3-4 different standards, each having different depreciation messages, I think that would increase the cognitive load on the end user. With a standardized depreciation message, users know what to expect, no matter which standard (bundled with PHPCS or not) they are using. |
Notes to self - additional ideas to make this feature complete:
|
I tend to agree with @dingo-d about the standardization of the messages, so my preliminary implementation is a stand-alone interface with three methods. Here's screenshot of what the output could look like (work in progress, feedback welcome): |
Q: Is there any way to show the deprecation details in the "explain" report? Other than that, it looks nice to me! |
@stronk7 That would be possible, but would make it quite noisy IMO. In that case, it would probably be better to show the whole deprecations block for the I mean, the details as per the above screenshot would now show on every normal run (except when running with |
PR #281 is now open for this feature. Reviewing and testing would be appreciated. |
Of the above, the first has been included in PR #281. The second has not as it would involve more extensive changes. This could potentially still be added at a later date. |
Unless anyone leaves a comment/feedback on the PR, I will merge it tomorrow. |
Is your feature request related to a problem?
There are times when a sniff gets superseded by another sniff or just isn't relevant anymore and needs to be deprecated.
In PHPCS itself, this was most recently done in PHPCS 3.3.0 for the
Squiz.WhiteSpace.LanguageConstructSpacing
sniff and in PHPCS 3.4.0 for theGeneric.Formatting.NoSpaceAfterCast
sniff.It can also be said that the MySource standard + all CSS/JS sniffs are effectively deprecated as they will be removed in PHPCS 4.0.
However, deprecating sniffs is not something which is unique to PHPCS itself. External standards will also, at times, want to deprecate sniffs.
Current options for deprecating a sniff
At this moment, when deprecating a sniff, there are effectively two options:
This will largely go unnoticed and end-users will be confronted with the removal in the next major.
This potentially breaks builds when CI is set to fail on warnings, which makes the impact of a deprecation too large for it to still be called a deprecation.
All in all, neither option is very satisfactory.
Describe the solution you'd like
Now to solve this conundrum, I'm thinking of introducing a new
DeprecatedSniff
interface which extends the existingSniff
interface and adds one additional methodgetDeprecationMessage()
.When a sniff gets deprecated, the
implements Sniff
would then be swopped out for animplements DeprecatedSniff
and thegetDeprecationMessage()
method would need to be added.In the PHPCS framework, when the ruleset gets loaded, it could then be detected if a sniff is deprecated and all sniff deprecation messages could be collected and displayed above the report output. Similar to messages about the ruleset containing a reference to a non-existent sniff or to a property which doesn't exist.
These deprecation messages would not influence the exit code of a PHPCS run and would therefore be non-breaking.
When the
-q
(quiet) option is used, these messages would also be silenced.Opinions ?
Open questions:
DeprecateSniff
interfaceextend Sniff
or should it be a stand-alone interface ?A stand-alone interface would possibly allow it to be used more easily in combination with arbitrary abstract sniff classes.
getDeprecationMessage()
method which allows for an arbitrary message or should the message be standardized more ?If the message should be more standardized, this could be done by having multiple methods:
getDeprecationVersion()
,getRemovalVersion()
,getReplacement()
; or by agetDeprecationInfo()
method which would expect an array with this info in three predefined keys./cc @kukulich @wimg @GaryJones @dingo-d @fredden @michalbundyra @stronk7
Additional Context
In a future iteration, I can imagine another interface which would allow for PHPCS natively handling the deprecation of one or more public properties in a sniff.
The text was updated successfully, but these errors were encountered: