簡體   English   中英

在 PHP-CS-Fixer 中使用制表符進行縮進

[英]Use tab for indentation in PHP-CS-Fixer

如何配置 PHP-CS-Fixer 以使用制表符進行縮進?

我可以看到indentation_type fixer

* indentation_type [@PSR2, @Symfony]
  | Code MUST use configured indentation type.

但是如何配置縮進類型? 如果我嘗試設置'indentation_type' => 'tab', ,我會收到錯誤

[indentation_type] Is not configurable.

它在文檔中,以及我是如何錯過它的(可能是因為我正在搜索術語“制表符”而不是“縮進”)

對於尋找相同內容的其他人,在PhpCsFixer\\Config有一個setIndent方法。

return PhpCsFixer\Config::create()
    ->setRules([
        '@PSR2' => true,
        'indentation_type' => true,
    ])
    ->setIndent("\t")
    ->setLineEnding("\n")
    ->setFinder($finder)

首先在您的項目根目錄中創建.php_cs文件。 然后.php_cs添加到.php_cs文件

<?php
return PhpCsFixer\Config::create()
->setRules([
    '@PSR2' => true,
    'indentation_type' => true,
])
->setIndent("\t")
->setLineEnding("\n")
->setFinder($finder)

然后運行以下命令來解決問題

vendor/bin/php-cs-fixer fix . --config .php_cs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM