Skip to content

Use ruff format for Markdown when format_tool=ruff#42

Merged
tsvikas merged 1 commit into
mainfrom
feat/ruff-format-markdown
May 25, 2026
Merged

Use ruff format for Markdown when format_tool=ruff#42
tsvikas merged 1 commit into
mainfrom
feat/ruff-format-markdown

Conversation

@tsvikas
Copy link
Copy Markdown
Owner

@tsvikas tsvikas commented May 25, 2026

Summary

  • When the ruff formatter is selected, drop blacken-docs entirely and use ruff format (preview) to format Python code blocks inside Markdown files. Feature added in ruff 0.15.0.
  • The Black variant keeps using blacken-docs.

Changes

  • project_name/pyproject.toml.jinja: enable [tool.ruff.format].preview = true and [tool.ruff].extend-include = ["*.md"] so ruff format discovers and formats Markdown files; drop black from dev deps when not using Black.
  • project_name/.pre-commit-config.yaml.jinja: drop the blacken-docs and black-pre-commit-mirror hooks for the ruff variant; add types_or: [python, pyi, jupyter, markdown] to ruff-format.
  • project_name/justfile.jinja: drop blacken-docs from the format recipe and _sync-blacken-docs from deps-update for the ruff variant; gate the _sync-blacken-docs recipe behind format_tool == "black".
  • ctt.toml: ignore PC111 (sp-repo-review requirement to use blacken-docs) since ruff format replaces it for the ruff variant.
  • README.md, CONTRIBUTING.md.jinja: document the new behavior.

Test plan

  • CI passes for both Black and Ruff variants in ctt
  • ruff format reformats Python code blocks inside *.md files in the ruff variant
  • ruff check skips *.md files (lint not affected)
  • blacken-docs still present and runs for the Black variant

When the ruff formatter is selected, drop blacken-docs entirely and let
ruff format handle Python code blocks in Markdown files (preview feature
added in ruff 0.15.0). The black variant keeps using blacken-docs.

- pyproject.toml: enable [tool.ruff.format].preview and extend-include
  for *.md so ruff format discovers Markdown files
- pre-commit: drop blacken-docs and black-pre-commit-mirror hooks;
  add types_or with markdown to ruff-format
- justfile: drop blacken-docs steps from format and deps-update
- ctt: ignore PC111 (repo-review requirement to use blacken-docs)
- drop black from dev deps when not using black
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


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.

@tsvikas tsvikas merged commit 1f888f1 into main May 25, 2026
5 checks passed
@tsvikas tsvikas deleted the feat/ruff-format-markdown branch May 25, 2026 22:05
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