Skip to content

feat(check-docstrings): short description up to blank line, add max l… - #20

Merged
ternaus merged 2 commits into
mainfrom
feat/short-description-paragraph-and-max-length
Mar 16, 2026
Merged

ternaus merged 2 commits into
mainfrom
feat/short-description-paragraph-and-max-length

Conversation

@ternaus

@ternaus ternaus commented Mar 16, 2026 •

Copy link
Copy Markdown
Owner

…ength

  • Short description = first paragraph (up to first blank line), not first line
  • Multi-line first paragraph joined with spaces for meta description use
  • Add max_short_description_length (0 to disable, 160 recommended for SEO)
  • Add _extract_short_description helper, extensive parametrized tests
  • Update README, tools/README, google-docstring-format and python-pre-commit skills
  • Bump version to 0.0.11

Made-with: Cursor

Summary by Sourcery

Introduce configurable short description extraction and length validation for docstring checking.

New Features:

  • Extract the short description as the first paragraph of the docstring (up to the first blank line), normalizing whitespace for meta-description use.
  • Add support for a configurable maximum short description length alongside the existing minimum length, controllable via CLI flags and pyproject.toml config.

Enhancements:

  • Propagate short description length configuration through the docstring checker pipeline, including verbose output, directory scanning, and file-level checks.
  • Document short description behavior, SEO-oriented length recommendations, and configuration options in the main README, tools README, and Cursor skills docs.
  • Expand tests with unit and integration coverage for short description extraction and min/max length validation behavior.

Build:

  • Bump package version from 0.0.10 to 0.0.11.

…ength

- Short description = first paragraph (up to first blank line), not first line
- Multi-line first paragraph joined with spaces for meta description use
- Add max_short_description_length (0 to disable, 160 recommended for SEO)
- Add _extract_short_description helper, extensive parametrized tests
- Update README, tools/README, google-docstring-format and python-pre-commit skills
- Bump version to 0.0.11

Made-with: Cursor
@ternaus
ternaus requested a review from Copilot March 16, 2026 04:24
@sourcery-ai

sourcery-ai Bot commented Mar 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implements configurable short-description handling for docstring checking: short description is now defined as the first paragraph (up to a blank line), supports an optional maximum length, wires both min/max length through CLI, config, and core checking pipeline, and updates documentation, skills, and tests accordingly.

Sequence diagram for docstring short description length validation

sequenceDiagram
    actor User
    participant CLI as check_docstrings_CLI
    participant Main as main
    participant Cfg as _get_config_values
    participant Paths as _process_paths
    participant Scan as scan_directory
    participant File as check_file
    participant Proc as _process_docstring
    participant AddVal as _check_additional_validations
    participant LenChk as check_short_description_length
    participant Extract as _extract_short_description

    User->>CLI: Invoke with paths and options
    CLI->>Main: Parse args with argparse

    Main->>Cfg: _get_config_values(args, config)
    Cfg-->>Main: paths, flags, min_short_description_length, max_short_description_length

    Main->>Paths: _process_paths(paths, flags, min_short_description_length, max_short_description_length)

    alt Path is directory
        Paths->>Scan: scan_directory(path, flags, min_short_description_length, max_short_description_length)
        Scan->>File: check_file(file, flags, min_short_description_length, max_short_description_length)
    else Path is single file
        Paths->>File: check_file(path, flags, min_short_description_length, max_short_description_length)
    end

    loop For each docstring in file
        File->>Proc: _process_docstring(DocstringContext(...))
        Proc->>AddVal: _check_additional_validations(context, parsed_docstring)

        alt Min or max short description length enabled
            AddVal->>LenChk: check_short_description_length(parsed_docstring,
            AddVal->>LenChk: min_short_description_length,
            AddVal->>LenChk: max_short_description_length)
            LenChk->>Extract: _extract_short_description(description)
            Extract-->>LenChk: short_desc
            LenChk-->>AddVal: errors for too short or too long
            AddVal-->>Proc: errors
        else No short description length checks
            AddVal-->>Proc: no length errors
        end
    end

    Paths-->>Main: Aggregate all_errors
    Main-->>User: Print errors and exit status
Loading

Class diagram for DocstringContext and short description helpers

classDiagram
    class DocstringContext {
        +str filepath
        +str name
        +bool require_param_types
        +bool check_references
        +bool check_type_consistency
        +int min_short_description_length
        +int max_short_description_length
        +ast_AST node
    }

    class main {
        +main() void
    }

    class _get_config_values {
        +_get_config_values(args, config) tuple
    }

    class _process_paths {
        +_process_paths(paths, require_param_types, check_references, check_type_consistency, min_short_description_length, max_short_description_length) list~str~
    }

    class scan_directory {
        +scan_directory(directory, require_param_types, check_references, check_type_consistency, min_short_description_length, max_short_description_length) list~str~
    }

    class check_file {
        +check_file(filepath, require_param_types, check_references, check_type_consistency, min_short_description_length, max_short_description_length) list~str~
    }

    class _process_docstring {
        +_process_docstring(context, docstring) list~str~
    }

    class _check_additional_validations {
        +_check_additional_validations(context, parsed) list~str~
    }

    class check_short_description_length {
        +check_short_description_length(parsed, min_length, max_length) list~str~
    }

    class _extract_short_description {
        +_extract_short_description(description) str
    }

    main --> _get_config_values : calls
    main --> _process_paths : calls

    _get_config_values ..> DocstringContext : provides config values

    _process_paths --> scan_directory : calls
    _process_paths --> check_file : calls

    scan_directory --> check_file : calls

    check_file ..> DocstringContext : constructs
    check_file --> _process_docstring : calls

    _process_docstring --> _check_additional_validations : calls

    _check_additional_validations --> check_short_description_length : calls

    check_short_description_length --> _extract_short_description : calls
Loading

Flow diagram for resolving min and max short description length configuration

flowchart TD
    A[Start] --> B[Read pyproject config for docstring_checker]
    B --> C[Parse CLI args with argparse]

    C --> D[Set min_short_description_length = config.min_short_description_length or 0]
    D --> E{CLI provides --min-short-description-length?}
    E -- Yes --> F[Override min_short_description_length with CLI value]
    E -- No --> G[Keep config-derived min_short_description_length]

    C --> H[Set max_short_description_length = config.max_short_description_length or 0]
    H --> I{CLI provides --max-short-description-length?}
    I -- Yes --> J[Override max_short_description_length with CLI value]
    I -- No --> K[Keep config-derived max_short_description_length]

    F --> L[Return min_short_description_length]
    G --> L
    J --> M[Return max_short_description_length]
    K --> M

    L --> N[Pass min_short_description_length into _process_paths]
    M --> N

    N --> O[Propagate min and max lengths into scan_directory and check_file]
    O --> P[Create DocstringContext with min and max lengths]
    P --> Q[_check_additional_validations uses lengths in check_short_description_length]
    Q --> R[End]
Loading

File-Level Changes

Change Details Files
Redefine and centralize short-description extraction as first paragraph and add max-length validation.
  • Introduce _extract_short_description to normalize the first paragraph (up to first blank line) into a single-line short description.
  • Update check_short_description_length to use the extracted paragraph, support both minimum and maximum length thresholds, and return combined errors.
  • Gate short-description checks on either min or max threshold being non-zero in _check_additional_validations.
tools/check_docstrings.py
tests/test_docstring_checker/test_check_docstrings.py
Plumb max_short_description_length through configuration, CLI, and checking pipeline.
  • Add max_short_description_length to default config, DocstringContext, and CONFIG_KEY_TYPES mapping.
  • Expose --max-short-description-length CLI argument and thread it through _get_config_values, _process_paths, check_file, and scan_directory.
  • Include max_short_description_length in verbose output and in the safe_execute call for short description checks.
tools/check_docstrings.py
Expand tests to cover new short-description semantics and CLI behavior.
  • Add parametrized tests for _extract_short_description covering whitespace, multi-line paragraphs, and empty cases.
  • Extend test_check_short_description_length to accept max_length and validate too-long as well as too-short cases, including paragraph-based extraction.
  • Add an integration-style test that runs tools.check_docstrings via subprocess with various min/max combinations and asserts on return codes and messages.
  • Adjust existing config-from-pyproject test to assert max short description length is printed.
tests/test_docstring_checker/test_check_docstrings.py
Update documentation and skills to describe short-description semantics and new configuration.
  • Document short description behavior, SEO-oriented length guidance, and min/max settings in README and tools/README.
  • Update google-docstring-format SKILL to show min/max_short_description_length usage and add corresponding error message descriptions.
  • Clarify python-pre-commit SKILL to mention docstring checker options including min/max_short_description_length.
README.md
tools/README.md
.cursor/skills/google-docstring-format/SKILL.md
.cursor/skills/python-pre-commit/SKILL.md
Bump package version for the new behavior.
  • Increment project version from 0.0.10 to 0.0.11 in pyproject.toml.
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In test_check_short_description_length, the isinstance(parsed, str) branch and accompanying comment appear unused now that all parametrized parsed values are dicts; consider removing this dead code for clarity.
  • In _extract_short_description, consider documenting the behavior for leading/trailing blank lines (e.g., that leading blank lines are stripped before paragraph detection) directly in the docstring to make the regex-based splitting easier to understand for future maintainers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `test_check_short_description_length`, the `isinstance(parsed, str)` branch and accompanying comment appear unused now that all parametrized `parsed` values are dicts; consider removing this dead code for clarity.
- In `_extract_short_description`, consider documenting the behavior for leading/trailing blank lines (e.g., that leading blank lines are stripped before paragraph detection) directly in the docstring to make the regex-based splitting easier to understand for future maintainers.

