lint-docstrings
Review and fix docstrings to follow Google-style conventions. Use when asked to check docstrings, format docstrings, or lint docstrings.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Docstring Linting
Review files for docstring compliance and fix any issues.
Instructions
- Find the target files (specified by user, or recently modified files)
- Check each public function, class, and method for proper docstrings
- Report issues and fix them
Google-Style Docstring Format
Functions
def calculate_percentile(value: float, distribution: list[float]) -> int:
"""Calculate the percentile rank of a value within a distribution.
Args:
value: The value to rank.
distribution: Sorted list of values forming the reference distribution.
Returns:
Percentile rank from 0-100.
Raises:
ValueError: If distribution is empty.
"""
Rules:
- First line: imperative summary ending with period
- Blank line before Args/Returns/Raises sections
- Args: one line per param, name followed by colon and description
- Returns: describe the return value (omit if None)
- Raises: list exceptions that may be raised
Classes
class PlayerMetrics:
"""Container for computed player statistics.
Holds percentile rankings and z-scores for a player across
multiple statistical categories.
Attributes:
player_id: Unique identifier for the player.
percentiles: Dict mapping metric names to percentile values.
computed_at: Timestamp when metrics were calculated.
"""
Simple Functions (no args)
def get_current_timestamp() -> datetime:
"""Return the current UTC timestamp."""
One-liner docstrings: opening and closing quotes on same line.
Test Docstring Format
Tests use a custom format with Fixtures, Scenario, and Expected sections:
def test_player_slug_generation(db_session):
"""Slug is generated from player name on create.
Fixtures:
db_session: Clean database session.
Scenario:
Create player with name "LeBron James".
Expected:
Player.slug equals "lebron-james".
"""
def test_percentile_edge_case_empty_distribution():
"""Percentile calculation handles empty distribution.
Scenario:
Call calculate_percentile with empty list.
Expected:
Raises ValueError with message about empty distribution.
"""
Rules for tests:
- First line: concise description of what's being tested
- Fixtures: list test fixtures/dependencies used (if any)
- Scenario: describe the setup and action
- Expected: describe the expected outcome
Checklist
When reviewing, check:
- All public functions have docstrings
- First line is imperative mood ("Return", "Calculate", not "Returns", "Calculates")
- First line ends with period
- Args section documents all parameters
- Returns section present (unless function returns None)
- One-liners fit on single line with quotes
- Test docstrings follow Fixtures/Scenario/Expected format
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-03-03
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!