-
-
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: only load sniffs containing fixers when PHPCBF is run #165
Comments
I like the idea 👍 I would like more version that However I understand that you want to be backward compatible... |
I don't mind preserving the So then we'd end up with |
Hi, just thinking how the interfaces stuff will work when Sniffs aren't implementing Take for example A possible alternative, just came to my brain because I've been working today with something similar, used to declare some stuff as "deprecated" within an app, could be to have some simple Trait, say For some reason, I find the trait alternative natural enough... and that won't require us to go splitting / changing all the extensions tree. Just shared, without too much reflexion, heh, so take it with a pinch of salt. Ciao :-) |
OT, hah, curious... I've just seen #164... about Sniff deprecations. Another example where Traits could came to rescue. |
@stronk7 Thanks for your input.
A class can So to take your example, to mark a sniff as containing a fixer, the class signature would become: class CamelCapsFunctionNameSniff extends AbstractScopeSniff implements FixableSniff {}
// We could even combine it with the interface proposed in #164:
class CamelCapsFunctionNameSniff extends AbstractScopeSniff implements NonFixableSniff, DeprecatedSniff {} The interfaces can be detected easily via an So yes, interfaces would work perfectly fine for this.
Traits would need some content for PHPCS to be able to detect their use, while there is no content PHPCS could/should provide by default for this functionality. While I have nothing against traits, in my opinion, they are not the right tool for the job in this case. |
Last question… and which interface will abstract sniffs implement? I mean, after all, we will need the 3 (Sniff, fixable and non-fixable) to stay forever… |
In most cases, in my thinking, that would be Having said that, I can imagine there may be a rare situation where the abstract would implement
You are probably right about that. |
Is your feature request related to a problem?
Some standards, like, for instance, PHPCompatibility contain a lot of sniff (150+), but barely any fixers. Another example is the VariableAnalysis standard, which only contains one non-fixable sniff, but has to do a lot of work for that one sniff, which makes it a slow sniff.
As things are, when running
phpcbf
all sniffs are loaded, whether they contain fixers or not. This also means that all sniffs are run in all fixer loops as PHPCS will only know about fixable errors/warnings once the sniff triggers an error/warning.All in all, this can make PHPCBF much slower than is needed when a ruleset contains a lot of non-fixable sniffs.
Describe the solution you'd like
A preliminary idea is to have a
FixableSniff
and aNonFixableSniff
interface.When running
phpcbf
PHPCS could then decide when reading the ruleset and loading the sniffs whether sniffs should actually be run, which could lead to a significant performance boost in cases when the ruleset contains quite some sniffs not containing fixers.Opinions ? Other ideas to tackle this ?
/cc @kukulich @wimg @GaryJones @dingo-d @fredden @michalbundyra @stronk7
Additional context (optional)
If there is interest in this idea, I'd be looking to introduce this feature in the 4.0 release.
The
Sniff
interface would then be (soft) deprecated in 4.0, to be removed in 5.0, which should give standard maintainers time to switch over to the new interfaces.If when running on 4.x, the
Sniff
interface is still used, it would be treated as if it were theFixableSniff
interface and the sniff would still run inphpcbf
mode.The text was updated successfully, but these errors were encountered: