astral-sh / ruff-pre-commit

A pre-commit hook for Ruff.
Apache License 2.0
802 stars 38 forks source link

add ruff-docs #88

Open inktrap opened 1 month ago

inktrap commented 1 month ago

Summary

Since ruff can fix docs(trings) it can replace something like blacken-docs too, that way everything is consistent.

Test Plan

I forked the repo, added the new hook-id, recreated the current release-tag and used it in a dedicated repo in a pre-commit file and it worked.

inktrap commented 1 month ago

I realized that you can achieve the same thing in one run with the default format action:

    - repo: https://github.com/astral-sh/ruff-pre-commit
      rev: v0.4.5
      hooks:
          - id: ruff
            types_or: [python, pyi, jupyter]
            args: [--fix, --exit-non-zero-on-fix]
          - id: ruff-format
            args: [--config, format.docstring-code-format=true, --config, format.docstring-code-line-length=72]
            types_or: [python, pyi, jupyter, markdown, rst]

However in that case I think it is useful to include it as an example to highlight that possibility.

Especially because it is not immediately clear that you can format docs with the docstring option, but it is a good name (i read the discussion about variable naming). And it is all documented anyways.

charliermarsh commented 1 month ago

I don't believe docstring formatting currently works on Markdown and rST files though. It supports Markdown and rST within Python docstrings, but not Python code within Markdown or rST files. Am I mistaken?