visual / eslint-config-php
visual PHP 项目的 eslint 配置
v0.0.17
2024-08-16 09:57 UTC
Requires
- friendsofphp/php-cs-fixer: ^3.51
README
安装
1.安装依赖项
在终端运行以下命令以安装必要的依赖项
composer require bisual/eslint-config-php --dev
2.代码检查器配置
在项目的根目录下创建一个名为 .php-cs-fixer.php
的文件,并添加以下内容
<?php namespace Bisual\LintConfigPhp; use Bisual\LintConfigPhp\CodingStyle; return CodingStyle::getConfig();
在 CodingStyle::getConfig()
函数中,您可以提供参数来配置格式化器。它作为参数传递一个具有以下选项的数组
- $disabled_rules (数组): 要禁用的规则。
- $routes (数组): 要格式化的文件的路径。
- $exclude_files (数组): 要排除在格式化之外的文件。
3.安装格式化器扩展
在 Visual Studio Code 中安装 junstyle.php-cs-fixer 扩展。
提示
为了方便新贡献者在 Visual Studio Code 中安装格式化器扩展,您可以在 .vscode
文件夹中创建一个名为 extensions.json
的文件,内容如下
{ "recommendations": ["junstyle.php-cs-fixer"] }
4.自动格式化配置
要启用保存时的自动代码格式化,请按照以下步骤操作
- 在项目的根目录下创建一个名为 .vscode 的文件夹。
- 在 .vscode 文件夹内,创建一个名为 settings.json 的文件。
- 将以下内容添加到 settings.json 文件中
{ "[php]": { "editor.formatOnSave": true, "editor.defaultFormatter": "junstyle.php-cs-fixer" }, "php-cs-fixer.onsave": true, "php-cs-fixer.formatHtml": true, "php-cs-fixer.executablePath": "${workspaceFolder}/vendor/bin/php-cs-fixer", "php-cs-fixer.config": ".php-cs-fixer.php" }
在做出这些更改后,您可能需要重新启动 Visual Studio Code 以使其生效。