Atom-Beautify未加载php-cs-fixer自定义配置

kuarbcqp  于 2023-02-03  发布在  PHP
关注(0)|答案(3)|浏览(93)

我安装了带有PHP-CS-Fixer插件的Atom。我正在尝试使用一些自定义规则来应用同行大括号样式。
我试过使用in-Atom配置选项,但无法使其工作。我试过设置position_after_functions_and_oop_constructs并将其放在Atom中的PHP-CS-FIXER Rules中,但无法工作。
因此,我设置了config的自定义路径,即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)
;

它没有工作,原子是没有做一个适当的美化。任何想法来执行规则?
注:
我对以下款式感兴趣:

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

31moq8wy1#

由于美化工作不正常,程序可能遇到了错误。您可以运行 Atom Beautify:从命令面板中帮助Debug Editor 获取调试信息。
你的配置工作完美的罚款为我和问题似乎是你的命名。
只需将atom.php_cs重命名为**.php_cs**,并从设置中删除任何配置文件路径。

fwzugrvs

fwzugrvs2#

对于任何新手,请注意,新版本的配置文件需要命名为.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;
ufj5ltwl

ufj5ltwl3#

如果你已经按照official github repo中的建议安装了php-cs-fixer,那么你很可能已经安装了当前版本,目前是V3(确切地说是V3.14.3)。
您可以通过执行以下命令来检查php-cs-fixer版本

php-cs-fixer -V

不幸的是,包atom-beautify(当前版本V0.33.4)似乎支持php-cs-fixer直到版本V2,就像你在包设置中看到的:

如果使用较新版本的php-cs-fixeratom-beautify在查找本地自定义配置文件(即.php-cs-fixer.php,还有.php_cs.php-cs.dist)时似乎会出现问题,除非您在包设置中指定它的完整路径,这只有在您在所有项目中使用相同的自定义配置时才有意义。

**长话短说:**您可以通过创建一个测试php文件并执行以下命令来检查您的php-cs-fixer是否正在独立工作,以及是否正在加载您的本地自定义配置文件

php-cs-fixer fix test.php

之后,您有三个选项:

  • 在命令行中使用php-cs-fixer
  • php-cs-fixer降级到V2并使用atom-beautify软件包
  • 或者使用当前版本的php-cs-fixer,但使用其他Atom包来代替。

相关问题