diff --git a/CHANGELOG.md b/CHANGELOG.md index 05d4d45..f06b16d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.0.21 +Fixes `req-webp-in-picture` to not check `` if all `` have attribute `type="image/svg+xml"`. + ## 1.0.20 - Adds a `req-tags-presence` rule that requires the specified tags on the page. - Adds a `req-preload-font` rule that requires the `preload` value for the font. diff --git a/rules/req-webp-in-picture/README.md b/rules/req-webp-in-picture/README.md index c603992..521bdeb 100644 --- a/rules/req-webp-in-picture/README.md +++ b/rules/req-webp-in-picture/README.md @@ -1,6 +1,6 @@ # htmlacademy/req-webp-in-picture -Правило проверяет наличие webp изображений в теге ``. +Правило проверяет наличие webp изображений в теге ``. Не проверяет `` если все `` имеют атрибут `type="image/svg+xml"`. ## true @@ -38,3 +38,11 @@ Example image ``` + +```html + + + + + +``` diff --git a/rules/req-webp-in-picture/index.js b/rules/req-webp-in-picture/index.js index 83dc693..5148d4d 100644 --- a/rules/req-webp-in-picture/index.js +++ b/rules/req-webp-in-picture/index.js @@ -7,6 +7,12 @@ module.exports = { lint(node, rule_config, { report }) { if (is_tag_node(node) && node.tagName === 'picture') { const sourceElements = node.children.filter((child) => child.tagName === 'source'); + const allSourcesAreSvg = sourceElements.every((source) => attribute_has_value(source, 'type', 'image/svg+xml')); + + if (allSourcesAreSvg) { + return; + } + const hasWebpSource = sourceElements.some((source) => attribute_has_value(source, 'type', 'image/webp')); if (!hasWebpSource) {