Files
tldr/pages.zh/common/ruff-check.md

33 lines
974 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ruff 检查
> 一个极快的 Python 代码检查工具。`check` 是默认命令 - 可以在任何地方省略。
> 如果没有指定文件或目录,则默认使用当前工作目录。
> 更多信息:<https://docs.astral.sh/ruff/linter>。
- 在指定的文件或目录上运行 linter
`ruff check {{path/to/file_or_directory1 path/to/file_or_directory2 ...}}`
- 应用建议的修复,直接修改文件:
`ruff check --fix`
- 运行 linter 并在更改时重新检查:
`ruff check --watch`
- 仅启用指定的规则(或所有规则),忽略配置文件:
`ruff check --select {{ALL|rule_code1,rule_code2,...}}`
- 另外启用指定的规则:
`ruff check --extend-select {{rule_code1,rule_code2,...}}`
- 禁用指定的规则:
`ruff check --ignore {{rule_code1,rule_code2,...}}`
- 通过在所有违反规则的行添加 `# noqa` 指令来忽略该规则所有现有的违规行为:
`ruff check --select {{rule_code}} --add-noqa`