Skip to content

Order of installed_paths inconsistent between runs #125

@kevinfodness

Description

@kevinfodness

Problem/Motivation

I am using this plugin to register several phpcs sniffs from different repos into my installed_paths with phpcs. I am also using Travis CI's caching directives in combination with phpcs' caching directives in order to cache the results of scans between runs for files that have not been modified. However, it appears that this plugin doesn't register installed_paths in a consistent way between CI runs, which invalidates the phpcs cache, thus negating the benefits of caching between runs.

Expected behaviour

Runs of this plugin between CI jobs should produce consistent output for the value of installed_paths (specifically, the order of the paths).

Actual behaviour

The order of the paths in installed_paths is not always the same between CI runs. This is likely due to a race condition of when certain packages finish installing.

Steps to reproduce

Use a standard in composer.json that references multiple standards, or reference multiple standards in composer.json (see example below). Create a Travis CI job to run phpcs and echo the value of installed_paths. Note that it will not always be in the same order between runs.

Example for run 1:

"installed_paths": "../../alleyinteractive/alley-coding-standards,../../wp-coding-standards/wpcs,../../sirbrillig/phpcs-variable-analysis,../../automattic/vipwpcs",

Example for run 2:

"installed_paths": "../../sirbrillig/phpcs-variable-analysis,../../automattic/vipwpcs,../../alleyinteractive/alley-coding-standards,../../wp-coding-standards/wpcs",

Contents of composer.json:

{
  "require-dev": {
    "alleyinteractive/alley-coding-standards": "^0.2.0"
},

Contents of composer.json in alley-coding-standards:

{
  "name": "alleyinteractive/alley-coding-standards",
  "description": "PHPCS sniffs for Alley Interactive",
  "type": "phpcodesniffer-standard",
  "license": "GPL-2.0-or-later",
  "require": {
    "squizlabs/php_codesniffer": "^3.5.0",
    "dealerdirect/phpcodesniffer-composer-installer": "*",
    "wp-coding-standards/wpcs": "^2.3.0",
    "automattic/vipwpcs": "^2.1.0",
    "phpcompatibility/phpcompatibility-wp": "*"
  },
  "require-dev": {}
}

Proposed changes

Make the installed_paths value consistent between runs by alphabetizing the values. This will allow repos that use this plugin to leverage Travis CI and phpcs caching for unmodified files by ensuring that the configuration values in the cache file, specifically the value for installed_paths, is consistent between runs if nothing changed.

Environment

Question Answer
OS Linux, Ubuntu Bionic, running on Travis CI
PHP version 7.3.14
Composer version 2.0.8
PHP_CodeSniffer version 3.5.8
Dealerdirect PHPCS plugin version 0.7.0
Install type project local

Output of vendor/bin/phpcs --config-show:

Using config file: /home/travis/build/alleyinteractive/brookings/vendor/squizlabs/php_codesniffer/CodeSniffer.conf

Contents of CodeSniffer.conf:

<?php
 $phpCodeSnifferConfig = array (
  'installed_paths' => '../../alleyinteractive/alley-coding-standards,../../wp-coding-standards/wpcs,../../sirbrillig/phpcs-variable-analysis,../../automattic/vipwpcs',
)
?>

Tested against master branch?

  • I have verified the issue still exists in the master branch.

I have not verified this against the master branch, but looking at the diff between 0.7.0 and the current HEAD, there shouldn't be anything in that diff that would affect this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions