【问题标题】:PHP-CS-FIXER is ignoring my configPHP-CS-FIXER 忽略了我的配置
【发布时间】:2017-04-29 08:15:14
【问题描述】:

我在项目的根目录中创建了一个名为 .gm_cs 的文件,并且全局安装了 php-cs-fixer

配置文件如下

<?php
 $rules = array(
     '@PSR2' => true,
     'combine_consecutive_unsets' => true,
     'no_extra_consecutive_blank_lines' => array('break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'),
     'no_useless_else' => true,
     'no_useless_return' => true,
     'ordered_class_elements' => true,
     'array_syntax' => array('syntax' => 'short'),
     'ordered_imports' => true,
     'phpdoc_add_missing_param_annotation' => true,
     'psr4' => true,
     'strict_comparison' => true,
     'strict_param' => true,
 );

 $fixers = array(
     '-pre_increment'
 );

 return PhpCsFixer\Config::create()->setRiskyAllowed(false)->setRules($rules)->fixers($fixers)->in(__DIR__);

我在 windows 上从 git-bash 调用命令,内容如下:
php-cs-fixer fix -vvv ./private --config-file=gm_cs

我也试过这些:
php-cs-fixer fix -vvv ./private --config-file=.gm_cs
php-cs-fixer fix -vvv ./private --config-file=./.gm_cs
php-cs-fixer fix -vvv ./private --config gm_cs
php-cs-fixer fix -vvv ./private --config .gm_cs
php-cs-fixer fix -vvv ./private --config ./.gm_cs
php-cs-fixer fix -vvv ./private --config=gm_cs
@987654331 @
php-cs-fixer fix -vvv ./private --config=./.gm_cs

我绝望地从我的作曲家/供应商文件夹中复制了.php_cs

<?php
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);

return Symfony\CS\Config::create()
    // use default SYMFONY_LEVEL and extra fixers:
    ->fixers(array(
        '-pre_increment',
    ))
    ->finder(
        Symfony\CS\Finder::create()
            ->exclude('Symfony/CS/Tests/Fixtures')
            ->in(__DIR__)
    )
;

并减少修复程序以停止预增量,然后使用前面列出的所有命令运行它,它仍然没有解决问题。

最重要的是,我只是希望它停止将$i++ 交换为++$i,因为这是我继承的一个大型项目,我还没有时间测试所有这些更改(不存在单元测试但是)。

任何人都可以提供任何建议或帮助将不胜感激。

【问题讨论】:

    标签: php configuration composer-php psr-2 php-cs-fixer


    【解决方案1】:

    原来我使用的php-cs-fixer的版本是Symfony\CS\Fixer\的版本,不需要$rules

    另外,文件需要命名为.php_cs

    【讨论】:

    • 你用的是哪个版本的?
    • 可能是1.x,2.x改名了。
    【解决方案2】:

    Symfony 独立示例:http://www.inanzzz.com/index.php/post/m9yq/creating-a-standalone-composer-json-library-or-package

    .php_cs

    return PhpCsFixer\Config::create()
        ->setUsingCache(false)
        ->setRules([
            'array_syntax' => ['syntax' => 'short'],
            'ordered_imports' => true,
        ])
        ->setFinder(
            PhpCsFixer\Finder::create()
                ->exclude(['bin', 'vendor'])
                ->in(__DIR__)
        );
    

    Symfony 依赖示例:

    .php_cs

    $finder = Symfony\CS\Finder::create()
        ->exclude(['app', 'spec', 'build', 'bin', 'web', 'vendor'])
        ->in(__DIR__);
    
    return  Symfony\CS\Config::create()
        ->fixers(['short_array_syntax', '-phpdoc_align', 'ordered_use'])
        ->finder($finder);
    

    没有.php_cs文件的例子:

    $ bin/php-cs-fixer fix src --fixers=short_array_syntax
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 1970-01-01
      • 2019-07-22
      • 2019-12-07
      • 1970-01-01
      • 2018-11-10
      • 2015-09-04
      相关资源
      最近更新 更多