Php cs fixer 正在做:
function foobar()
{
....
}
Run Code Online (Sandbox Code Playgroud)
而且我要:
function foobar() {
....
}
Run Code Online (Sandbox Code Playgroud)
我看不到在我的配置.php_cs
文件或https://github.com/FriendsOfPHP/PHP-CS-Fixer上将大括号保持在同一行的配置是什么。我正在使用 php-cs-fixerV2。
我的配置文件:https : //pastebin.com/v03v9Lb5
您在此处描述的样式称为“真正的大括号样式”(缩写为 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)
;
Run Code Online (Sandbox Code Playgroud)
一些解释(来自(PHP-CS-Fixer README):
array()
而不是[]
. 是否使用长数组或短数组语法;默认为“长”;在 IDE 这样的 Atom 中,php-cs-fixer 插件会.php_cs
在当前项目的根路径中搜索配置文件。也可以指定路径。
最后但并非最不重要的是,Michele Locati的网站,PHP CS Fixer 配置确实可以提供帮助。
您启用了 PSR-2,这需要下一行的大括号。从文档看来,您可以设置braces.position_after_functions_and_oop_constructs
为same
(默认为next
):
position_after_functions_and_oop_constructs ('next', 'same')
: 在经典构造(非匿名类、接口、特征、方法和非 lambda 函数)之后,左大括号是否应该放在“下一个”或“相同”行上;默认为“下一个”
myconfig.php_cs:
'braces' => array(
'allow_single_line_closure' => true,
'position_after_functions_and_oop_constructs' => 'same',
),
Run Code Online (Sandbox Code Playgroud)