使用 GrumPHP 运行 PHP CS 修复程序

Kev*_*vin 5 php symfony phpcs

我正在使用 GrumPhp 嗅探我在 symfony 项目中的提交: https: //github.com/phpro/grumphp

这是我的配置:

parameters:
    git_dir: .
    bin_dir: vendor/bin
    tasks:
        phpcsfixer:
            config_file: ~
            config: sf23
            fixers: [psr2, symfony, indentation]
            level: psr2
            verbose: true
Run Code Online (Sandbox Code Playgroud)

我的问题是:

有没有办法让Grumphp在我提交时自动运行php-cs-fixer

Dev*_*rry 3

就在这里! https://github.com/phpro/grumphp/blob/master/doc/tasks.md

由于您的帖子有点旧,这里是新更新的文档,但您仍然可以使用版本一!https://github.com/phpro/grumphp/blob/master/doc/tasks/php_cs_fixer2.md

您可以尝试此配置,但它是 phpcsfixer version2!:

# grumphp.yml
parameters:
    bin_dir: "./vendor/bin"
    git_dir: "."
    hooks_dir: ~
    hooks_preset: local
    stop_on_failure: false
    ignore_unstaged_changes: false
    process_async_limit: 10
    process_async_wait: 1000
    process_timeout: 60
    ascii:
        failed: grumphp-grumpy.txt
        succeeded: grumphp-happy.txt
    tasks:
        phpcsfixer2:
        allow_risky: false
        cache_file: ~
        config: ~
        rules: ['@Symfony']
        using_cache: true
        path_mode: ~
        verbose: true
Run Code Online (Sandbox Code Playgroud)

您的配置看起来不错,输出是什么?您是否安装了 cs 修复程序并将 grumPHP 配置配置为 CS 修复程序的路径? https://github.com/FriendsOfPHP/PHP-CS-Fixer#usage