File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
rules/req-source-width-height Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ # htmlacademy/req-source-width-height
2
+
3
+ Правило требует наличие атрибутов ` width ` и ` height ` у ` <source> ` , находящихся внутри ` <piture> ` .
4
+
5
+ ## true
6
+ Если включён, ` <source> ` без атрибутов ` width ` и ` height ` считаются проблемой.
7
+
8
+
9
+ Проблемными считаются следующие шаблоны:
10
+ ``` html
11
+ <picture >
12
+ <source srcset =" images/image-tablet.jpg" media =" (min-width: 768px)" >
13
+ <img src =" images/image-mobile.jpg" width =" 320" height =" 148" alt =" " >
14
+ </picture >
15
+ ```
16
+
17
+ Следующие шаблоны ** не** считаются проблемами:
18
+
19
+ ``` html
20
+ <picture >
21
+ <source srcset =" images/image-tablet.jpg" width =" 768" height =" 480" media =" (min-width: 768px)" >
22
+ <img src =" images/image-mobile.jpg" width =" 320" height =" 148" alt =" " >
23
+ </picture >
24
+ ```
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+ const { has_non_empty_attribute, is_tag_node } = require ( '@linthtml/dom-utils' ) ;
3
+
4
+ module . exports = {
5
+ name : 'htmlacademy/req-source-width-height' ,
6
+ // eslint-disable-next-line camelcase
7
+ lint ( node , { report } ) {
8
+ if ( is_tag_node ( node ) && node . name === 'picture' ) {
9
+ node . children . forEach ( ( child ) => {
10
+ if ( is_tag_node ( child ) && child . name === 'source' ) {
11
+ const hasWidth = has_non_empty_attribute ( child , 'width' ) ;
12
+ const hasHeight = has_non_empty_attribute ( child , 'height' ) ;
13
+
14
+ if ( ! hasWidth || ! hasHeight ) {
15
+ report ( {
16
+ position : child . loc ,
17
+ message : 'The <source> tag inside <picture> must have both "width" and "height" attributes.' ,
18
+ } ) ;
19
+ }
20
+ }
21
+ } ) ;
22
+ }
23
+ }
24
+ } ;
You can’t perform that action at this time.
0 commit comments