WordPress / wporg-code-analysis

An experiment.
62 stars 8 forks source link

Contribute sniffs upstream #34

Open iandunn opened 3 years ago

iandunn commented 3 years ago

Once the custom sniffs are mature, it might be a good idea to contribute them to the WordPress Coding Standards and WPThemeReview projects. They have broad application, and could be useful to many.

cc @jrfnl

jrfnl commented 3 years ago

@iandunn I've had a quick look through the repo. Here's some feedback to consider (or disregard, whatever takes your fancy):

iandunn commented 3 years ago

Thanks for the review and tips!

tellyworth commented 3 years ago
  • I see a custom way of testing sniffs, while PHPCS has a build-in abstract test class available which simplifies the testing immensely.

Where is the abstract test class documented? I was unable to work out how to use it, so I followed this example: https://payton.codes/2017/12/15/creating-sniffs-for-a-phpcs-standard/#writing-tests

(Also: please don't ever use assertEquals() in tests unless you're testing objects).

What should I use instead?

tellyworth commented 3 years ago

For sniffs which are widely applicable, why not contribute them straight away to WPCS

This is an experimental repo. It's fast moving and unstable, and as you've noted has plenty of problems that we have yet to solve. Once we've figured out what's possible and what's useful we definitely will contribute it to WPCS and elsewhere as applicable.

Thanks for the notes!

jrfnl commented 3 years ago

Where is the abstract test class documented? I was unable to work out how to use it.

See: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/tests/Standards/AbstractSniffUnitTest.php or just look at how WPCS tests sniffs.

If you can't get this working it may be due to the fact that the whole setup is broken as it doesn't comply with the PHPCS naming conventions and therefore will not work properly as a stand-alone standard.

You may want to have a read through the sniff writing tutorial to get a better understanding of the basics: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Coding-Standard-Tutorial

What should I use instead?

assertSame()