Skip to content
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

Contribute sniffs upstream #34

Open
iandunn opened this issue Apr 6, 2021 · 5 comments
Open

Contribute sniffs upstream #34

iandunn opened this issue Apr 6, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@iandunn
Copy link
Member

iandunn commented Apr 6, 2021

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

@iandunn iandunn added the enhancement New feature or request label Apr 6, 2021
@jrfnl
Copy link
Member

jrfnl commented Apr 6, 2021

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

  • For sniffs which are widely applicable, why not contribute them straight away to WPCS ? Especially as what I see so far in the MinimalPluginStandard directory seem (in part) rip-offs of the WPCS sniffs anyway.
    Improvements to WPCS are very welcome, though do expect them to be reviewed very critically.
    Atomic commits/PRs (incremental changes) will help get things accepted.
  • I see a dev requirement to PHPCSUtils, but as both sniffs appear to use it based on the use statements at the top of the files, this should be a non-dev require.
    You can then also remove the dealerdirect/phpcodesniffer-composer-installer dependency as it will be inherited from PHPCSUtils (with better version constraints).
  • I see numerous utility functions in the sniffs which could benefit from/could be simplified or even replaced by using utilities from PHPCSUtils.
  • I see a testVersion being set for PHPCompatibility in the ruleset and PHPCompatibilityWP as a require, but the PHPCompatibility[WP] ruleset is not included in the ruleset, so not run.
  • I see various duplicate and semi-invalid exclude-patterns in the ruleset.
  • I see the WordPress.NamingConventions.PrefixAllGlobals sniff being included, but without setting a prefix, this is useless.
  • I see a custom way of testing sniffs, while PHPCS has a build-in abstract test class available which simplifies the testing immensely.
    (Also: please don't ever use assertEquals() in tests unless you're testing objects).
  • etc...

@iandunn
Copy link
Member Author

iandunn commented Apr 6, 2021

Thanks for the review and tips!

@iandunn iandunn mentioned this issue Apr 9, 2021
@tellyworth
Copy link
Collaborator

  • 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
Copy link
Collaborator

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
Copy link
Member

jrfnl commented Apr 21, 2021

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants