代码之家  ›  专栏  ›  技术社区  ›  DCYılmaz

VsCode中的PHP CS修复程序我认为它的格式不正确

  •  0
  • DCYılmaz  · 技术社区  · 4 年前

    我通常用PHP编写代码,但我有一个非常简单的html代码,它的结构很糟糕。当我尝试用php-cs修复程序修复它时,情况可能会变得更糟。它将一些元素(如“i”)保持在同一行,但将其类下移。或者它保持了“Lorem”Impsum脚本中的Lorem部分,并将“Impsum”扔下。。。等 notfixed

    fixed 我使用我在互联网上找到的以下配置代码:

    <?php
    $config = new PhpCsFixer\Config();
    return $config
    ->setRules([
        '@PSR12' => true,
        'new_with_braces' => false,
        'array_indentation' => true,
        'array_syntax' => ['syntax' => 'short'],
        'combine_consecutive_unsets' => true,
        'multiline_whitespace_before_semicolons' => true,
        'single_quote' => true,
        'blank_line_before_statement' => true,
        'braces' => [
            'allow_single_line_closure' => true,
        ],
        'concat_space' => ['spacing' => 'one'],
        'declare_equal_normalize' => true,
        'function_typehint_space' => true,
        'include' => true,
        'lowercase_cast' => true,
        'no_multiline_whitespace_around_double_arrow' => true,
        'no_spaces_around_offset' => true,
        'no_unused_imports' => true,
        'no_whitespace_before_comma_in_array' => true,
        'no_whitespace_in_blank_line' => true,
        'object_operator_without_whitespace' => true,
        'single_blank_line_before_namespace' => true,
        'ternary_operator_spaces' => true,
        'trailing_comma_in_multiline' => true,
        'trim_array_spaces' => true,
        'unary_operator_spaces' => true,
        'binary_operator_spaces' => true,
        'whitespace_after_comma_in_array' => true,
        'single_trait_insert_per_statement' => false,
        'method_separation' => false,
    ])
    ->setLineEnding("\n");
    

    有人给我一个更好的配置建议吗?谢谢你的回复。

    0 回复  |  直到 4 年前
        1
  •  0
  •   WinterSilence    4 年前

    PSR-12格式纯PHP代码,PhpCsFixer不太好格式化混合代码,使用PHP CodeSniffer(或 badoo/phpcf )相反

    推荐文章