-
-
Notifications
You must be signed in to change notification settings - Fork 522
Description
The I18n sniff needs a text_domain property to be set in a custom ruleset to trigger the text-domain checks.
The DeprecatedFunctions, DeprecatedClasses and the upcoming DeprecatedParameters (#826) sniffs need a minimum_supported_version property.
When the sniffs are used on plugins and themes, this information is typically already available in the theme/plugin headers in style.css/ readme.txt or the main plugin file and - at least for the minimum_supported_version a pain to keep in sync.
Since PHPCS 2.5.0 there appears to be a - rarely used - option to bootstrap a file to be run between when the sniffs are loaded and when they are actually run.
See:
- Add bootstrap file option squizlabs/PHP_CodeSniffer#783
- https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-bootstrap-file
I would like to suggest we explore the possibility of auto-detecting the above mentioned properties using a bootstrap file.
Some thoughts:
- Look only in the root of the directory being sniffed for any of the files mentioned & if the file is found, parse the top of the file similar to how WP core does. Looking further down or up can quickly become more complicated than is warranted.
- Custom
text_domainproperties if set should still be respected as this is an array and the property can be used to pass more than one text-domain.- So I suggest for the in-sniff logic to check for a custom property first and if none is found, use the auto-detected info. Alternatively, the auto-detected property could be merged into the custom property.
- Custom
minimum_supported_versionproperties should be overruled if something different is auto-detected, as that is the "official" minimum supported version so this should always be leading.
I suggest this to be added to the Extra ruleset as these sniffs are typically contained therein.
Opinions ?
/cc @grappler This principle may also be useful for the theme sniffs.