Rust Clippy集合了一系列规则用于改进Rust代码的质量,这个规则集包含了600条以上的规则。这些规则被分成了几个大类,可以在允许Clippy的时候指定分类。
目前有如下几个分类:
- clippy::all 执行所有检查规则
- clippy::correctness 检查错误逻辑和代码
- clippy::suspicious 检查可疑逻辑和代码
- clippy::style 代码风格相关的检查规则
- clippy::complexity 复杂性相关的检查规则
- clippy::perf 性能相关的检查规则
- clippy::pedantic 严格会引起误报的规则
- clippy::restriction 阻止使用语言或库功能的规则
- clippy::nursery 人在开发中的规则
- clippy::cargo cargo相关的规则
你可以把Clippy整合到工作流程中,比如自动构建中。
Rust Clippy中的大多数规则没有额外配置,约有50条规则有自定义配置。
使用gui配置工具
使用gui配置工具,可以让配置rust clippy参数更简单。
在凌鲨(linksaas)的微应用里面可以找到clippy配置助手,快速配置自定义规则。
凌鲨(linksaas)是以开源方式运作的,您可以从linksaas · 极狐GitLab 访问源代码。也可以从 凌鲨 软件研发团队信息枢纽 下载预编译的版本。
附录
自定义配置
- arithmetic-side-effects-allowed
- arithmetic-side-effects-allowed-binary
- arithmetic-side-effects-allowed-unary
- avoid-breaking-exported-api
- msrv
- cognitive-complexity-threshold
- disallowed-names
- doc-valid-idents
- too-many-arguments-threshold
- type-complexity-threshold
- single-char-binding-names-threshold
- too-large-for-stack
- enum-variant-name-threshold
- enum-variant-size-threshold
- verbose-bit-mask-threshold
- literal-representation-threshold
- trivial-copy-size-limit
- pass-by-value-size-limit
- too-many-lines-threshold
- array-size-threshold
- vec-box-size-threshold
- max-trait-bounds
- max-struct-bools
- max-fn-params-bools
- warn-on-all-wildcard-imports
- disallowed-macros
- disallowed-methods
- disallowed-types
- unreadable-literal-lint-fractions
- upper-case-acronyms-aggressive
- matches-for-let-else
- cargo-ignore-publish
- standard-macro-braces
- enforced-import-renames
- allowed-scripts
- enable-raw-pointer-heuristic-for-send
- max-suggested-slice-pattern-length
- await-holding-invalid-types
- max-include-file-size
- allow-expect-in-tests
- allow-unwrap-in-tests
- allow-dbg-in-tests
- allow-print-in-tests
- large-error-threshold
- ignore-interior-mutability
- allow-mixed-uninlined-format-args
- suppress-restriction-lint-in-const
- missing-docs-in-crate-items