## Individual Comments

### Comment 1
<location path="tests/test_docstring_checker/test_check_docstrings.py" line_range="671" />
<code_context>
+            0,
+            [],
+        ),
+        # Max length
+        (
+            {"Description": "A" * 161},
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding a max-length test case where the first paragraph is multi-line and joined with spaces

The current max-length tests only cover a single-line description of repeated "A" characters, so they don’t verify how `_extract_short_description` handles multi-line first paragraphs. To cover the new behavior, consider adding a case where the first paragraph spans multiple lines and is joined with spaces before the length check, e.g.:

```python
(
    {"Description": "Line one with some text.\nAnd another line that pushes length over max.\n\nNext paragraph."},
    0,
    80,
    ["Short description too long ..."],
),
```

Suggested implementation:

```python
        # First paragraph = up to blank line (multi-line)
        (
            {"Description": "First line. More.\nSecond line of para.\n\nSecond para."},
            0,
            0,
            [],
        ),
        # Max length with multi-line first paragraph (joined with spaces)
        (
            {
                "Description": (
                    "Line one with some text.\n"
                    "And another line that pushes length over max.\n\n"
                    "Next paragraph."
                )
            },
            0,
            80,
            [
                "Short description too long (93 chars, max 80): "
                "'Line one with some text. And another line that pushes length over max.'"
            ],
        ),
        # Max length (single-line)
        (
            {"Description": "A" * 161},
            0,
            160,
            ["Short description too long (161 chars, max 160): 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...'"],
        ),

```

Depending on the exact implementation of `_extract_short_description` and the error formatting logic, you may need to:
1. Adjust the expected length value `93` if your join/strip logic counts characters differently (e.g., handling of trailing spaces).
2. Update the expected preview string if your error message truncates the description differently (for example, limiting to a fixed prefix length and appending `...`).
3. If your checker normalizes whitespace more aggressively (e.g. collapsing multiple spaces or stripping punctuation), mirror that behavior in the expected string so the test aligns with the actual output.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/test_docstring_checker/test_check_docstrings.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the docstring checker to treat the “short description” as the first paragraph (up to the first blank line), normalizes multi-line paragraphs into a single line for meta-description use, and adds an optional maximum-length constraint.

Changes:

  • Add _extract_short_description() and update short-description length validation to support both min and max bounds.
  • Wire max_short_description_length through config, CLI, runtime context, and verbose output.
  • Add/extend parametrized and integration tests; update documentation and bump version to 0.0.11.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tools/check_docstrings.py Implements paragraph-based short description extraction and adds max length enforcement + CLI/config plumbing.
tests/test_docstring_checker/test_check_docstrings.py Adds unit tests for extraction/length checks and integration coverage for CLI behavior.
tools/README.md Documents new short-description semantics and max_short_description_length option.
README.md Adds user-facing explanation of short description usage for meta descriptions and config knobs.
pyproject.toml Bumps project version to 0.0.11.
.cursor/skills/python-pre-commit/SKILL.md Notes docstring checker config now includes min/max short description length.
.cursor/skills/google-docstring-format/SKILL.md Documents short-description guidance and references new error cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_docstring_checker/test_check_docstrings.py Outdated
…add multi-line max test

- Remove unused isinstance(parsed, str) branch in test_check_short_description_length
- Document leading/trailing blank line behavior in _extract_short_description
- Add max-length test for multi-line first paragraph (joined with spaces)

Made-with: Cursor

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the docstring checker to treat the “short description” as the first paragraph (up to the first blank line), and adds an optional maximum length constraint to complement the existing minimum-length check.

Changes:

  • Implement _extract_short_description() (first paragraph extraction + whitespace normalization) and update length validation to support both min/max bounds.
  • Thread max_short_description_length through config defaults, CLI flags, and the checker pipeline (file/directory scanning + verbose config output).
  • Expand unit + integration tests and update documentation/examples; bump package version to 0.0.11.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/check_docstrings.py Adds paragraph-based short description extraction and min/max length checks; wires new config/CLI through execution flow.
tests/test_docstring_checker/test_check_docstrings.py Adds focused unit tests for extraction plus min/max validation and end-to-end CLI integration coverage.
tools/README.md Documents new short description semantics and max_short_description_length config/CLI usage.
README.md Adds a dedicated “Short Description” section and updates example configuration to include min/max bounds.
pyproject.toml Bumps project version to 0.0.11.
.cursor/skills/python-pre-commit/SKILL.md Notes docstring checker supports min/max short description config.
.cursor/skills/google-docstring-format/SKILL.md Documents short description paragraph rule and the min/max length knobs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ternaus
ternaus merged commit 14be47c into main Mar 16, 2026
24 checks passed
@ternaus
ternaus deleted the feat/short-description-paragraph-and-max-length branch March 16, 2026 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants