Skip to content

Plugin Docs: Add asset validation rules#2507

Merged
sunker merged 7 commits intomainfrom
plugin-docs/asset-validation-rules
Mar 6, 2026
Merged

Plugin Docs: Add asset validation rules#2507
sunker merged 7 commits intomainfrom
plugin-docs/asset-validation-rules

Conversation

@sunker
Copy link
Contributor

@sunker sunker commented Mar 4, 2026

What this PR does / why we need it:

This PR adds 8 asset validation rules to the plugin-docs-cli validation engine. These rules enforce image hygiene in plugin documentation: images must live in img/ directories, use allowed formats (no SVG due to XSS risk), stay within size limits (300KB static, 1MB GIF, 5MB total) and use clean filenames. The rules also detect broken image references in markdown and flag orphaned images that are no longer used.

Severity depends on the validation mode. In strict mode (validate command), most rules are errors that block. In non-strict mode (serve command), they surface as info-level hints. Two rules - total image size and orphan detection - only run in strict mode.

The epic lists images-in-img-dir and no-images-outside-img as separate rows but notes they are the same enforcement from opposite directions. They are consolidated into one rule here.

Which issue(s) this PR fixes:

Part of #771

Special notes for your reviewer:

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged. It will not be considered when calculating future versions of the npm packages and will not appear in the changelogs.

@sunker sunker added the no-changelog Don't include in changelog and version calculations label Mar 4, 2026
@sunker sunker self-assigned this Mar 4, 2026
@grafana-plugins-platform-bot grafana-plugins-platform-bot bot moved this from 📬 Triage to 🔬 In review in Grafana Catalog Team Mar 4, 2026
@sunker sunker marked this pull request as ready for review March 4, 2026 09:14
@sunker sunker requested a review from a team as a code owner March 4, 2026 09:14
@sunker sunker requested review from Ukochka and Copilot March 4, 2026 09:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new asset-validation rule runner to @grafana/plugin-docs-cli to enforce image hygiene in plugin documentation (location under img/, allowed formats, size limits, filename rules, reference integrity, and orphan detection).

Changes:

  • Introduces 8 new asset-related rule IDs and wires a new checkAssets runner into the validation pipeline.
  • Shares allowed image extension configuration between filesystem and asset validation.
  • Adds a comprehensive Vitest suite for the new asset rules.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/plugin-docs-cli/src/validation/types.ts Adds new rule identifiers for asset validation.
packages/plugin-docs-cli/src/validation/rules/index.ts Registers the new checkAssets rule runner.
packages/plugin-docs-cli/src/validation/rules/filesystem.ts Refactors allowed image extensions into a shared constant.
packages/plugin-docs-cli/src/validation/rules/assets.ts Implements asset validation (formats, locations, sizes, refs, orphans).
packages/plugin-docs-cli/src/validation/rules/assets.test.ts Adds tests for the asset validation behavior.

@sunker sunker requested review from academo and mckn March 4, 2026 09:56
Copy link
Collaborator

@mckn mckn left a comment

Choose a reason for hiding this comment

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

LGTM! Should we add a test that verifies that you can't add image refs outside of the current root folder? So you can't reference files higher in the folder structure than the plugin docs.

Just make sure that we don't allow things such as ../../../etc/passwd

@sunker
Copy link
Contributor Author

sunker commented Mar 5, 2026

LGTM! Should we add a test that verifies that you can't add image refs outside of the current root folder? So you can't reference files higher in the folder structure than the plugin docs.

Good idea, added!

Just make sure that we don't allow things such as ../../../etc/passwd

yes - this will be covered in an upcoming PR for security related rules (see https://github.com/grafana/grafana-catalog-team/issues/769)

@sunker sunker requested review from academo and mckn March 5, 2026 11:09
@sunker sunker merged commit 6384f34 into main Mar 6, 2026
28 checks passed
@sunker sunker deleted the plugin-docs/asset-validation-rules branch March 6, 2026 06:26
@github-project-automation github-project-automation bot moved this from 🔬 In review to 🚀 Shipped in Grafana Catalog Team Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Don't include in changelog and version calculations

Projects

Status: 🚀 Shipped

Development

Successfully merging this pull request may close these issues.

4 participants