Skip to content

Enable svg for the req-webp-in-picture rule #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.0.21
Fixes `req-webp-in-picture` to not check `<picture>` if all `<source>` 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.
Expand Down
10 changes: 9 additions & 1 deletion rules/req-webp-in-picture/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# htmlacademy/req-webp-in-picture

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

## true

Expand Down Expand Up @@ -38,3 +38,11 @@
<img width="400" height="200" src="image.png" alt="Example image">
</picture>
```

```html
<picture>
<source type="image/svg+xml" media="(width >= 1280px)" srcset="images/logo-1280.svg" width="33" height="38">
<source type="image/svg+xml" media="(width >= 768px)" srcset="images/logo-768.svg" width="33" height="38">
<img src="images/logo.svg" srcset="images/logo.svg" width="33" height="38" alt="">
</picture>
```
6 changes: 6 additions & 0 deletions rules/req-webp-in-picture/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading