Skip to content

Use a PHPCS bootstrap file to auto-detect text-domain and minimum supported wp version #995

@jrfnl

Description

@jrfnl

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:

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_domain properties 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_version properties 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions