Skip to content

Releases: Yoast/yoastcs

3.1.0

05 Apr 08:59
533b74e
Compare
Choose a tag to compare

3.1.0 - 2024-04-05

Added

  • Threshold report: aside from the pre-existing YOASTCS_ABOVE_THRESHOLD constant, a new YOASTCS_THRESHOLD_EXACT_MATCH constant will now be available to determine (from a calling script) whether the error/warning thresholds were matched exactly or need to be updated.

Changed

  • Composer: Supported version of PHP_CodeSniffer has been changed from ^3.8.0 to ^3.9.1.
  • Composer: Supported version of PHPCSUtils has been changed from ^1.0.9 to ^1.0.10.
  • Composer: Supported version of WordPressCS has been changed from ^3.0.1 to ^3.1.0.
    This introduces one new sniff - Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence - to the YoastCS ruleset.
  • Composer: Supported version of SlevomatCodingStandard has been changed from ^8.14.0 to ^8.15.0.
  • Composer: Supported version of PHP Parallel Lint has been changed from ^1.3.2 to ^1.4.0.
  • PHPCS: The default value for the minimum_wp_version (previously minimum_supported_wp_version) property which is used by various WPCS sniffs has been updated to WP 6.3 (was 6.2).
  • Various housekeeping.

3.0.0

14 Dec 15:22
Compare
Choose a tag to compare

3.0.0 - 2023-12-14

Added

  • Composer/PHPCS: Dependencies on the following external PHPCS standards packages: PHPCSUtils, PHPCSExtra, SlevomatCodingStandard, VariableAnalysis and WordPressVIP Coding Standards.
  • PHPCS: A best effort has been made to add support for new PHP syntaxes/features to all YoastCS native sniffs and utility functions (or to verify/improve existing support).
    YoastCS native sniffs and utilities have received fixes for the following syntaxes:
    • PHP 5.6
      • Parameter unpacking in function calls.
    • PHP 8.0
      • Named arguments in function calls.
    • PHP 8.1
      • Enumerations.
      • First class callables.
    • PHP 8.2
      • Readonly classes.
  • PHPCS: The Yoast.Commenting.CoversTag sniff includes a new warning for the use of ClassName<*> type @covers annotations, as these have been deprecated as of PHPUnit 9.0.
  • PHPCS: The Yoast.Files.FileName sniff now has the (optional) ability to check whether file names comply with PSR-4.
    To enable this ability, add the custom psr4_paths property to your ruleset. The psr4_paths property is an array property and mirrors the psr4 setting in the Composer autoload directive. It expects a namespace prefix as the array key and a comma separated list of relative paths as the array value. Multiple PSR-4 paths can be passed (array elements).
    For files containing OO structures in a "PSR4 path", the oo_prefixes and the excluded_files_strict_check properties will be ignored.
  • PHPCS: The Yoast.NamingConventions.NamespaceName sniff will now throw a MissingPrefix error if a prefix is expected, but the namespace name does not include a prefix.
  • PHPCS: The Yoast.NamingConventions.NamespaceName sniff will now throw a DirectoryInvalid error if a file is in a directory which would not result in a valid namespace name.
  • PHPCS: The Yoast.NamingConventions.NamespaceName sniff now has the (optional) ability to check whether namespace names comply with PSR-4.
    To enable this ability, add the custom psr4_paths property to your ruleset. The psr4_paths property is an array property and mirrors the psr4 setting in the Composer autoload directive. It expects a namespace prefix as the array key and a comma separated list of relative paths as the array value. Multiple PSR-4 paths can be passed (array elements).
    A psr4_paths property will take precedence over the, potentially set, src_directory and prefixes properties.
  • PHPCS: The following sniffs/error codes have been added to/enabled in the YoastCS ruleset (with appropriate configuration):
    • All new sniffs which were added/included in WordPressCS 3.0.0.
    • PSR1.Classes.ClassDeclaration (for tests only)
    • PSR12.Properties.ConstantVisibility
    • SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation
    • SlevomatCodingStandard.Classes.ClassStructure
    • SlevomatCodingStandard.Classes.ModernClassNameReference
    • SlevomatCodingStandard.Functions.StaticClosure
    • SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses
    • SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants
    • SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions
    • SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
    • SlevomatCodingStandard.Namespaces.UnusedUses
    • SlevomatCodingStandard.Namespaces.UseFromSameNamespace
    • SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint (tests excluded)
    • SlevomatCodingStandard.TypeHints.LongTypeHints
    • SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue
    • SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition
    • SlevomatCodingStandard.TypeHints.ParameterTypeHint
    • SlevomatCodingStandard.TypeHints.PropertyTypeHint
    • SlevomatCodingStandard.TypeHints.ReturnTypeHint
    • Squiz.Commenting.FunctionComment.InvalidReturnNotVoid
    • Squiz.Commenting.FunctionComment.MissingReturn
    • Squiz.Commenting.FunctionComment.ParamCommentNotCapital
    • Squiz.Commenting.FunctionComment.SpacingAfterParamName
    • Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines
    • Universal.Classes.RequireFinalClass (for tests only, doubles/mocks excluded)
    • Universal.CodeAnalysis.NoDoubleNegative
    • Universal.ControlStructures.DisallowAlternativeSyntax
    • Universal.ControlStructures.IfElseDeclaration
    • Universal.FunctionDeclarations.NoLongClosures
    • Universal.Operators.ConcatPosition
    • Universal.Operators.DisallowLogicalAndOr
    • Universal.PHP.LowercasePHPTag
    • Universal.UseStatements.DisallowUseConst
    • Universal.UseStatements.DisallowUseFunction
    • VariableAnalysis.CodeAnalysis.VariableAnalysis
    • WordPressVIPMinimum.Classes.DeclarationCompatibility
    • WordPressVIPMinimum.Hooks.AlwaysReturnInFilter
    • WordPressVIPMinimum.Security.EscapingVoidReturnFunctions
    • WordPressVIPMinimum.Security.ProperEscapingFunction
  • PHPCS: New PathHelper, PathValidationHelper and PSR4PathsTraits classes/traits for use by the sniffs.
  • Readme: section on the YoastCS Threshold report.

Changed

  • ⚠️ The minimum supported PHP version for this package is now PHP 7.2 (was 5.4).
  • PHPCS: all sniffs are now runtime compatible with PHP 7.2 - 8.3.
  • ⚠️ PHPCS: All non-abstract classes in YoastCS are now final and all non-public methods and properties are now private.
    Additionally, all non-private methods in traits have also been made final.
  • Composer: Supported version of PHP_CodeSniffer has been changed from ^3.7.1 to ^3.8.0.
  • ⚠️ Composer: Supported version of WordPressCS has been changed from ^2.3.0 to ^3.0.1.
    YoastCS is now fully compatible with WordPressCS 3.0.
    Note: WordPressCS 3.0.0 contains breaking changes. Please read the WordPressCS release announcement and follow the WordPressCS upgrade guides.
  • PHPCS: The default value for the minimum_wp_version (previously minimum_supported_wp_version) property which is used by various WPCS sniffs has been updated to WP 6.2 (was 6.0).
  • PHPCS: Files in a wp-content/plugins/ subdirectory will now always be ignored for PHPCS scans.
  • PHPCS: The ruleset included value for the doubles_path property in the Yoast.Files.TestDoubles sniff has been updated to include the typical Yoast test/Unit/Doubles and test/WP/Doubles directories as per the restructured tests.
  • PHPCS: The Yoast.Commenting.CodeCoverageIgnoreDeprecated sniff will now also examine class docblocks.
  • PHPCS: The Yoast.Commenting.FileComment sniff will no longer flag a file docblock in a namespaced file which doesn't contain an OO structure as redundant.
  • PHPCS: The Yoast.Files.FileName sniff will now also examine the file name of PHP files using only the PHP short open tag (<?=).
  • PHPCS: The Yoast.Files.FileName sniff will now respect inline PHPCS native ignore/disable annotations for the sniff.
    Note: the annotations are respected for the sniff itself, but not for individual error codes from the sniff!
  • PHPCS: The Yoast.Files.FileName sniff now recognizes more word separators, meaning that files using other word separators than underscores will now be flagged for not using hyphenation.
  • PHPCS: The Yoast.Files.FileName sniff will now throw a potential "missing basepath" warning only once per run, not for each file triggering the sniff.
  • PHPCS: The default value for the doubles_path property in the Yoast.Files.TestDoubles sniff is now an empty array.
    This property should now always be set in a custom ruleset.
    Note: the YoastCS ruleset sets this property, so if the ruleset is used instead of explicitly including the individual sniff, this change has no impact.
  • PHPCS: The "namespace level depth" check in the Yoast.NamingConventions.NamespaceName sniff now allows for test fixtures directories being at a deeper level than directly under a tests directory.
  • PHPCS: The Yoast.NamingConventions.ObjectNameDepth sniff now allows for test classes using a _TestCase suffix and will allow for extra object name depth for those, same as for test classes with a _Test suffix.
  • ⚠️ PHPCS: The Yoast.Yoast.AlternativeFunctions sniff has been renamed to Yoast.Yoast.JsonEncodeAlternative.
  • The Yoast.Yoast.JsonEncodeAlternative sniff (previously Yoast.Yoast.AlternativeFunctions) is now disabled by default for files in a /tests/ directory.
  • The Generic.CodeAnalysis.UselessOverridingMethod sniff is now disabled by default for files in a /tests/*/Doubles/ directory.
  • The WordPress.WP.GlobalVariablesOverride sniff is now disabled by default for files in a /tests/ directory.
  • PHPCS: The eror messages for the Yoast.Files.TestDoubles sniff have been improved for accuracy.
  • PHPCS: The error message for the Yoast.NamingConventions.NamespaceName.Invalid error has been made more informative/actionable.
  • PHPCS: The error message for the Yoast.NamingConventions.ValidHookName.NonString warning has been made more actionable.
  • PHPCS: Various sniffs have received efficiency fixes for improved performance.
  • PHPCS: the XML documentation for various sniffs ha...
Read more

2.3.1

09 Mar 10:18
Compare
Choose a tag to compare

2.3.1 - 2023-03-09

Changed

  • PHPCS: The default setting for the minimum supported PHP version for repos using YoastCS is now PHP 7.2 (was 5.6).
  • Composer: Supported version of PHP_CodeSniffer has been changed from ^3.7.1 to ^3.7.2.

2.3.0

09 Jan 11:35
Compare
Choose a tag to compare

2.3.0 - 2023-01-09

Added

  • PHPCS: New Yoast.Tools.BrainMonkeyRaceCondition sniff.
    This sniff will flag test code which is likely to run into a particular race condition when using BrainMonkey to set expectations for WP hook functions.

Changed

  • PHPCS: The default value for the minimum_supported_wp_version property which is used by various WPCS sniffs has been updated to WP 6.0 (was 5.7).
  • Composer: The package will now identify itself as a static analysis tool. Thanks @GaryJones!
  • Composer: Supported version of PHP_CodeSniffer has been changed from ^3.6.2 to ^3.7.1.
  • Composer: Supported version of PHPCompatibilityWP has been changed from ^2.1.3 to ^2.1.4.
  • Composer: Supported version of the Composer PHPCS plugin has been changed from ^0.5 || ^0.6.2 || ^0.7 to ^0.6.2 || ^0.7 || ^1.0.
  • Various housekeeping.

Fixed

  • PHPCS: Yoast.Files.FileComment: the sniff will now allow for and respect phpcs:disable comments for this sniff when found in a file docblock.

2.2.1

22 Feb 12:56
Compare
Choose a tag to compare

2.2.1 - 2022-02-22

Changed

  • Composer: Supported version of PHP_CodeSniffer has been changed from ^3.6.0 to ^3.6.2.
  • Composer: Supported version of PHPCompatibilityWP has been changed from ^2.1.0 to ^2.1.3.
  • Composer: Supported version of PHP Parallel Lint has been changed from ^1.3.1 to ^1.3.2.
  • Composer: Supported version of PHP Console Highlighter has been changed from ^0.5.0 to ^1.0.0.
  • Readme: Updated installation instructions for compatibility with Composer 2.2+ and other minor improvements.
  • Various housekeeping.

2.2.0

22 Sep 14:15
Compare
Choose a tag to compare

2.2.0 - 2021-09-22

Added

  • PHP Parallel Lint will now be provided via YoastCS.
    If php-parallel-lint/php-parallel-lint and php-parallel-lint/php-console-highlighter are included in the require-dev of your composer.json file, you can remove these after updating the version constraint for YoastCS to "yoast/yoastcs": "^2.2.0".
  • PHPCS: A custom YoastCS\Yoast\Reports\Threshold report.
    This commit adds a custom report for use with PHPCS to compare the run results with "threshold" settings.
    • The report will look in the runtime environment for the following two environment variables and will take the values of those as the thresholds to compare the PHPCS run results against:
      • YOASTCS_THRESHOLD_ERRORS
      • YOASTCS_THRESHOLD_WARNINGS
    • If the environment variables are not set, they will default to 0 for both, i.e. no errors or warnings allowed.
    • After the report has run, a global YOASTCS_ABOVE_THRESHOLD constant (boolean) will be available which can be used in calling scripts.
    • To use this report, run PHPCS with the following command-line argument: --report=YoastCS\Yoast\Reports\Threshold.
      Note: depending on the OS the command is run on, the backslashes in the report name may need to be escaped (doubled).
  • PHPCS: The PSR12.ControlStructures.BooleanOperatorPlacement sniff.
    Enforces that boolean operators in multi-line control structures are always placed at the start of a line.
  • PHPCS: Yoast.Commenting.CodeCoverageIgnoreDeprecated: Support for attributes (PHP 8.0+) placed between a function or class declaration and the associated docblock.
  • PHPCS: Yoast.Commenting.TestHaveCoversTag: Support for attributes (PHP 8.0+) placed between a function or class declaration and the associated docblock.
  • PHPCS: Yoast.NamingConventions.ObjectNameDepth: Support for attributes (PHP 8.0+) placed between a function or class declaration and the associated docblock.
  • PHPCS: Yoast.NamingConventions.ObjectNameDepth: Support for examining the word count in CamelCaps class names.
  • PHPCS: Yoast.NamingConventions.ValidHookName: Verification that backslashes in namespace-like prefixes in double quoted strings are slash-escaped.
  • An initial CONTRIBUTING file with guidelines on acceptance testing changes to the sniffs in this repository.

Changed

  • PHPCS: The default value for the minimum_supported_wp_version property which is used by various WPCS sniffs has been updated to WP 5.7 (was 5.4).
  • Composer: Supported version of PHP_CodeSniffer has been changed from ^3.5.0 to ^3.6.0.
  • Composer: Supported version of WordPressCS has been changed from ^2.2.0 to ^2.3.0.
  • Composer: Updated the supported versions of dev dependencies.
  • Readme: Minor documentation improvements.
  • Continuous Integration: CI has been moved from Travis to GitHub Actions.
  • Various housekeeping.

Fixed

  • PHPCS: Yoast.Commenting.CoversTag: @covers tags refering to classes and functions which don't follow the WordPressCS naming conventions will now be regarded as valid.
  • PHPCS: Yoast.Commenting.TestsHaveCoversTag: the sniff will now also report missing @covers tags for test methods without docblock.
  • PHPCS: Yoast.Commenting.TestsHaveCoversTag: the determination whether a class or method is a test class or method has been made more flexible to allow for different test naming conventions.
  • PHPCS: Yoast.Commenting.TestsHaveCoversTag: will no longer expect a @covers tag for abstract test methods.
  • PHPCS: Yoast.Files.FileComment: fixed performance issue.
  • PHPCS: Yoast.Files.FileName: will no longer throw an error when a class names is an exact match for one of the "removable" prefixes (as there would be nothing left to name the file as).
  • PHPCS: Yoast.NamingConventions.ObjectNameDepth: the object name depth for underscore prefixed class names will now be calculated correctly.
  • PHPCS: Yoast.NamingConventions.ValidHookName: will now recognize slash-escaped backslashes in namespace-like prefixes correctly when in a double quoted string.

2.1.0

27 Oct 09:54
Compare
Choose a tag to compare

2.1.0 - 2020-10-27

Added

  • PHPCS: A new check to the Yoast.Files.TestDoubles sniff to verify that all double/mock classes have either Double or Mock in the class name.
  • PHPCS: Metrics to the Yoast.NamingConventions.NamespaceName sniff to see the breakdown of the number of levels used in namespace names across a code base.
    To see the metrics, run PHPCS with the --report=info option.
  • PHPCS: Metrics to the Yoast.NamingConventions.ObjectNameDepth sniff to see the breakdown of the number of words used in object names across a code base.
    To see the metrics, run PHPCS with the --report=info option.
  • PHPCS: Metrics to the Yoast.NamingConventions.ValidHookName sniff to see the breakdown of the number of words used in hook names across a code base, as well as a break down of old-style versus new-style hook name usage.
    To see the metrics, run PHPCS with the --report=info option.

Changed

  • PHPCS: The default value for the minimum_supported_wp_version property which is used by various WPCS sniffs has been updated to WP 5.4 (was 5.3).
  • Composer: Supported version of the DealerDirect Composer PHPCS plugin has been changed to allow for the newly released 0.7.0 version which adds support for Composer 2.0.
    Note: this requirement is flexible to prevent conflicts with included standards which may include the plugin as well.
  • Travis: improved testing against the upcoming PHP 8.0.
  • Various housekeeping.

Fixed

  • PHPCS: The Yoast.Files.FileName sniff expects a -functions suffix for a function-only file. The sniff has been updated to also allow such a file to be called functions.php without further specification.
    This widening is specifically intended for namespaced function-only files.
  • PHPCS: The Yoast.NamingConventions.NamespaceName sniff has improved handling of the allowance for an extra namespace level for test double directories for non-conventional test directory set-ups (like YoastSEO).

2.0.2

02 Apr 17:18
Compare
Choose a tag to compare

2.0.2 - 2020-04-02

Changed

  • PHPCS: The default value for the minimum_supported_wp_version property which is used by various WPCS sniffs has been updated to WP 5.3 (was 5.2).

2.0.1

06 Feb 11:59
Compare
Choose a tag to compare

[2.0.1] - 2020-02-06

Changed

  • Composer: Supported version of the DealerDirect Composer PHPCS plugin has been changed from ^0.5.0 to ^0.5 || ^0.6.
    Note: this requirement is flexible to prevent conflicts with included standards which may include the plugin as well.
  • Various housekeeping.

Fixed

  • Yoast.NamingConventions.NamespaceName: fixed a potential "undefined index" notice.

2.0.0

17 Dec 07:46
Compare
Choose a tag to compare

[2.0.0] - 2019-12-17

Added

  • PHPCS: New Yoast.NamingConventions.ObjectNameDepth sniff.
    • For objects declared within a namespace, this sniff verifies that an object name consist of maximum three words separated by underscores.
    • For objects which are part of a unit test suite, a _Test, _Mock or _Double suffix at the end of the object name will be disregarded for the purposes of the word count.
    • The sniff has two configurable properties max_words (error) and recommended_max_words (warning). The default for both is 3.
  • PHPCS: New Yoast.NamingConventions.NamespaceName sniff.
    This sniff verifies that:
    • Namespace names consist of a maximum of three levels (excluding the plugin specific prefix) and recommends for the name to be maximum two levels deep.
      For unit test files, Tests\(Doubles\) directly after the prefix will be ignored when determining the level depth.
    • The levels in the namespace name directly translate to the directory path to the file.
    • The sniff has four configurable properties:
      • max_levels (error) and recommended_max_levels (warning) which are by default set to 3 and 2 respectively.
      • src_directory to indicate the project root(s) for the path-to-name translation when the project root is not the repo root directory.
      • prefixes to set the plugin specific prefix(es) to take into account.
  • PHPCS: New Yoast.NamingConventions.ValidHookName sniff.
    This sniff extends and adds to the upstream WordPress.NamingConventions.ValidHookName sniff.
    The sniff will ignore non-prefixed hooks and hooks with a prefix unrelated to the plugin being examined, to prevent errors being thrown about hook names which are outside of our control.
    This sniff verifies that:
    • Hook names are in lowercase with words separated by underscores (same as WordPressCS).
    • Hook names are prefixed with the plugin specific prefix in namespace format, i.e. Yoast\WP\PluginName.
      Note: The prefix is exempt from the lowercase with words separated by underscores rule.
      If the non-namespace type prefix for a plugin is used, the sniff will throw a warning.
    • The actual hook name (after the prefix) consist of maximum four words separated by underscores.
      • Note: The hook_name part should be descriptive for the (dev-)user and does not need to follow the namespace or file path of the file they are in.
      • Also note: for dynamic hook names where the hook name length can not reliably be determined, the sniff will throw a warning at severity 3 suggesting the hook name be inspected manually.
        As the default severity for PHPCS is 5, this warning at severity 3 will normally not be shown.
        It is there to allow for intermittently checking of the dynamic hook names. To trigger it, --severity=3 should be passed on the command line.
    • The sniff has three configurable properties:
      • maximum_depth (error) and soft_maximum_depth (warning). The default for both is 4.
      • prefixes to set the plugin specific prefix(es) to take into account.
  • PHPCS: The Generic.Arrays.DisallowLongArraySyntax sniff.
    WPCS 2.2.0 demands long array syntax. In contrast to that, YoastCS demands short array syntax.
  • PHPCS: The Generic.ControlStructures.DisallowYodaConditions sniff.
    In contrast to WPCS, YoastCS never demanded Yoda conditions. With the addition of this sniff, "normal" (non-Yoda) conditions will now be enforced.
  • PHPCS: The Generic.WhiteSpace.SpreadOperatorSpacingAfter sniff.
    Enforces no space between the ... spread operator and the variable/function call it applies to.
  • PHPCS: The PEAR.WhiteSpace.ObjectOperatorIndent sniff.
    Enforce consistent indentation of chained method calls to one more or less than the previous call in the chain and always at least one in from the start of the chain.
  • PHPCS: The PSR12.Classes.ClosingBrace sniff.
    This sniff disallows the outdated practice of // end ... comments for OO stuctures.
  • PHPCS: The PSR12.Files.ImportStatement sniff.
    Import use statements must always be fully qualified, so a leading backslash is redundant (and discouraged by PHP itself).
    This sniff enforces that no leading backslash is used for import use statements.
  • PHPCS: The PSR12.Files.OpenTag sniff.
    Enforces that a PHP open tag is on a line by itself in PHP-only files.
  • PHPCS: A CustomPrefixesTrait to handle checking names against a list of custom prefixes.
  • Composer: lint script which uses the Parallel-Lint package for faster and more readable linting results.

Changed

  • ⚠️ PHPCS: Yoast.Files.FileName sniff: the public $prefixes property, which can be used to indicate which prefixes should be stripped of a class name when translating it to a file name, has been renamed to $oo_prefixes.
    Custom repo specific rulesets using the property should be updates to reflect this change.
  • ⚠️ PHPCS: Yoast.Files.FileName sniff: the public $exclude property, which can be used to indicate which files to exclude from the file name versus object name check, has been renamed to $excluded_files_strict_check.
    Custom repo specific rulesets using the property should be updates to reflect this change.
  • PHPCS: The default setting for the minimum supported PHP version for repos using YoastCS is now PHP 5.6 (was 5.2).
  • PHPCS: The default value for the minimum_supported_wp_version property which is used by various WPCS sniffs has been update to WP 5.2 (was 4.9).
  • Composer: Supported version of PHP_CodeSniffer has been changed from ^3.4.2 to ^3.5.0.
    Note: this makes the option --filter=gitstaged available which can be used in git pre-commit hooks to only check staged files.
  • Composer: Supported version of WordPressCS has been changed from ^2.1.1 to ^2.2.0.
  • Composer: Supported version of PHPCompatibilityWP has been changed from ^2.0.0 to ^2.1.0.
  • Travis: the build check is now run in stages.
  • Travis: Tests against PHP 7.4 are no longer allowed to fail.
  • Various housekeeping & code compliance with YoastCS 2.0.0.