定制 dragon-code/codestyler 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dragon-code/codestyler

Composer 安装命令:

composer require dragon-code/codestyler

包简介

A tool to automatically fix Coding Style Standards issues by The Dragon Code.

README 文档

README

Codestyler

Stable Version Total Downloads License

Note

Codestyler 5 is the last version that runs on its own code and includes a mechanism for publishing files via command parameters. It is also the last version installed globally via Composer.

Starting with Codestyler 6, the project will contain pint.json and .editorconfig files, and adding them to the project will be done by calling a console command.

Installation

You can install the package using Composer:

composer require dragon-code/codestyler --dev

composer config scripts.style "vendor/bin/rector && vendor/bin/pint --parallel"

It is also possible to establish dependence in the global area of visibility:

composer global require dragon-code/codestyler

After installing the dependency, add a file copy command to the scripts.post-update-cmd section. This will automatically copy the pint.json file to the project root.

When adding the command, replace 8.5 with the minimum PHP version your application works with. Available presets: 8.2, 8.3, 8.4 and `8.5.

You can also add copying the .editorconfig file to help the IDE and calling normalize the composer.json file and biome.json file for Biome Linter:

{
    "scripts": {
        "post-update-cmd": [
            "vendor/bin/codestyle pint 8.5",
            "vendor/bin/codestyle rector laravel",
            "vendor/bin/codestyle editorconfig",
            "vendor/bin/codestyle npm",
            "composer normalize"
        ]
    }
}

When using a globally established dependence, the call must be replaced with the following:

{
    "scripts": {
        "post-update-cmd": [
            "codestyle pint 8.5",
            "codestyle rector laravel",
            "codestyle editorconfig",
            "codestyle npm",
            "composer normalize"
        ]
    }
}

For JS, CSS, JSON

If it is necessary to correct the code style for JS, CSS and JSON, you need to separately set the dependence through the NPM package manager (or any other):

npm i -D @biomejs/biome

After that, write the commands in the package.json file:

{
    "scripts": {
        "lint": "npx @biomejs/biome lint --write",
        "format": "npx @biomejs/biome format --write",
        "style": "npm run lint && npm run format"
    }
}

Usage

PHP Linter

Laravel Pint is used as the linter for PHP.

The linter is invoked by a console command:

composer style

Rector

Rector is uses as the code rector for PHP.

The Rector is invoked by a console command:

composer style

To do this, make sure the file is in the root of the project. You can also automate this process by adding a call to the file copy function in the scripts.post-update-cmd section of the composer.json file.

{
    "scripts": {
        "post-update-cmd": [
            "vendor/bin/codestyle rector laravel"
        ]
    }
}

Available presets:

  • laravel
  • default

Node Linter

Biome is used as the linter for JS, CSS and JSON.

Make sure the biome.json file is in the root of the project. You can also automate this process by adding a call to the file copy function in the scripts.post-update-cmd section of the composer.json file:

{
    "scripts": {
        "post-update-cmd": [
            "vendor/bin/codestyle npm"
        ]
    }
}

EditorConfig

The .editorconfig file helps your IDE to work according to certain rules.

To do this, make sure the file is in the root of the project. You can also automate this process by adding a call to the file copy function in the scripts.post-update-cmd section of the composer.json file.

{
    "scripts": {
        "post-update-cmd": [
            "vendor/bin/codestyle editorconfig"
        ]
    }
}

Composer Normalize

We recommend using the Composer Normalize plugin, which normalizes the composer.json file appearance to match its schema. This will keep each project's file consistent, making it much easier to read.

To activate the plugin, call the console command:

composer config allow-plugins.ergebnis/composer-normalize true

To use this feature, add a call parameter to the post-update-cmd block of the composer.json file:

{
    "scripts": {
        "post-update-cmd": [
            "composer normalize"
        ]
    }
}

Now you can just a run console command:

composer update

Finalized composer.json

After completing all the steps, the composer.json file will have the following changes:

{
    "require-dev": {
        "dragon-code/codestyler": "^6.0"
    },
    "config": {
        "allow-plugins": {
            "ergebnis/composer-normalize": true
        }
    },
    "scripts": {
        "post-update-cmd": [
            "vendor/bin/codestyle pint 8.5",
            "vendor/bin/codestyle rector laravel",
            "vendor/bin/codestyle editorconfig",
            "vendor/bin/codestyle npm",
            "composer normalize"
        ],
        "style": [
            "vendor/bin/rector",
            "vendor/bin/pint --parallel"
        ]
    }
}

Finalized package.json

After completing all the steps, the package.json file will have the following changes:

{
    "scripts": {
        "lint": "npx @biomejs/biome lint --write",
        "format": "npx @biomejs/biome format --write",
        "style": "npm run lint && npm run format"
    },
    "devDependencies": {
        "@biomejs/biome": "^2.2.2"
    }
}

GitHub Actions

To use the Linter with GitHub Actions, just create a file .github/workflows/code-style.yml and insert this content into it:

name: Code Style

on:
    push:
    pull_request:

permissions: write-all

jobs:
    Checks:
        uses: TheDragonCode/.github/.github/workflows/code-style.yml@main
        with:
            php: true
            node: true

Defaults:

  • php: true
  • node: true

IDE

After executing the composer update console command, a .editorconfig file will be added to your application. If the file already exists, it will be replaced.

In order for your IDE to read the code style settings from it, make sure its support is enabled in the settings.

For example, in phpStorm the setting is in the File | Settings | Editor | Code Style:

image

License

This package is licensed under the MIT License.

dragon-code/codestyler 适用场景与选型建议

dragon-code/codestyler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.9M 次下载、GitHub Stars 达 29, 最近一次更新时间为 2022 年 02 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「yaml」 「php」 「json」 「linter」 「formatter」 「format」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dragon-code/codestyler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dragon-code/codestyler 我们能提供哪些服务?
定制开发 / 二次开发

基于 dragon-code/codestyler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.9M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 29
  • 点击次数: 28
  • 依赖项目数: 14
  • 推荐数: 0

GitHub 信息

  • Stars: 29
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-10