no-invalid-image-src rule validates that the src attribute of <Image> components uses valid URLs. Some invalid code flagged by this rule is eligible for fixing via the --fix option provided by the ESLint CLI.
Rule details
HubSpot’s<Image> component has specific requirements for the src attribute when using string values. This rule enforces those requirements to ensure images load correctly at runtime.
The rule validates that the src attribute:
- Contains no leading or trailing whitespace (auto-fixable).
- Uses absolute URLs, not relative paths.
- Uses only allowed protocols:
http://,https://, ordata:. - Points to a valid image file type:
.jpg,.jpeg,.png,.gif,.svg,.webp.
Examples
Whitespace in URLs
Invalid: extra space around the URL.Relative paths
Invalid: relative URL path:Invalid protocols
Invalid: unsupported image URL protocol:http://, https://, or data: protocol instead:
Invalid file types
Invalid: unsupported file type:.jpg, .jpeg, .png, .gif, .svg, .webp):