Readouble

Laravel 10.x Laravel Pint

イントロダクションIntroduction

Laravel Pint(ピント:PHP lint)は、ミニマリストのための主張を持ったPHPコードスタイルフィクサです。PintはPHP-CS-Fixer上に構築されており、あなたのコードスタイルがクリーンで一貫したものになるよう、シンプルにします。Laravel Pint[https://github.com/laravel/pint] is an opinionated PHP code style fixer for minimalists. Pint is built on top of PHP-CS-Fixer and makes it simple to ensure that your code style stays clean and consistent.

Pintは、すべての新しいLaravelアプリケーションに自動的にインストールされますので、すぐに使い始めることができます。デフォルトで、Pintは設定を必要とせず、Laravelの主張を取り入れたコーディングスタイルに従い、コードスタイルの問題を修正します。Pint is automatically installed with all new Laravel applications so you may start using it immediately. By default, Pint does not require any configuration and will fix code style issues in your code by following the opinionated coding style of Laravel.

インストールInstallation

PintはLaravelフレームワークの最近のリリースに含まれているため、通常インストールは不要です。しかし、古いアプリケーションでは、Composer経由でLaravel Pintをインストールできます。Pint is included in recent releases of the Laravel framework, so installation is typically unnecessary. However, for older applications, you may install Laravel Pint via Composer:

composer require laravel/pint --dev

Pintの実行Running Pint

プロジェクトのvendor/binディレクトリにある、pintバイナリを起動し、Pintへコードスタイルの問題を修正するように指示できます。You can instruct Pint to fix code style issues by invoking the pint binary that is available in your project's vendor/bin directory:

./vendor/bin/pint

また、特定のファイルやディレクトリに対してPintを実行することもできます。You may also run Pint on specific files or directories:

./vendor/bin/pint app/Models

./vendor/bin/pint app/Models/User.php

Pintは更新した全ファイルの完全なリストを表示します。Pintを起動する際に、-vオプションを指定すれば、Pintが行う変更についてさらに詳しく確認できます。Pint will display a thorough list of all of the files that it updates. You can view even more detail about Pint's changes by providing the -v option when invoking Pint:

./vendor/bin/pint -v

もし、実際にファイルを変更せず、Pintにコードのスタイルエラーを検査させたい場合は、--testオプションを使用します。If you would like Pint to simply inspect your code for style errors without actually changing the files, you may use the --test option:

./vendor/bin/pint --test

もし、Gitへコミットされていない変更のあるファイルだけをPintに修正させたい場合は、--dirty オプションを使用します。If you would like Pint to only modify the files that have uncommitted changes according to Git, you may use the --dirty option:

./vendor/bin/pint --dirty

Pintの設定Configuring Pint

前述したように、Pintは設定を一切必要としません。しかし、プリセットやルール、インスペクトフォルダをカスタマイズしたい場合は、プロジェクトのルートディレクトリに、pint.jsonファイルを作成してください。As previously mentioned, Pint does not require any configuration. However, if you wish to customize the presets, rules, or inspected folders, you may do so by creating a pint.json file in your project's root directory:

{
    "preset": "laravel"
}

また、特定のディレクトリにあるpint.jsonを利用したい場合は、Pintを起動する際に--configオプションを指定してください。In addition, if you wish to use a pint.json from a specific directory, you may provide the --config option when invoking Pint:

pint --config vendor/my-company/coding-style/pint.json

プリセットPresets

プリセットは、コード内のスタイルの問題を修正するために使用するルールセットを定義しています。デフォルトでPintは、laravelプリセットを使用します。これは、Laravelの意見に基づいたコーディングスタイルに従って問題を修正するものです。しかし、Pintに--presetオプションを指定することで、別のプリセットも指定できます。Presets defines a set of rules that can be used to fix code style issues in your code. By default, Pint uses the laravel preset, which fixes issues by following the opinionated coding style of Laravel. However, you may specify a different preset by providing the --preset option to Pint:

pint --preset psr12

お望みならば、プロジェクトのpint.jsonファイルにプリセットを設定できます。If you wish, you may also set the preset in your project's pint.json file:

{
    "preset": "psr12"
}

Pintが現在サポートしているプリセットは、laravelperpsr12symfony です。Pint's currently supported presets are: laravel, per, psr12, and symfony.

ルールRules

ルールは、コードのスタイルに関する問題を修正するためにPintが使用するスタイルのガイドラインです。前述したように、プリセットはあらかじめ定義されたルールのグループであり、ほとんどのPHPプロジェクトに最適であるため、通常、含まれる個々のルールについて心配する必要はありません。Rules are style guidelines that Pint will use to fix code style issues in your code. As mentioned above, presets are predefined groups of rules that should be perfect for most PHP projects, so you typically will not need to worry about the individual rules they contain.

しかし、必要に応じて、pint.jsonファイルで特定のルールの有効/無効を指定できます。However, if you wish, you may enable or disable specific rules in your pint.json file:

{
    "preset": "laravel",
    "rules": {
        "simplified_null_return": true,
        "braces": false,
        "new_with_braces": {
            "anonymous_class": false,
            "named_class": false
        }
    }
}

Pintは、PHP-CS-Fixer上に構築しています。したがって、プロジェクトのコードスタイルの問題を修正するため、いずれかのルールを使用できます。PHP-CS-Fixerの設定を参照してください。Pint is built on top of PHP-CS-Fixer[https://github.com/FriendsOfPHP/PHP-CS-Fixer]. Therefore, you may use any of its rules to fix code style issues in your project: PHP-CS-Fixer Configurator[https://mlocati.github.io/php-cs-fixer-configurator].

ファイル/フォルダの除外Excluding Files / Folders

デフォルトでPintは、プロジェクト内のvendorディレクトリにあるものを除く、すべての.phpファイルを検査します。もし、より多くのフォルダを除外したい場合は、exclude設定オプションを使用して除外可能です。By default, Pint will inspect all .php files in your project except those in the vendor directory. If you wish to exclude more folders, you may do so using the exclude configuration option:

{
    "exclude": [
        "my-specific/folder"
    ]
}

もし、指定した名前のパターンに一致するファイルをすべて除外したい場合は、notName設定オプションを使用します。If you wish to exclude all files that contain a given name pattern, you may do so using the notName configuration option:

{
    "notName": [
        "*-my-file.php"
    ]
}

もし、ファイルの正確なパスを指定して除外したい場合は、notPath設定オプションを使用して除外できます。If you would like to exclude a file by providing an exact path to the file, you may do so using the notPath configuration option:

{
    "notPath": [
        "path/to/excluded-file.php"
    ]
}

章選択

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

Pagination和文
ペジネーション
ペギネーション
ページネーション
ページ付け
Scaffold和文
スカフォールド
スキャフォールド
型枠生成
本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作