Skip to main content
The 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:
  1. Contains no leading or trailing whitespace (auto-fixable).
  2. Uses absolute URLs, not relative paths.
  3. Uses only allowed protocols: http://, https://, or data:.
  4. Points to a valid image file type: .jpg, .jpeg, .png, .gif, .svg, .webp.
Dynamic values, such as variables, are not validated by this rule.

Examples

Whitespace in URLs

Invalid: extra space around the URL.
This can be fixed manually or by running the npx eslint —fix command.

Relative paths

Invalid: relative URL path:
Instead use absolute URLs with supported protocols:

Invalid protocols

Invalid: unsupported image URL protocol:
Use http://, https://, or data: protocol instead:

Invalid file types

Invalid: unsupported file type:
Use supported image formats instead (.jpg, .jpeg, .png, .gif, .svg, .webp):

Dynamic values

Dynamic values are not validated by this rule:
Last modified on March 29, 2026