3个版本
0.1.4 | 2024年6月30日 |
---|---|
0.1.3 | 2024年6月29日 |
0.1.2 | 2024年6月29日 |
#474 in 开发工具
每月80次下载
20KB
381 代码行
swiftlint-autodetect
Python脚本来自动检测一组Swiftlint规则。
安装
通过homebrew
brew tap schwa/schwa
brew install swiftlint-autodetect
或直接通过cargo
cargo install --git https://github.com/schwa/swiftlint-autodetect
用法
Casey Liss在这里详细介绍了如何使用swiftlint-autodetect:https://www.caseyliss.com/2021/12/29/swiftlint-autodetect。这篇文档基于工具的早期Python版本,但用法类似。
# Count the number of violations of _all_ SwiftLint rules in the given directory
$ swiftlint-autodetect count
# Output a SwiftLint configuration that disables all rules that are violated in the given directory.
$ swiftlint-autodetect generate --count
# Save a SwiftLint configuration that disables all rules that are violated in the given directory.
$ swiftlint-autodetect generate --count --output .swiftlint.yml
帮助
$ swiftlint-autodetect generate --help
Generate a SwiftLint configuration, by disabling rules with a minimum number of violations
Usage: swiftlint-autodetect generate [OPTIONS] [PATH]
Arguments:
[PATH] Path to the project [default: .]
Options:
-c, --counts
Include violation counts in the generated configuration
-o, --output <OUTPUT>
Output path for the generated configuration
-m, --minimum-violations <MINIMUM_VIOLATIONS>
Minimum number of violations required to disable a rule [default: 1]
-i, --ignore-fixable
Don't disable fixable rules
-h, --help
Print help
统计违规
要显示规则列表以及每个规则的违规次数,请使用count
子命令。
此子命令还会突出显示可以与swiftlint --fix
一起修复的规则。
$ swiftlint-autodetect count ~/Projects/Demos
explicit_acl: 2182
explicit_type_interface: 1669
identifier_name: 622
missing_docs: 409
type_contents_order: 335
explicit_top_level_acl: 321
implicit_return (*): 306
let_var_whitespace: 295
line_length: 294
force_unwrapping: 260
vertical_whitespace_between_cases (*): 167
nesting: 165
orphaned_doc_comment: 140
file_types_order: 140
indentation_width: 134
required_deinit: 117
trailing_comma (*): 106
todo: 106
配置
将文件保存到~/.config/swiftlint-autodetect/config.toml
。当前支持的键是'always_disabled_rules',用于指定始终禁用的规则,例如。
always_disabled_rules = ["yoda_condition"]
工作原理
swiftlint-autodetect查询swiftlint以获取规则列表,并创建一个临时swiftlint配置文件以启用所有这些规则。然后它对指定路径的源代码执行代码检查操作,并找出哪些规则会被违反。然后输出一个禁用违规规则的配置。
依赖关系
~9–23MB
~306K SLoC