Skip to content

Commit 49ccf9b

Browse files
Enable svg for the req-webp-in-picture rule (#113)
* Enable svg for the req-webp-in-picture rule * Fix Readme.md * Update CHANGELOG.md
1 parent 26390b5 commit 49ccf9b

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.0.21
4+
Fixes `req-webp-in-picture` to not check `<picture>` if all `<source>` have attribute `type="image/svg+xml"`.
5+
36
## 1.0.20
47
- Adds a `req-tags-presence` rule that requires the specified tags on the page.
58
- Adds a `req-preload-font` rule that requires the `preload` value for the font.

rules/req-webp-in-picture/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# htmlacademy/req-webp-in-picture
22

3-
Правило проверяет наличие webp изображений в теге `<picture>`.
3+
Правило проверяет наличие webp изображений в теге `<picture>`. Не проверяет `<picture>` если все `<source>` имеют атрибут `type="image/svg+xml"`.
44

55
## true
66

@@ -38,3 +38,11 @@
3838
<img width="400" height="200" src="image.png" alt="Example image">
3939
</picture>
4040
```
41+
42+
```html
43+
<picture>
44+
<source type="image/svg+xml" media="(width >= 1280px)" srcset="images/logo-1280.svg" width="33" height="38">
45+
<source type="image/svg+xml" media="(width >= 768px)" srcset="images/logo-768.svg" width="33" height="38">
46+
<img src="images/logo.svg" srcset="images/logo.svg" width="33" height="38" alt="">
47+
</picture>
48+
```

rules/req-webp-in-picture/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ module.exports = {
77
lint(node, rule_config, { report }) {
88
if (is_tag_node(node) && node.tagName === 'picture') {
99
const sourceElements = node.children.filter((child) => child.tagName === 'source');
10+
const allSourcesAreSvg = sourceElements.every((source) => attribute_has_value(source, 'type', 'image/svg+xml'));
11+
12+
if (allSourcesAreSvg) {
13+
return;
14+
}
15+
1016
const hasWebpSource = sourceElements.some((source) => attribute_has_value(source, 'type', 'image/webp'));
1117

1218
if (!hasWebpSource) {

0 commit comments

Comments
 (0)