Php cs fixer正在做什么:
function foobar()
{
....
}
and I want:
function foobar() {
....
}
我看不到在我的
.php_cs
文件中保持大括号在同一行的配置,也找不到相关信息在https://github.com/FriendsOfPHP/PHP-CS-Fixer上。我正在使用php-cs-fixerV2。我的配置文件:https://pastebin.com/v03v9Lb5。
Php cs fixer正在做什么:
function foobar()
{
....
}
and I want:
function foobar() {
....
}
.php_cs
文件中保持大括号在同一行的配置,也找不到相关信息在https://github.com/FriendsOfPHP/PHP-CS-Fixer上。我正在使用php-cs-fixerV2。你在这里描述的风格被称为 "the one true brace style"(缩写为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-fixer 插件 将在当前项目的根路径中搜索 .php_cs
配置文件。也可以指定路径。
braces.position_after_functions_and_oop_constructs
设置为same
(默认值为next
):
position_after_functions_and_oop_constructs('next', 'same')
:在经典结构(非匿名类、接口、特征、方法和非lambda函数)之后,是否应该将左花括号放在“下一行”或“同一行”;默认为'next'
myconfig.php_cs:
'braces' => array(
'allow_single_line_closure' => true,
'position_after_functions_and_oop_constructs' => 'same',
),
PHP-CS-fixer配置文件路径
中。 - ramsey_lewis.php_cs
文件,因为这个文件会被默认加载到Atom中的php-cs-fixer中。 - ponsfrilus
[]
。PHP CS Fixer配置非常有帮助:已添加到书签。 - ramsey_lewis