2016-12-14 171 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