[英]PHP-CS-FIXER is ignoring my config
我在項目的根目錄中創建了一個名為.gm_cs
的文件,並且php-cs-fixer
.gm_cs
已全局安裝。
在配置文件中如下
<?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
php-cs-fixer fix -vvv ./private --config=.gm_cs
php-cs-fixer fix -vvv ./private --config=./.gm_cs
無奈.php_cs
,我從composer / vendor文件夾中復制了.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-cs-fixer
版本是Symfony\\CS\\Fixer\\
,並且不需要$rules
。
此外,該文件需要命名為.php_cs
獨立於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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.