Skip to content

Absolute vs relative paths #156

@jrfnl

Description

@jrfnl

I'd like to re-open the discussion around whether the paths registered with PHPCS should be absolute or relative paths.

Some previous issues related to this: #14, #33, #73

Current status after #28:

  • Global installs use absolute paths
  • Local installs use relative paths

Problems I'm seeing

  • In some tests on Windows, I'm seeing duplicate relative paths being registered, i.e.:
    Using config file: C:\\Users\\runneradmin\\AppData\\Local\\Temp\\PHPCSPluginTest\\RegisterExternalStandardsTest_61fe56765bc692.23339840\\local\\vendor\\squizlabs\\php_codesniffer\\CodeSniffer.conf
    
    installed_paths: ../../../../../../../../../../RUNNER~1/AppData/Local/Temp/PHPCSPluginTest/RegisterExternalStandardsTest_61fe56765bc692.23339840/local/vendor/phpcs-composer-installer,../../phpcs-composer-installer
    
    As this will result in the same standard(s) being registered twice with PHPCS, this is likely to cause problems with the autoloading of sniffs.
  • Even without duplicate paths, I've had reports of relative paths causing problems with the PHPCS autoloading of sniffs: Unable to get stock install working, cannot declare class errors PHPCompatibility/PHPCompatibility#1311 (comment)

Proposal

Always use absolute paths.

Further research needed

  • What about projects in a dual OS setup, like Windows with WSL or a Vagrant environment ?
  • What about projects with a committed vendor directory ?
    => I'd like to suggest that they can add a script to run this plugin to their composer.json and can run that script whenever the project is checked out. After all, the plugin will update the paths based on the runtime environment, so should fix the paths in the committed CodeSniffer.Conf file to the new environment.
  • Can this be made easier ?
    => In Composer 2.x, Plugins can add their own commands to Composer. We could consider adding a custom command to run this plugin. This would negate the need to add the script.
    Ref: https://getcomposer.org/doc/articles/plugins.md#command-provider
  • Should there still be an option for users to use relative paths ?
    => Along the same lines as the search-depth option, we could consider adding a force-relative-paths option.
    We should probably also investigate if custom commands can take custom arguments. In that case, we could possible add support for a --force-relative-paths CLI argument if needs be.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions