【问题标题】:Atom-beautify not loading php-cs-fixer custom configAtom-beautify 不加载 php-cs-fixer 自定义配置
【发布时间】:2019-07-22 23:27:59
【问题描述】:

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

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

因此,我为我的配置设置了一个自定义路径,即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。

【问题讨论】:

    标签: php atom-beautify


    【解决方案1】:

    由于美化没有正常工作,程序可能遇到了错误。 您可以从命令面板运行Atom Beautify:帮助调试编辑器以获取调试信息。
    你的配置对我来说非常好,问题似乎是你的命名。

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

    【讨论】:

    • 调试没有显示任何关于 php 美化的信息。问题是 Atom-beautify 没有遵循我的规则,而只是使用默认规则。关于php_cs路径,我在Atom的设置中设置了,使用的是.php_cs结尾的文件的绝对路径。
    • @Jaeger 问题是它找不到您的文件。如果我复制并粘贴您的设置,它工作得很好。您是否尝试从设置中删除绝对路径并将文件重命名为 .php_cs(名称中没有其他任何内容)?它应该至少在您的调试日志中显示一些内容。尝试一直滚动到底部并在那里查看或在日志中搜索“错误”一词
    • 重命名文件没有得到应用,因​​为 Windows 不接受空的命名文件。
    • 谢谢!!正如你所说,配置是正确的。问题在于配置文件的附加命名。这真是一个奇怪的问题。再次感谢!
    【解决方案2】:

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

    确保 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;
    

    【讨论】:

      猜你喜欢
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 2017-11-26
      • 1970-01-01
      • 2017-06-25
      • 2019-12-07
      • 1970-01-01
      相关资源
      最近更新 更多