PHPCSStandards / PHPCSExtra

A collection of code standards for use with PHP_CodeSniffer
GNU Lesser General Public License v3.0
91 stars 8 forks source link

Feature suggestion: new sniff for detecting brand name or text string #302

Closed ernilambar closed 10 months ago

ernilambar commented 10 months ago

Is your feature request related to a problem?

This could be probably generalization of WordPress.WP.CapitalPDangit. Like we can use it for any brand name or string like WooCommerce, Github, etc

Describe the solution you'd like

Inspired from https://github.com/WordPress/WordPress-Coding-Standards/issues/1945

Use cases:

jrfnl commented 10 months ago

Thank you for the suggestion, but I'm not inclined to accept this feature request.

To detect this, all tokens which can contain text should be examined. However, whether something should be flagged, or not, is highly dependent on the context. Think:

$array = [
    'woocommerce' => 'array keys should not be flagged as changing those breaks other code',
];

// And what about callbacks ? Should not be flagged as function names have their own naming conventions.
array_map('github_callback', $array);

// But hey, we do want to flag this:
printf( 'sentence containing %s keyword', 'woocommerce');

// Now what about a comment containing github ?
// But we don't want to flag it in a URL: https://github.com/org/package/blob/master/woocommerce-interface.php

In other words, a "generic" sniff for such a feature would be a nightmare to maintain and support as code can be written in lots of different ways, so there will always be more exceptions to take into account and some codebases will want the exception, while others won't want it.