![](/img/trans.png)
[英]New line on function argument list while using php-cs-fixer and PHPCodeSniffer
[英]php-cs-fixer : keep brace on the same line of function declaration
Php cs fixer正在做:
function foobar()
{
....
}
而且我要:
function foobar() {
....
}
我無法看到配置是什么配置在我的配置.php_cs
文件中保持同一行,也沒有在https://github.com/FriendsOfPHP/PHP-CS-Fixer上 。 我正在使用php-cs-fixerV2。
我的配置文件: https : //pastebin.com/v03v9Lb5
您已啟用PSR-2,這需要下一行的大括號。 從文檔看起來你可以將braces.position_after_functions_and_oop_constructs
設置為same
(默認為next
):
position_after_functions_and_oop_constructs ('next', 'same')
:是否應該在經典構造(非匿名類,接口,特征,方法和非lambda函數)之后將左大括號放在“next”或“same”行上; 默認為'下一步'
myconfig.php_cs:
'braces' => array(
'allow_single_line_closure' => true,
'position_after_functions_and_oop_constructs' => 'same',
),
你在這里描述的風格被稱為“ 一個真正的支撐風格 ”(縮寫為1TBS或OTBS)。
當我得到完全相同的問題時,我終於在這里結束了,而@Robbie回答有幫助,我仍然需要搜索很多。
所以我終於在我的存儲庫中得到了這個.php_cs
:
<?php
$finder = PhpCsFixer\Finder::create()
//->exclude('somedir')
//->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php'
->in(__DIR__)
;
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'strict_param' => false,
'array_syntax' => ['syntax' => 'long'],
'braces' => [
'allow_single_line_closure' => true,
'position_after_functions_and_oop_constructs' => 'same'],
])
->setFinder($finder)
;
一些解釋(來自( PHP-CS-Fixer README ):
array()
而不是[]
。 是使用長數組還是短數組語法; 默認為'long'; 在IDE這樣的Atom中, php-cs- .php_cs
插件將在當前項目的根路徑中搜索.php_cs
配置文件。 也可以指定路徑。
最后但並非最不重要的是, Michele Locati的網站, PHP CS Fixer配置確實有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.