Skip to content

fix: compare inline image alt text and URLs in no-duplicate-headings - #769

Open
lumirlumir wants to merge 1 commit into
mainfrom
fix/compare-inline-image-alt-text-and-urls-in-no-duplicate-headings
Open

lumirlumir wants to merge 1 commit into
mainfrom
fix/compare-inline-image-alt-text-and-urls-in-no-duplicate-headings

Conversation

@lumirlumir

@lumirlumir lumirlumir commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Prerequisites checklist

AI acknowledgment

Check all that apply.

  • I did not use AI to generate this PR.
  • I used AI to write or edit the description of this PR (including translation).
  • I used AI to understand the codebase.
  • I used AI to write or edit the files in this PR and I reviewed the files.

What is the purpose of this pull request?

Which language are you using?

commonmark/gfm

What did you do?

<!-- eslint markdown/no-duplicate-headings: "error" -->

# ![Sun](a.png)
# ![Moon](a.png)
# ![Sun](b.png)
# ![Sun](a.png)

What did you expect to happen?

Only line 6 should report Duplicate heading "Sun" found. because its alt text and URL match line 3.

What actually happened?

4:1  error  Duplicate heading "" found.  markdown/no-duplicate-headings
5:1  error  Duplicate heading "" found.  markdown/no-duplicate-headings
6:1  error  Duplicate heading "" found.  markdown/no-duplicate-headings

What changes did you make? (Give an overview)

This PR fixes an issue where image alt text and URLs are not recognized as part of a heading sequence, causing headings to be incorrectly reported as duplicates.

I've updated the logic to correctly recognize alt text and URL sequences.

Related Issues

N/A

Is there anything you'd like reviewers to focus on?

There's also an issue with the ImageReference node. That said, fixing it would require more extensive changes to the logic, so I'll address it in a follow-up PR after this one is merged.

Summary by CodeRabbit

  • Bug Fixes
    • Duplicate-heading checks now distinguish image headings when their alternative text or destination differs.
    • Identical image headings are now reported as duplicates, including those with empty alternative text or destinations.
    • HTML content still affects duplicate comparisons but is no longer included in the reported heading text.

@eslintbot eslintbot added this to Triage Nov 25, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Nov 25, 2026
@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage Nov 25, 2026
@lumirlumir lumirlumir moved this from Implementing to Needs Triage in Triage Nov 25, 2026
@lumirlumir
lumirlumir marked this pull request as ready for review November 25, 2026 08:03
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The duplicate-heading rule now compares image alt text and destinations, and uses image alt text as reported heading text. Tests cover duplicate and non-duplicate image headings, including empty alt text and destinations.

Changes: Duplicate heading comparison

Layer / File(s) Summary
Update heading comparison and coverage
src/rules/no-duplicate-headings.js, tests/rules/no-duplicate-headings.test.js
The visitor uses length-prefixed child values for comparison. Image comparisons include alt text and destination, while reported heading text uses the alt text. Tests cover matching and differing image values, including empty values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: nzakas

Merge Risk: Minimal · up to e8c69

Headings with inline images are now compared by alt text and URL, so images that differ are no longer flagged as duplicates. No concrete merge-blocking risk was found. The ImageReference case stays out of scope and is planned for a follow-up PR.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the no-duplicate-headings rule now compares inline image alt text and URLs. The raw summary confirms the visitor change that builds comparison values from image alt te…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the no-duplicate-headings rule now compares inline image alt text and URLs. The raw summary confirms the visitor change that builds comparison values from image alt text and URL. The title is specific and matches the objectives of PR #769, which prevents headings with differing images from being flagged as duplicates. The title's 'fix:' prefix is a conventional commit type and does not affect the assessment.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 26b5bdf8-863c-40b0-9a1a-7f23400ea31a
Commits

Reviewing files that changed from the base of the PR and between e3ce918 and e8c6935.

Files selected for processing: 2

  • src/rules/no-duplicate-headings.js
  • tests/rules/no-duplicate-headings.test.js

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@hoanle0126 hoanle0126 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checked the rule changes and test cases here. Length-prefixing both the serialized value and alt/url avoids delimiter collisions cleanly, even with crafted text containing brackets or commas, while keeping alt as the reported heading text. Leaving ImageReference for a follow-up makes sense to keep this fix small.

@DMartens

Copy link
Copy Markdown
Contributor

Changes LGTM, thanks. Leaving open for another day for others to review.

@DMartens DMartens moved this from Needs Triage to Merge Candidates in Triage Nov 25, 2026

@Pixel998 Pixel998 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

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

Projects

Status: Merge Candidates

Development

Successfully merging this pull request may close these issues.

4 participants