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.
This PR introduces a
docs snippets
command that statically extracts and lints all code snippets contained within docs to asnippets/
folder.Motivation
New Commands
docs snippets
will clean, export, and lint all code snippet filesdocs snippets clean
will clean all non-boilerplate files from the snippets directoriesdocs snippets export
will only extract code snippets from docs filesdocs snippets lint
will only lint code snippet files already exported to the snippets folderNew code block directives
export
To make this change opt-in, code blocks will only be exported into the snippets folder if it has an
export
attribute. For instance:ignore
This directive is only for rendering snippets in the final docs build, and is meant to be used in conjunction with
merge-before
to give additional scope to the snippetmerge-before
You can use this to merge code blocks together into one consistent snippet -- this is helpful for examples that span across multiple code snippets, but still should be treated as one consistent example when we go to export the snippet and lint.
When used with the
ignore
directive, you can pin additional scopes to the snippet without it being rendered in the final docs build. For instance:Structure change:
snippets/
This PR adds a top level
snippets/
directory that contains each language's boilerplate code for linting + formatting. Whendocs snippets
is run, all code snippets will be exported into each languages directory to be linted and formatted.Each language directory contains a Makefile that has a
lint
command that kicks off a linting command for all exported snippets. For python we run the same lint commands as we do in the root of the directory (with some special docs-only rules applied inpyproject.toml
, and in JS we run thelint
pnpm script which triggers an eslint run.Each snippet file that gets exported is intentionally not tracked -- we should only really need these snippet files for CI reasons (for now)
Test cases
(might be good as unit tests, but these are just one off checks I've done for now)
merge-before
directive are collapsed into one code snippetignore
directive are omitted from the final buildsnippets/
if it contains theexport
directive