feat: support embedded robot code in markdown and python files - #1932
Open
bhirsz wants to merge 1 commit into
Open
feat: support embedded robot code in markdown and python files#1932bhirsz wants to merge 1 commit into
bhirsz wants to merge 1 commit into
Conversation
Lint and format Robot Framework code embedded in fenced code blocks inside Markdown (.md, .markdown) and Python (.py) files. Each block is treated as an independent suite; physical line and column positions are preserved so diagnostics and fixes point at the right place, and the file's indentation and line endings are kept on write-back. Embedded files are opt-in: pass the file directly or add its extension to the include patterns. Adds acceptance tests and documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for linting and formatting Robot Framework code embedded in Markdown and Python files, mirroring the embedded execution support Robot Framework added in 7.5 (Robocop does its own parsing, so it works on any RF version).
Robot code is discovered in fenced code blocks tagged
```robotframework(or```robot):.md,.markdown) — blocks in prose..py) — the same blocks inside docstrings (as used for runnable library examples).A file may contain 0, 1, or many blocks. Each block is treated as an independent suite — linted and formatted on its own — while surrounding prose, fences, indentation and line endings are left untouched.
Behaviour
robocop format file.md) or by adding the extension to the include patterns (--include "*.md"/ configinclude).--fixre-indent each block to its original position and preserve the file's line endings; prose is untouched and formatting is idempotent.Implementation
src/robocop/embedded.py— line-based fence extractor and block model helpers.EmbeddedSourceFile(source_file.py) with abuild_source_filefactory used by config discovery.docs/user_guide/embedded_code.md.While implementing, a line-ending bug was found and fixed: formatted blocks were emitted with LF while surrounding prose kept CRLF — the file's line ending is now detected and reapplied.
Tests
New acceptance tests under
tests/embedded/cover extraction, linter line numbers / column offsets, formatter prose-preservation, Python docstring re-indentation, idempotency, and 0/1/many blocks.ruff check/ruff formatclean, mypy strict clean.Note
Because each block is an independent suite, suite-level rules (e.g. missing suite documentation) are reported once per block. This is the intended per-block semantics.