Skip to content

feat: add DOCSTRING_HEDGE_WORD rule to check for slop in docstrings#4

Open
amaurigmartins wants to merge 1 commit into
mmartoccia:mainfrom
amaurigmartins:docstring-hedge-word-check
Open

feat: add DOCSTRING_HEDGE_WORD rule to check for slop in docstrings#4
amaurigmartins wants to merge 1 commit into
mmartoccia:mainfrom
amaurigmartins:docstring-hedge-word-check

Conversation

@amaurigmartins
Copy link
Copy Markdown

Summary

This is my poor man's attempt to push back on AI slop based on some recent experiments of my own.

This PR adds an opt-in Python docstring hedge-word check while keeping the existing Markdown hedge-word rule unchanged.

HEDGE_WORD continues to control Markdown prose. A new rule, DOCSTRING_HEDGE_WORD, controls Python module, class, function, and async function docstrings. Both rules read from the same [grain.markdown].hedge_words list, so projects maintain one shared policy vocabulary while deciding independently where it applies.

Why

Previously, Grain could flag hedge words in Markdown, but Python docstrings were not covered by the same policy. That made it easy for AI-generated bullshit to remain in API documentation embedded in code.

A specific DOCSTRING_HEDGE_WORD is introduced so Markdown and Python can be configured independently, while preserving the shared hedge-word list. The --fix semantics is retained, i.e. it will remove garbage filler both from docstrings and MD files.

Changes

  • Added DocstringHedgeWord in grain/checks/python_checks.py.
  • Registered it as an opt-in Python check under OPT_IN_PYTHON_CHECKS.
  • Kept Markdown HEDGE_WORD and Python DOCSTRING_HEDGE_WORD independently configurable via fail_on, warn_only, and ignore.
  • Reused [grain.markdown].hedge_words for both checks.
  • Kept --fix support for both HEDGE_WORD and DOCSTRING_HEDGE_WORD.
  • Updated docs to describe DOCSTRING_HEDGE_WORD as opt-in.
  • Added tests covering:
    • module, class, function, and async function docstrings
    • markdown-only configuration
    • docstring-only configuration
    • mixed fail/warn severities
    • ordinary Python string literals and comments not being scanned

Testing

  • python -m grain check on modified Python files: passed with no violations.
  • Reproduction smoke tests for markdown-only, docstring-only, and mixed severity configs: passed.
  • Direct no-fixture test harness: passed 108 tests.
  • Tested the forked implementation in an unrelated project, seems consistent.

AI slop is the first sign of Skynet emergence. It will rot our codes and corrupt our brains. Fight back, brother!

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.

1 participant