15

我安装了带有 PHP-CS-Fixer 插件的 Atom。我正在尝试使用一些自定义规则来应用同行大括号样式。

我曾尝试使用 in-Atom 配置选项,但无法使其工作。我已经尝试设置position_after_functions_and_oop_constructs并将其放入PHP-CS-FIXER RulesAtom 中,但没有奏效。

因此,我为我的配置设置了一个自定义路径,即C:\xampp\htdocs\myproject\atom.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)
;

它没有用,Atom 没有做适当的美化。有执行规则的想法吗?

笔记:

我有兴趣拥有以下风格:

  public function someFunction(){ 
    // code here
}
  • 我使用 Windows 10 作为操作系统,Atom 是 IDE,并通过 Composer 安装了 PHP-cs-fixer。
4

2 回答 2

6

由于美化无法正常工作,程序可能遇到了错误。您可以从命令面板运行Atom Beautify:Help Debug Editor以获取调试信息。
您的配置对我来说非常好用,问题似乎出在您的命名上。

只需将您的atom.php_cs重命名为.php_cs并从设置中删除任何配置文件路径。

于 2019-03-09T17:43:02.730 回答
0

对于任何新人,请注意新版本需要将配置文件命名为.php-cs-fixer.php. 太有趣了,我用谷歌搜索,看到了我的问题,哈哈。

确保 php-cs-fixer 与 fixer 一起全局安装,并在完成所有这些更改后重新启动 Atom 以确保它被应用。

此外,新配置看起来像这样

<?php

$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__)
;

$config = new PhpCsFixer\Config();
$config->setRules([
        '@PSR2' => true,
        'strict_param' => false,
        'array_syntax' => ['syntax' => 'long'],
        'no_spaces_around_offset' => [
          'positions' => [ "inside", "outside" ]
        ],
        'no_spaces_inside_parenthesis' => true,
        'array_indentation' => true,
        'no_extra_blank_lines' => true,
        'object_operator_without_whitespace' => true,
        'multiline_whitespace_before_semicolons' => true,
        'switch_case_space' => true,
        'indentation_type' => true,
        'blank_line_after_namespace' => true,
        "no_break_comment"=> true,
        "no_closing_tag"=> true,
        'switch_case_semicolon_to_colon' => true,
        "no_spaces_after_function_name"=> true,
        "no_trailing_whitespace"=> true,
        "no_trailing_whitespace_in_comment"=> true,
        'no_whitespace_before_comma_in_array'=> true,
        'braces' => [
            'allow_single_line_closure' => true,
            'position_after_functions_and_oop_constructs' => 'same'],
    ])
    ->setFinder($finder);
  return $config;
于 2022-02-22T08:03:21.960 回答