maximal/gitlab-code-quality
Composer 安装命令:
composer create-project maximal/gitlab-code-quality
包简介
GitLab Code Quality generator for PHP and JS projects
README 文档
README
This program generates Code Climate report for GitLab Code Quality widget in merge requests and pipelines using various tools and linters:
They are automatically detected in the following paths:
vendor/bin/psalmvendor/bin/phpstanvendor/bin/phpcsvendor/bin/ecsnode_modules/eslint/bin/eslint.jsnode_modules/stylelint/bin/stylelint.mjsnode_modules/@biomejs/biome/bin/biome
Two JS runtimes supported (to run Biome, ESLint, and StyleLint checks):
The application is written in pure PHP (8.0+) without any framework or library dependencies.
Installation
Install the tool via Composer:
composer require --dev maximal/gitlab-code-quality
Make the test run:
./vendor/bin/gitlab-code-quality > gl-code-quality-report.json
Now, you should have gl-code-quality-report.json file with all code quality issues found in your project.
Usage
Edit your GitLab CI/CD config to have code_quality step, which runs this tool.
Example .gitlab-ci.yml file:
# ... ... ... # GitLab Code Quality Widget # https://docs.gitlab.com/ee/ci/testing/code_quality.html#view-code-quality-results code_quality: stage: test script: - ./vendor/bin/gitlab-code-quality > gl-code-quality-report.json artifacts: reports: codequality: gl-code-quality-report.json expire_in: 1 month paths: [gl-code-quality-report.json] # ... ... ...
Strict Mode
By default, the tool returns non-zero exit code (1) only if critical errors are found. For example, on PHP syntax parsing errors (the code cannot be executed at all). This is considered a non-strict behavior.
Although, you can harden issue handling and have non-zero exit code (2) if any issues are found:
./vendor/bin/gitlab-code-quality --strict > gl-code-quality-report.json
In strict mode, code quality stage will fail CI/CD pipeline even on minor issues.
Configuration
Code quality tools are detected automatically and run with their default config files.
You can override this behavior in extra section of your project’s composer.json file:
{ // composer.json // ... ... ... "extra": { // GitLab Code Quality report settings with their default values // All the paths and filenames are relative to the root of the project "gitlab-code-quality": { // Directory for PHP checks/linters "php-dir": ".", // Directory for JS checks/linters "js-dir": "resources", // Paths above are typical for Laravel projects // Print issue statistics table to STDERR (`false` to only print issues JSON to STDOUT) "stats": true, // Print last issue location for every issue type in statistics table: // `false` or `"no"` — do not print // `true` or `"yes"` — print // `"single"` (default) — print only if the issue is the only one of its class "last": "single", // Run Psalm and PHP CodeSniffer with `--no-cache` and ECX with `--clear-cache` "cache": false, // Strict mode: // `false` to return non-zero exit code only if critical errors are found (for example, PHP parsing errors) // `true` to return non-zero exit code if any issues are found "strict": false, // Run Psalm if it exists in `vendor/bin` "psalm": true, // Psalm config file path "psalm-config": "psalm.xml", // Run PHPStan if it exists in `vendor/bin` "phpstan": true, // PHPStan config file path "phpstan-config": "phpstan.neon", // Run PHP CodeSniffer if it exists in `vendor/bin` "phpcs": true, // PHP CodeSniffer standard (name or path to rules file) "phpcs-standard": "PSR12", // PHP CodeSniffer ignore paths (string or array, will be added to `--ignore=` flag) "phpcs-ignore": "", // Run ECS (Easy Coding Standard) if it exists in `vendor/bin` "ecs": true, // ECS config file path "ecs-config": "ecs.php", // Bun executable for EsLint and StyleLint (preferred over Node) "bun": "bun", // Node executable for EsLint and StyleLint (used if no Bun found) "node": "node", // Run ESLint if it exists in `node_modules/eslint/bin/eslint.js` "eslint": true, // ESLint config file "eslint-config": ".eslintrc.yml", // Run StyleLint if it exists in `node_modules/stylelint/bin/stylelint.mjs` "stylelint": true, // StyleLint config file "stylelint-config": ".stylelintrc.yml", // Files to check glob pattern for StyleLint "stylelint-files": "resources/**/*.{css,scss,sass,vue}", // Run Biome if it exists in `node_modules/@biomejs/biome/bin/biome` "biome": true, // Biome config file "biome-config": "biome.jsonc" } }, // ... ... ... }
In most cases you only need to specify php-dir and js-dir paths. For example:
{ // composer.json // ... ... ... "require-dev": { // ... "maximal/gitlab-code-quality": "^1.0", // ... }, // ... ... ... "extra": { "gitlab-code-quality": { // Run all quality tools if they exist, // considering that PHP files are located in `app` directory // and JS files are located in `frontend` directory "php-dir": "app", "js-dir": "frontend", } }, // ... ... ... }
In an ordinary Laravel project this tool runs in zero-config way with Laravel’s default paths (php-dir is . and js-dir is resourses):
{ // composer.json // ... ... ... "require-dev": { // ... "maximal/gitlab-code-quality": "^1.0", // ... }, // ... ... ... "extra": { "laravel": { // ... Laravel’s `dont-discover` and other configs ... }, // No `gitlab-code-quality` section }, // ... ... ... }
Coding Style
PER-3T / PSR-12T (PHP’s standard PER-3 / PSR-12 with SmartTabs instead of spaces).
Author
maximal/gitlab-code-quality 适用场景与选型建议
maximal/gitlab-code-quality 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43.31k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2023 年 03 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「ci」 「report」 「widget」 「gitlab」 「cd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maximal/gitlab-code-quality 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maximal/gitlab-code-quality 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maximal/gitlab-code-quality 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Reportico Open Source PHP Report Designer
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Allow KoolReport to use twig template engine to render view
Add a weather widget to Flarum
Pure PHP library to read JRXML files made with 'JasperSoft Studio' and generate reports in PDF
统计信息
- 总下载量: 43.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-20