2016-12-14 98 views
2

我在我的项目的根目录下创建了一个名为.gm_cs的文件,并且全局安装了php-cs-fixerPHP-CS-FIXER忽略我的配置

在config文件中,以下

<?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__); 

我打电话从混帐的bash命令在Windows上执行以下操作:
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
php-cs-fixer fix -vvv ./private --config=.gm_cs
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

任何意见或帮助任何人可以提供将不胜感激。

回答

2

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

此外,文件需要被命名.php_cs

+0

一个您正在使用哪个版本? –

+0

可能是1.x,它在2.x中重命名。 –

1

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