mcore-linting-and-formatting
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLinting and Formatting
代码检查与格式化
Running the Formatter
运行格式化工具
Run before opening a PR:
bash
undefined在提交PR前运行以下命令:
bash
undefinedCheck mode (no changes applied)
检查模式(不应用任何修改)
BASE_REF=main CHECK_ONLY=true SKIP_DOCS=false bash tools/autoformat.sh
BASE_REF=main CHECK_ONLY=true SKIP_DOCS=false bash tools/autoformat.sh
Fix mode
修复模式
BASE_REF=main CHECK_ONLY=false bash tools/autoformat.sh
Tools invoked: `black`, `isort`, `pylint`, `ruff`, `mypy`.
---BASE_REF=main CHECK_ONLY=false bash tools/autoformat.sh
调用的工具:`black`, `isort`, `pylint`, `ruff`, `mypy`.
---Import Ordering
导入排序
After editing imports in any Python files, always run on those
files before committing:
uv run isortbash
uv run isort <file1>.py <file2>.py在编辑任何Python文件的导入语句后,提交前务必对这些文件运行:
uv run isortbash
uv run isort <file1>.py <file2>.pySetting Up the Linting Group
设置代码检查环境组
Inside the container:
bash
uv sync --locked --only-group lintingThis installs , , , — the same tools used by
and CI's job.
ruffblackisortpylinttools/autoformat.shlinting在容器内执行:
bash
uv sync --locked --only-group linting这会安装, , , —— 与及CI的任务使用的工具一致。
ruffblackisortpylinttools/autoformat.shlintingCode Style Rules
代码风格规则
- Type hints: required on all public API functions. Use , not
X | None.Optional[X] - Docstrings: Google-style on all public classes and functions.
- Naming: follow Python conventions — for functions and variables,
snake_casefor classes.PascalCase - Line length: 119 characters (configured in ).
pyproject.toml - No bare : always catch specific exception types.
except
- 类型提示:所有公共API函数必须添加类型提示。使用,而非
X | None。Optional[X] - 文档字符串:所有公共类和函数采用Google风格的文档字符串。
- 命名规范:遵循Python约定 —— 函数和变量使用,类使用
snake_case。PascalCase - 行长度:119个字符(在中配置)。
pyproject.toml - 禁止裸:始终捕获特定的异常类型。
except