qltysh/qlty

GitHub: qltysh/qlty

一款用 Rust 编写的多语言代码质量 CLI,集成 linting、格式化、安全扫描和可维护性分析于一体。

Stars: 2967 | Forks: 261

Qlty
## 通用代码检查、自动格式化、可维护性与安全扫描 Qlty CLI 是一款多语言的代码质量工具,提供代码检查、自动格式化、可维护性分析及安全扫描功能,支持 40 多种语言和技术的 70 多种静态分析工具。 借助 Qlty CLI,多语言团队可以通过单一工具利用最佳的代码质量静态分析,获得快速、一致且统一的结果。配置只需通过代码仓库中的一个简单的 `.qlty/qlty.toml` 文件即可完成,该文件可以根据您使用的语言自动生成。 Qlty CLI **完全免费**,可用于包括商业项目在内的所有用途,且不限制贡献者数量。 [![可维护性](https://qlty.sh/badges/f983cb35-d208-4d2f-8872-03fb3e1205de/maintainability.svg)](https://qlty.sh/gh/qltysh/projects/qlty) [![代码覆盖率](https://qlty.sh/badges/f983cb35-d208-4d2f-8872-03fb3e1205de/test_coverage.svg)](https://qlty.sh/gh/qltysh/projects/qlty) [![单元测试](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/d989bb9e8e031015.svg)](https://github.com/qltysh/qlty/actions/workflows/cli.yml) [![最新版本](https://img.shields.io/github/v/release/qltysh/qlty)](https://github.com/qltysh/qlty/releases) [![docs.qlty.sh](https://img.shields.io/badge/docs-docs.qlty.sh-08b2b7)](https://docs.qlty.sh) [![GitHub stars](https://img.shields.io/github/stars/qltysh/qlty)](https://github.com/qltysh/qlty) ## 📖 目录 - [✨ 核心特性](#-key-features) - [🚀 快速入门](#-quick-start) - [📦 安装](#-quick-start) - [在新仓库中设置 Qlty](#setting-up-qlty-in-a-new-repository) - [使用方法](#usage) - [配置](#configuration) - [🧹 可用的 Linter](#-available-linters) - [📊 代码质量指标](#-code-quality-metrics) - [🖥️ 系统要求](#%EF%B8%8F-system-requirements) - [🛟 帮助或反馈](#-help-or-feedback) - [🧑‍💻 贡献](#-contributing) - [⚖️ 许可证](#️-license) ## ✨ 核心特性 ### 我们的功能 | | 特性 | 优势 | | --- | ----------------- | ---------------------------------------------------- | | 🐛 | 代码检查 | 集多语言支持于一体 | | 🖌️ | 自动格式化 | 统一的代码风格 | | 💩 | 可维护性 | 代码异味检测,如复制粘贴检测和复杂度分析 | | 🚨 | 安全扫描 | SAST, SCA, 秘密检测, IaC 分析及更多 | | 🚦 | 代码覆盖率 | 总覆盖率和差异覆盖率 | | 📊 | 质量指标 | 复杂度、重复率、LOC 等 | ### 我们的实现方式 | | 特性 | 优势 | | --- | ----------------------- | --------------------------------------------------------------------------- | | 🌲 | Git 感知 | 关注新引入的质量问题 | | ⚡ | 自动初始化 | 两分钟即可上手 | | ✅ | 自动修复 | 包括工具生成和 AI 生成的修复 | | ⚙️ | 配置即代码 | 版本控制,具有最大的灵活性 | | 🏎️ | 缓存与并发 | 运行静态分析的绝对最快方式 | | 🪝 | Git hooks | 集成 pre-commit 和 pre-push hooks | | 🤖 | Pull request 审查 | 在评论和状态中提供自动反馈 | | 🌐 | 到处运行 | Mac, Linux, 和 Windows,无需依赖 Docker | | 🦀 | 使用 Rust 编写 | 执行速度快且易于贡献 | | 🎁 | 100% 免费 | 包括商业项目,无贡献者限制 | | ⚖️ | 公平源代码 | 在 GitHub 上公开,采用延迟开源发布 (DOSP)。接受 PR! | 💡 了解更多请查阅 [文档](https://docs.qlty.sh/)。 ### Qlty Software:正确实现代码质量与覆盖率 Qlty CLI 是 Qlty Software 全面的代码质量平台的一部分。将代码质量融入您软件开发工作流程的每一个步骤: - [Qlty CLI](https://github.com/qltysh/qlty) -- 使用 Rust 编写的多语言代码质量 CLI - [Qlty Cloud](https://qlty.sh) -- 自动化代码审查和质量趋势 - [Visual Studio Code 扩展](https://github.com/qltysh/qlty-vscode) -- 在您的 IDE 中进行代码检查和自动格式化 - [GitHub Action](https://github.com/qltysh/qlty-action) -- 在您的 CI 工作流中运行 Qlty CLI - [Chrome 和 Firefox 扩展](https://github.com/qltysh/qlty-browser) -- 在 GitHub.com 上添加代码覆盖率数据 ## 🚀 快速入门 ### 安装 安装 Qlty CLI 最快的方式是使用我们的安装脚本,它会安装我们的原生二进制文件: ``` # 在 MacOS 或 Linux 上安装 curl https://qlty.sh | bash # 在 Windows 上安装 powershell -c "iwr https://qlty.sh | iex" ``` 我们也将 CLI 打包为 GitHub Container Registry (GHCR) 上的 [Docker 镜像](https://github.com/qltysh/qlty/pkgs/container/qlty)。 ### 在新仓库中设置 Qlty 在 Git 仓库中设置 Qlty: ``` cd my_repo/ qlty init ``` ### 使用方法 | 示例命令 | 描述 | | ---------------------------------------------------- | ---------------------------------------- | | `qlty init` | 在 Git 仓库中设置 Qlty | | `qlty check --sample=5` | 查看代码检查问题样本 | | `qlty fmt --all` | 自动格式化代码库 | | `qlty smells --all` | 扫描代码异味(如重复代码) | | `qlty metrics --max-depth=2 --sort complexity --all` | 查看代码质量指标摘要 | ### 配置 Qlty CLI 使用 Git 仓库中的 `.qlty/qlty.toml` 文件进行配置。您可以使用 `qlty init` 生成默认配置,然后对其进行自定义。 请阅读我们关于 [配置](https://docs.qlty.sh/analysis-configuration) 的文档以获取更多信息。 ## 🧹 可用的 Linter Qlty CLI 通过其 60 多个 linter 插件提供了超过 20,000 条代码质量规则。 要启用新插件,请将其添加到您的 `.qlty/qlty.toml` 文件中,运行: ``` qlty plugins enable ``` | 技术 | 可用的代码质量工具 | | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 所有文件 | [ast-grep](https://ast-grep.github.io/), [gitleaks](https://gitleaks.io/), [ripgrep](https://github.com/BurntSushi/ripgrep), [semgrep](https://semgrep.dev), [trivy](https://trivy.dev), [trufflehog](https://trufflesecurity.com/trufflehog), [vale](https://vale.sh/) | | Apex | [pmd](https://pmd.github.io/) | | C# | [complexity](https://github.com/qltysh/qlty/tree/main/qlty-smells), [duplication](https://github.com/qltysh/qlty/tree/main/qlty-smells) | | C/C++ | [osv-scanner](https://google.github.io/osv-scanner/), [trivy](https://trivy.dev) | | CloudFormation | [checkov](https://www.checkov.io/) | | CoffeeScript | [coffeelint](https://github.com/clutchski/coffeelint) | | CSS | [biome](https://biomejs.dev/), [prettier](https://prettier.io/), [stylelint](https://stylelint.io/) | | Dart | [osv-scanner](https://google.github.io/osv-scanner/), [trivy](https://trivy.dev) | | Docker | [checkov](https://www.checkov.io/), [dockerfmt](https://github.com/reteps/dockerfmt), [hadolint](https://github.com/hadolint/hadolint), [radarlint](https://github.com/qltysh/radarlint), [trivy](https://trivy.dev) | | Dotenv | [dotenv-linter](https://dotenv-linter.github.io/#/) | | Elixir | [osv-scanner](https://google.github.io/osv-scanner/), [trivy](https://trivy.dev) | | Erlang | [osv-scanner](https://google.github.io/osv-scanner/), [trivy](https://trivy.dev) | | GitHub Actions | [actionlint](https://rhysd.github.io/actionlint/) | | Go | [complexity](https://github.com/qltysh/qlty/tree/main/qlty-smells), [duplication](https://github.com/qltysh/qlty/tree/main/qlty-smells), [gofmt](https://pkg.go.dev/cmd/gofmt), [golangci-lint](https://golangci-lint.run/), [osv-scanner](https://google.github.io/osv-scanner/), [radarlint](https://github.com/qltysh/radarlint) | | GraphQL | [prettier](https://prettier.io/) | | HTML | [prettier](https://prettier.io/) | | Java | [checkstyle](https://checkstyle.org/), [complexity](https://github.com/qltysh/qlty/tree/main/qlty-smells), [duplication](https://github.com/qltysh/qlty/tree/main/qlty-smells), [google-java-format](https://github.com/google/google-java-format), [osv-scanner](https://google.github.io/osv-scanner/), [pmd](https://pmd.github.io/), [radarlint](https://github.com/qltysh/radarlint), [trivy](https://trivy.dev) | | JavaScript | [biome](https://biomejs.dev/), [complexity](https://github.com/qltysh/qlty/tree/main/qlty-smells), [duplication](https://github.com/qltysh/qlty/tree/main/qlty-smells), [eslint](https://eslint.org/), [knip](https://knip.dev/), [osv-scanner](https://google.github.io/osv-scanner/), [oxc](https://oxc.rs/), [prettier](https://prettier.io/), [radarlint](https://github.com/qltysh/radarlint), [trivy](https://trivy.dev) | | JSON | [biome](https://biomejs.dev/), [prettier](https://prettier.io/) | | Kotlin | [complexity](https://github.com/qltysh/qlty/tree/main/qlty-smells), [duplication](https://github.com/qltysh/qlty/tree/main/qlty-smells), [osv-scanner](https://google.github.io/osv-scanner/), [radarlint](https://github.com/qltysh/radarlint), [trivy](https://trivy.dev) | | Kubernetes | [kube-linter](https://docs.kubelinter.io/#/) | | Markdown | [markdownlint](https://github.com/DavidAnson/markdownlint), [prettier](https://prettier.io/) | | OpenAPI | [redocly](https://redocly.com/docs/cli) | | PHP | [complexity](https://github.com/qltysh/qlty/tree/main/qlty-smells), [duplication](https://github.com/qltysh/qlty/tree/main/qlty-smells), [osv-scanner](https://google.github.io/osv-scanner/), [php-codesniffer](https://github.com/squizlabs/PHP_CodeSniffer), [php-cs-fixer](https://cs.symfony.com/), [phpstan](https://phpstan.org/), [radarlint](https://github.com/qltysh/radarlint), [trivy](https://trivy.dev) | | Prisma | [prisma](https://github.com/prisma/prisma) | | Python | [bandit](https://bandit.readthedocs.io/en/latest/), [black](https://github.com/psf/black), [complexity](https://github.com/qltysh/qlty/tree/main/qlty-smells), [duplication](https://github.com/qltysh/qlty/tree/main/qlty-smells), [flake8](https://flake8.pycqa.org/en/latest/), [mypy](https://www.mypy-lang.org/), [osv-scanner](https://google.github.io/osv-scanner/), [radarlint](https://github.com/qltysh/radarlint), [ruff](https://docs.astral.sh/ruff/), [trivy](https://trivy.dev) | | R | [osv-scanner](https://google.github.io/osv-scanner/), [trivy](https://trivy.dev) | | Ruby | [brakeman](https://brakemanscanner.org/), [complexity](https://github.com/qltysh/qlty/tree/main/qlty-smells), [duplication](https://github.com/qltysh/qlty/tree/main/qlty-smells), [osv-scanner](https://google.github.io/osv-scanner/), [radarlint](https://github.com/qltysh/radarlint), [reek](https://github.com/troessner/reek), [rubocop](https://docs.rubocop.org/rubocop/1.75/index.html), [ruby-stree](https://github.com/ruby-syntax-tree/syntax_tree), [standardrb](https://github.com/standardrb/standard), [trivy](https://trivy.dev) | | Rust | [clippy](https://rust-lang.github.io/rust-clippy/), [complexity](https://github.com/qltysh/qlty/tree/main/qlty-smells), [duplication](https://github.com/qltysh/qlty/tree/main/qlty-smells), [osv-scanner](https://google.github.io/osv-scanner/), [rustfmt](https://rust-lang.github.io/rustfmt/?version=v1.8.0&search=), [trivy](https://trivy.dev) | | SASS | [prettier](https://prettier.io/), [stylelint](https://stylelint.io/) | | Scala | [radarlint](https://github.com/qltysh/radarlint) | | Shell | [shellcheck](https://www.shellcheck.net/), [shfmt](https://pkg.go.dev/mvdan.cc/sh/v3) | | SQL | [sqlfluff](https://sqlfluff.com/) | | Swift | [swiftlint](https://realm.github.io/SwifLint/) | | Terraform | [checkov](https://www.checkov.io/), [osv-scanner](https://google.github.io/osv-scanner/), [radarlint](https://github.com/qltysh/radarlint), [tflint](https://github.com/terraform-linters/tflint), [trivy](https://trivy.dev) | | TypeScript | [biome](https://biomejs.dev/), [complexity](https://github.com/qltysh/qlty/tree/main/qlty-smells), [duplication](https://github.com/qltysh/qlty/tree/main/qlty-smells), [eslint](https://eslint.org/), [knip](https://knip.dev/), [oxc](https://oxc.rs/), [prettier](https://prettier.io/) | | YAML | [prettier](https://prettier.io/), [trivy](https://trivy.dev), [yamllint](https://github.com/adrienverge/yamllint) | [完整插件列表](https://github.com/qltysh/qlty/tree/main/qlty-plugins/plugins/linters) 可在 GitHub 上找到。 ## 📊 代码质量指标 Qlty CLI 计算各种代码质量指标,可通过 `qlty metrics` 子命令访问,并可作为趋势在 [Qlty Cloud](https://qlty.sh) 上查看。
重复度
重复密度 重复行数除以代码行数
重复行数 重复的行数
重复块数 连续重复行跨度数
复杂度
复杂度密度 复杂度除以代码行数
总复杂度 认知复杂度 计数
圈复杂度 圈复杂度 计数
可维护性
异味 重复和结构问题的数量
技术债务 解决代码异味所需的估计时间
技术债务比率 技术债务除以估计实现时间
可维护性评级 以字母等级表示的技术债务比率
LCOM 方法内聚缺乏度 (LCOM4)
安全性
各级别安全问题 按高、中、低级别统计的安全问题数量
安全问题 安全问题计数
安全评级 基于安全问题及其严重程度的字母评级
覆盖率
已覆盖行数 被自动化测试覆盖的行数
未覆盖行数 可以被覆盖但未被覆盖的行数
行覆盖率 已覆盖行数除以已覆盖行数加未覆盖行数
差异覆盖率 Git diff 中新增和更改行的行覆盖率
覆盖率评级 以字母等级表示的行覆盖率
大小
类的数量
字段 唯一字段的数量
函数 函数或方法的数量
代码文件 编程语言文件的数量
行数 所有行数,包括空行和注释
代码行数 非空行或注释的行数
注释行数 注释行的数量
注释密度 注释行数除以总行数
问题
问题计数 静态分析问题计数
各级别问题计数 按高、中、低级别统计的静态分析问题计数
质量指标适用于 C#, Go, Java, JavaScript, Kotlin, PHP, Python, Ruby, Rust, 和 TypeScript。 ## 🖥️ 系统要求 Qlty CLI 支持 MacOS, Linux, 和 Windows 的 x86 和 ARM 平台。 ### PHP linter 的额外要求 某些 PHP linter 需要在您的 `$PATH` 中有可用的 PHP 工作环境。要安装 PHP,请使用 [Homebrew](https://brew.sh/) 或其他方法。 ## 🛟 帮助或反馈 - 阅读 [文档](https://docs.qlty.sh) - 加入我们的 [Discord](https://qlty.sh/discord) 聊天 - 通过 GitHub Discussions 获取 [社区支持](https://github.com/orgs/qltysh/discussions/categories/q-a) - 通过 GitHub Discussions 提出 [功能请求](https://github.com/orgs/qltysh/discussions/categories/feedback) - 通过 GitHub Issues 提交 [Bug 报告](https://github.com/qltysh/qlty/issues/new/choose) - 通过 GitHub Issues 提交 [插件请求](https://github.com/qltysh/qlty/issues/new/choose) ## 🧑‍💻 贡献 ### 添加插件 创建插件可以像编写一个小的插件定义 TOML 文件一样简单。如果工具具有自定义输出格式(而不是像 [SARIF](https://sarifweb.azurewebsites.net/) 这样的标准格式),则还需要用 Rust 编写一个简单的输出解析器。 我们也非常乐意通过 [GitHub issues](https://github.com/qltysh/qlty/issues/new/choose) 接受新插件的请求。 ### 开发 CLI 开发 Qlty CLI 需要一个可用的 [Rust 工具链](https://rustup.rs/),并遵循标准的 Rust 开发流程: ``` git clone https://github.com/qltysh/qlty.git cd qlty cargo build cargo test ``` ### 更多信息 关于如何贡献的更多信息可以在 CONTRIBUTING.md 中找到。 安全漏洞报告应按照 SECURITY.md 中概述的流程处理。 ## ⚖️ 许可证 Qlty CLI 采用 [Fair Source](https://fair.io/) 许可证发布。作为 Fair Source,Qlty CLI 可以根据其许可证免费使用(包括商业环境)、修改和分发。 本代码根据 Business Source License 1.1 (BSL) 提供,并通过 Delayed Open Source Publication (DOSP) 转为开源。更多详情请参阅 LICENSE.md。 ### 致谢 我们要感谢所有代码质量工具(如 linter 和 meta-linter)的开发人员,以及所有为开源静态分析领域做出贡献的人。Qlty CLI 建立在数十年这些卓越工作的基础之上。 包含在 Qlty CLI 中的代码许可证可以在 docs/licenses 文件夹中找到。
标签:Linting, LLM应用, Polyglot, Python安全, Qlty, SAST, SOC Prime, 云安全监控, 代码安全, 代码审查, 代码异味, 可视化界面, 多语言支持, 安全合规, 安全测试框架, 开发工具, 开源框架, 弱口令爆破, 技术债务, 持续集成, 漏洞枚举, 盲注攻击, 网络代理, 网络安全研究, 自动化格式化, 请求拦截, 质量门禁, 软件维护性, 通知系统, 通知系统, 静态分析