Skip to content

php-cs-fixer git hook doesn't work if more than 1 file php file is staged #630

@wujekbogdan

Description

@wujekbogdan

Describe the bug

php-cs-fixer git hook doesn't work if more than 1 file php file is staged - it throws an In ConfigurationResolver.php line 539: For multiple paths config parameter is required. error.

To reproduce

  1. Enable the php-cs-fixer git hook
hooks = {
  php-cs-fixer = {
    enable = true;
  };
};
  1. Stage more than one PHP file (this is crucial! With just one PHP file, it's all fine)
  2. Run pre-commit run
  3. It will fail with the message In ConfigurationResolver.php line 539: For multiple paths config parameter is required.

This message is misleading because it sounds as if the config file was missing, but what happens instead is that php-cs-fixer doesn't accept multiple files that pre-commit provides it with by default. It's a well-known limitation of the php-cs-fixer tool.

The workaround I'm using is:

php-cs-fixer = {
    enable = true;
    # php-cs-fixer won't accept multiple file paths at a time. This is why we're providing an override and spawning
    # as many php-cs-fixer processes as the number of staged *.php files.
    entry = ''
      sh -c '
        for file in "$@"; do
          php-cs-fixer fix "$file"
        done
      ' --
    '';
  };

So, while I understand this isn't an issue on either devenv or pre-commit, it still makes the php-cs-fixer devenv plugin useless.

I'm not sure what the real solution is - I'm afraid that the hacky solution I use might be the only option. Otherwise, I would simply remove this plugin since with the default configuration, it's simply useless.

Version
devenv 1.8.2 (aarch64-darwin)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions