Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pre-flight checklist
Motivation
This PR address the concerns brought up in issue #6472, and enforces the use of @theme/IdealImage component instead of
tags.
Following feedback from @slorber in previous discussions (#8826, #11416), this rule adopts a tiered approach to minimize false positives and noise:
src={require('./img.png')}. Since the asset is explicitly required, we are certain it is a local file that would benefit from the Ideal Image optimization pipeline../img.png) or root-relative paths (/img.png). This nudges the user to optimize if the file is indeed local.https://...) and protocol-relative links (//).src={props.src}orsrc={someVariable}) to avoid annoying users in generic components.IdealImagedoes not support vector formats, these are explicitly ignored to prevent useless warnings.Test Plan
I have implemented a comprehensive test suite in
prefer-ideal-image.test.tscovering the following:.svgfiles.<img>tags usingrequire(), relative strings, and manualsrcsetimplementations.Tested locally using
yarn jest packages/docusaurus-eslint-pluginwith all cases passing.Related issues/PRs