WordPress / plugin-check

A repository for the new Plugin Check plugin from the WordPress Performance and Plugins Team.
https://wordpress.org/plugins/plugin-check/
GNU General Public License v2.0
212 stars 39 forks source link

Implement reusable `PHPCodeSniffer_Sniff_Check` class to replace individual check classes per sniff #204

Open felixarntz opened 1 year ago

felixarntz commented 1 year ago

Is your enhancement related to a problem? Please describe.

The following checks currently rely on an extremely similar class implementation:

Implementing a new class for every single sniff check is unnecessarily tedious, and it will just get worse in the future as we add more PHPCS sniff-based checks.

Therefore, we should introduce a single class for that purpose, which can simply be passed the sniff to use in a constructor parameter.

Designs

Describe alternatives you've considered

No response

Code of Conduct

jjgrainger commented 1 year ago

Thanks @felixarntz the AC's look good to me.

I think we might want to consider how additional attributes are added for these checks. I've noted in #203 that the PHPCodeSniffer_Sniff_Check constructor would need to accept a category parameter, but what about any other attributes such as stability flags (#92)?

Although this approach will reduce repeated code it does bring some restrictions. However, we could take this approach for now and adjust as we need.

felixarntz commented 1 year ago

I left a reply to your other comment, for the class here we could use traits probably for both the category and stability.

For stability, we could even consider to always make these PHPCS checks stable for now, since they would always use logic that is already established (e.g. through WPCS) anyway.