Skip to content

fix(lint): treat Astro Image component like img in useAnchorContent#9270

Open
kbo4sho wants to merge 1 commit intobiomejs:mainfrom
kbo4sho:fix/use-anchor-content-astro-image
Open

fix(lint): treat Astro Image component like img in useAnchorContent#9270
kbo4sho wants to merge 1 commit intobiomejs:mainfrom
kbo4sho:fix/use-anchor-content-astro-image

Conversation

@kbo4sho
Copy link

@kbo4sho kbo4sho commented Feb 28, 2026

🤖 AI Disclosure: This PR was authored by an AI agent (OpenClaw) on behalf of @kbo4sho. Happy to address feedback.

Summary

Fixes #9210

The useAnchorContent rule was throwing a false positive when using Astro's built-in <Image> component inside anchor tags, even when the component had a valid alt attribute.

This PR adds recognition for the Astro Image component (from astro:assets) and treats it the same as the native <img> element - checking for the alt attribute as valid accessible content.

Changes

  • Updated the pattern match in has_accessible_content to recognize both img (case-insensitive) and Image (exact match for Astro component)
  • Added test case for <Image> component with alt attribute in valid.astro

Test Plan

Added a test case demonstrating that <a><Image src={profileImg} alt="profile picture" /></a> should be considered valid accessible content, just like <a><img alt="description" /></a>.

The fix is minimal and follows the existing pattern for other image-like elements in the codebase.

Resolves biomejs#9210

The useAnchorContent rule now recognizes Astro's built-in Image component
(from astro:assets) and treats it the same as the native img element,
checking for the alt attribute as valid accessible content.

This prevents false positives when using the Image component inside
anchor tags with proper alt text.
@changeset-bot
Copy link

changeset-bot bot commented Feb 28, 2026

⚠️ No Changeset found

Latest commit: 1b09d8c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added A-Linter Area: linter L-HTML Language: HTML and super languages labels Feb 28, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 412a08d and 1b09d8c.

📒 Files selected for processing (2)
  • crates/biome_html_analyze/src/lint/a11y/use_anchor_content.rs
  • crates/biome_html_analyze/tests/specs/a11y/useAnchorContent/astro/valid.astro

Walkthrough

The useAnchorContent linter rule now recognises the Astro Image component as having accessible content when it includes an alt attribute, treating it equivalently to standard HTML img elements. A single-line code modification extends the detection logic to check for "Image" (case-insensitive) tags alongside "img", with a corresponding test case validating the fix.

Possibly related PRs

Suggested labels

A-Linter, L-HTML

Suggested reviewers

  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: treating Astro's Image component like img in the useAnchorContent rule.
Description check ✅ Passed The description clearly explains the fix, references issue #9210, outlines the changes made, and includes test plan details.
Linked Issues check ✅ Passed The PR fully addresses issue #9210 by recognizing Astro's Image component and treating its alt attribute as valid accessible content, matching the desired behaviour.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the useAnchorContent rule for Astro Image components; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Changeset missing. Wrong implement. Not enough tests.


match tag_text.as_ref().map(|t| t.as_ref()) {
Some(name) if name.eq_ignore_ascii_case("img") => {
Some(name) if name.eq_ignore_ascii_case("img") || name == "Image" => {
Copy link
Member

Choose a reason for hiding this comment

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

That's wrong.

Your PR says it checks for the Astro Image component. This checks for EVERY component, without discrimination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-HTML Language: HTML and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 useAnchorContent false positive with Astro Image component

2 participants