astral-sh/ruff · error

The `{SECTION_CONFIG_SNAPSHOT}` directive does not take a va

Error message

The `{SECTION_CONFIG_SNAPSHOT}` directive does not take a value.

What it means

In mdtest files, `<!-- snapshot-diagnostics -->` is a valueless section directive: the parser splits the HTML comment on ':' and rejects the directive when a value was supplied. It is an authoring error in the test markdown, not a behavior of the code under test.

Source

Thrown at crates/mdtest/src/parser.rs:615

        const HTML_COMMENT_END: &[u8] = b"-->";

        while let Some(first) = self.cursor.bump() {
            match first {
                '<' if self.cursor.eat_char3('!', '-', '-') => {
                    if let Some(position) =
                        memchr::memmem::find(self.cursor.as_bytes(), HTML_COMMENT_END)
                    {
                        let html_comment = self.cursor.as_str()[..position].trim();
                        let (directive, value) = match html_comment.split_once(':') {
                            Some((directive, value)) => {
                                (directive.trim(), Some(value.trim().to_string()))
                            }
                            None => (html_comment, None),
                        };

                        match directive {
                            SECTION_CONFIG_SNAPSHOT => {
                                anyhow::ensure!(
                                    value.is_none(),
                                    "The `{SECTION_CONFIG_SNAPSHOT}` directive \
                                    does not take a value."
                                );
                                self.process_mdtest_directive(
                                    MdtestDirective::SnapshotDiagnostics,
                                    None,
                                )?;
                            }
                            SECTION_CONFIG_PULLTYPES => {
                                anyhow::ensure!(
                                    value.is_none(),
                                    "The `{SECTION_CONFIG_PULLTYPES}` directive \
                                    does not take a value."
                                );
                                self.process_mdtest_directive(
                                    MdtestDirective::PullTypesSkip,
                                    None,

View on GitHub (pinned to 672bb4edf0)

Solutions

  1. Remove the colon and value: use exactly `<!-- snapshot-diagnostics -->`
  2. Copy the directive syntax from a nearby passing mdtest file

Example fix

<!-- before -->
<!-- snapshot-diagnostics: on -->

<!-- after -->
<!-- snapshot-diagnostics -->
Defensive patterns

Strategy: validation

Validate before calling

# reject valued forms of the directive in CI
! grep -rnE 'snapshot-diagnostics[[:space:]]*:[[:space:]]*[^[:space:]]' \
  crates/ty_python_semantic/resources/mdtest/ || {
  echo 'snapshot-diagnostics takes no value' >&2; exit 1;
}

Prevention

When it happens

Trigger: Writing `<!-- snapshot-diagnostics: on -->` or any text after a colon in the HTML comment form of the directive.

Common situations: Copy-pasting from keyed directives of other tools; assuming all mdtest directives take values; converting inline comments to HTML comment form and keeping a value.

Related errors


AI-assisted analysis of astral-sh/ruff@672bb4edf0 (2026-08-16). Data as JSON: /api/errors/8d1f5eccc935c0de. Report an issue: GitHub.