dragon-code / codestyler
Dragon Code 提供的一个自动修复编码风格标准问题的工具。
Requires
- php: ^8.1
- ext-dom: *
- ext-json: *
- ext-libxml: *
- ext-mbstring: *
- ext-tokenizer: *
- ext-xml: *
Requires (Dev)
- archtechx/enums: ^1.0
- dragon-code/pretty-array: ^4.1
- dragon-code/support: ^6.12.0
- friendsofphp/php-cs-fixer: ^3.49.0
- illuminate/view: ^10.44.0
- kubawerlos/php-cs-fixer-custom-fixers: ^3.20.0
- laravel-zero/framework: ^10.3.0
- mockery/mockery: ^1.6.7
- nunomaduro/termwind: ^1.15.1
- pedrotroller/php-cs-custom-fixer: ^2.33.0
- pestphp/pest: ^2.33.6
- seld/jsonlint: ^1.10.2
- symfony/yaml: ^6.4.3 || ^7.0
- dev-main
- 4.x-dev
- 4.2.0
- 4.1.0
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- v4
- 3.x-dev
- v3.15.1
- 3.15.0
- v3.14.1
- 3.14.0
- 3.13.0
- v3.12.2
- v3.12.1
- 3.12.0
- 3.11.0
- v3.10.1
- v3.10.0
- v3.9.0
- v3.8.1
- v3.8.0
- v3.7.2
- v3.7.1
- v3.7.0
- v3.6.18
- v3.6.17
- v3.6.16
- v3.6.15
- v3.6.14
- v3.6.13
- v3.6.12
- v3.6.11
- v3.6.8
- v3.6.7
- v3.6.6
- v3.6.5
- v3.6.4
- v3.6.3
- v3.6.2
- v3.6.1
- v3.6.0
- v3.5.1
- v3.5.0
- v3.4.3
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.4
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- 2.x-dev
- v2.6.24
- v2.6.23
- v2.6.22
- v2.6.21
- v2.6.20
- v2.6.19
- v2.6.18
- v2.6.17
- v2.6.16
- v2.6.15
- v2.6.14
- v2.6.13
- v2.6.12
- v2.6.11
- v2.6.10
- v2.6.9
- v2.6.8
- v2.6.7
- v2.6.6
- v2.6.5
- v2.6.4
- v2.6.3
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- 1.x-dev
- v1.13.1
- v1.13.0
- v1.12.4
- v1.12.3
- v1.12.2
- v1.12.1
- v1.12.0
- 1.12-rc.1
- v1.11.1
- v1.11.0
- v1.10.8
- v1.10.7
- v1.10.6
- v1.10.5
- v1.10.4
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.0
- v1.8.7
- v1.8.6
- v1.8.5
- v1.8.4
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.2
- v1.6.1
- v1.6.0
- dev-dependabot/github_actions/peter-evans/create-pull-request-7
This package is auto-updated.
Last update: 2024-09-04 01:19:19 UTC
README
介绍
Dragon Code Styler
是一个面向简约主义者,具有偏见的 PHP 代码风格修复器。 Codestyler
基于 Laravel Pint 和 PHP-CS-Fixer 构建,使得确保您的代码风格保持清洁和一致变得简单。
默认情况下,Codestyler
不需要任何配置,并且会根据 PER
规则集,遵循 The Dragon Code
的具有偏见的编码风格来修复您的代码中的编码风格问题。
感谢您使用您所使用的包的开发者最简单和免费的方式是“星”GitHub 仓库。
安装
必需
- PHP: ^8.1
- Composer: ^2.0
本地
composer global require dragon-code/codestyler
使用方法
当您在项目根目录下运行命令时,将自动读取 composer.json
文件,从中获取您项目的最小 PHP 版本。
这是为了制定应用 Codestyler 的规则。
例如,如果您的项目支持 PHP 8.0 及以上版本,并且您在其中使用了 mkdir($path, 0755)
函数,那么应用 PHP 8.0 的规则将破坏您的代码,因为它会将 0755
替换为 0o755
(mkdir($path, 0o755)
)。
为了避免这种情况发生,我们检查最小 PHP 版本。
请注意,只有在启动脚本执行在包含它的文件夹中时才会读取 composer.json
文件。
CLI
# Check code-style codestyle --test # Fix code-style codestyle # Update `.editorconfig` codestyle editorconfig # Update Dependabot rules codestyle dependabot # Publishes code-style settings for the phpStorm IDE codestyle phpstorm # Show list of available commands codestyle list
选项
路径
修复路径
codestyle foo/bar
测试
测试代码风格错误而不修复它们
codestyle --test
配置
应使用的配置。目标目录将从 Laravel Pint 读取 pint.json
文件,但不包括样式集。
codestyle --config=foo/bar
风险
允许设置是否可以运行风险规则
codestyle --risky --test codestyle --risky
脏
仅修复有未提交更改的文件。
codestyle --dirty
退出
测试代码风格错误而不修复它们,并在第一个错误时停止
codestyle --bail
输出格式
应使用的输出格式。
codestyle --format
可用格式的列表
- checkstyle
- gitlab
- json
- junit
- txt
- xml
帮助命令
要查看可用命令的列表,可以调用控制台命令
codestyle list
要查看关于命令的扩展信息,可以使用 help
选项。例如,
codestyle --help codestyle dependabot --help codestyle editorconfig --help
GitHub 动作
注意
从代码风格器版本 4.2.0 开始,我们将不再支持 GitHub Actions 的 容器。
相反,请使用下面的示例直接使用依赖项安装。
创建一个新的 .github/workflows/code-style.yml
文件并将内容添加到其中
name: Code Style on: [ push, pull_request ] permissions: write-all jobs: check: runs-on: ubuntu-latest if: ${{ github.event_name != 'push' || github.ref != 'refs/heads/main' }} steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv, json coverage: none - name: Install dependency run: composer global require dragon-code/codestyler - name: Check the code-style run: codestyle --test fix: runs-on: ubuntu-latest if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: extensions: curl, mbstring, zip, pcntl, pdo, pdo_sqlite, iconv, json coverage: none - name: Setup Composer run: | composer global config --no-plugins allow-plugins.dragon-code/codestyler true composer global config --no-plugins allow-plugins.ergebnis/composer-normalize true composer config --no-plugins allow-plugins.dragon-code/codestyler true composer config --no-plugins allow-plugins.ergebnis/composer-normalize true - name: Install dependencies run: | composer global require dragon-code/codestyler composer global require ergebnis/composer-normalize - name: Fix the code-style run: | # Copies the `.editorconfig` file to the folder from which the command is run. # The file contains a complete set of instructions for the IDE that supports EditorConfig. codestyle editorconfig # Copies the `The_Dragon_Code_phpStorm.xml` file to the folder from which the command is run. # The file contains a complete set of instructions for JetBrains PhpStorm. codestyle phpstorm # Creates or updates the `dependabot.yml` file for GitHub Actions. codestyle dependabot # The main script for fixing the project code style codestyle # Provides a composer plugin for normalizing `composer.json`. composer normalize - name: Create a Pull Request uses: peter-evans/create-pull-request@v6 with: branch: code-style branch-suffix: random delete-branch: true title: "🦋 The code style has been fixed" commit-message: 🦋 The code style has been fixed body: The code style has been fixed labels: code-style
您还可以通过链接到我们的设置来使用简化的配置。
在这种情况下,将应用以下设置
- 始终检查事件是否不等于
push
或分支是否不等于main
- 纠正代码风格将采取以下步骤
name: Code Style on: [ push, pull_request ] permissions: write-all jobs: style: name: Code Style uses: TheDragonCode/.github/.github/workflows/code-style.yml@main
其他 CI/CD
composer global require dragon-code/codestyler codestyle <command>
IDE
在执行 codestyle editorconfig
控制台命令后,将添加一个 .editorconfig
文件到您的应用程序中。如果文件已存在,它将被替换。
为了使您的 IDE 从该文件中读取代码风格设置,请确保在设置中已启用其支持。
例如,在 phpStorm
中,设置在 文件 | 设置 | 编辑器 | 代码风格
您还可以使用 codestyle phpstorm
控制台命令将模式 xml 文件发布到 phpStorm。您可以将此文件导入到 IDE 中。
许可证
此软件包采用 MIT 许可证 许可。