Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions scripts/snippets/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations

from pathlib import Path

from .model import Diagnostic, LocalSourcePolicyIssue

LOCAL_SOURCE_REMEDIATION = (
"Run `npm run snippets:resolve-local -- --page <page.source.mdx>` before pushing."
)


def local_source_policy_diagnostic(
path: Path, issue: LocalSourcePolicyIssue
) -> Diagnostic:
"""Add committed-page remediation to a local-ref policy failure."""

return Diagnostic(
path=path,
span=issue.span,
code="SNIP007",
message=issue.message,
remediation=LOCAL_SOURCE_REMEDIATION,
)
26 changes: 26 additions & 0 deletions tests/test_local_snippet_source_remediation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import annotations

from pathlib import Path

from scripts.snippets.diagnostics import local_source_policy_diagnostic
from scripts.snippets.model import LocalSourcePolicyIssue, Span


def test_reports_resolve_local_command_at_source_location() -> None:
diagnostic = local_source_policy_diagnostic(
Path("docs-main/validator.source.mdx"),
LocalSourcePolicyIssue(
span=Span(start=20, end=30, line=7, column=3),
message=(
"Local snippet references are preview-only and cannot be committed"
),
),
)

assert diagnostic.code == "SNIP007"
assert diagnostic.span.line == 7
assert diagnostic.span.column == 3
assert diagnostic.remediation == (
"Run `npm run snippets:resolve-local -- --page <page.source.mdx>` "
"before pushing."
)