File tree Expand file tree Collapse file tree 3 files changed +63
-0
lines changed
rules/section-has-heading Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 11# Changelog
22
3+ ## 1.0.5
4+ Adds new rule htmlacademy/section-has-heading
5+
36## 1.0.4
47Fixed name for ` head-meta-charset `
58
Original file line number Diff line number Diff line change 1+ # htmlacademy/section-has-heading
2+
3+ Правило проверяет наличие заголовка любого уровня h1-h6 у ` <section> ` . Правило принимает значения ` true ` или ` false `
4+
5+ ## true
6+ У ` <section> ` есть дочерний заголовок любого уровня h1-h6.
7+
8+ Проблемными считаются следующие шаблоны:
9+ ``` html
10+ <section >
11+ ...
12+ </section >
13+ ```
14+
15+ Следующие шаблоны ** не** считаются проблемами:
16+ ``` html
17+ <section >
18+ <h2 >title</h2 >
19+ </section >
20+
21+ <section >
22+ <div >
23+ <h2 >title</h2 >
24+ </div >
25+ </section >
26+ ```
27+
28+ Вложенность заголовка(h1-h6) может быть любой.
Original file line number Diff line number Diff line change 1+ const { is_tag_node } = require ( "@linthtml/dom-utils" ) ;
2+
3+ const isSectionElement = ( node ) => is_tag_node ( node ) && node . name === "section" ;
4+ const isHeadingElement = ( node ) => is_tag_node ( node ) && / ^ h [ 1 - 6 ] $ / . test ( node . name ) ;
5+ const isNotSvg = ( node ) => node . name !== 'svg' ;
6+ const checkChildNode = ( node ) => {
7+ if ( isHeadingElement ( node ) ) {
8+ return true ;
9+ }
10+
11+ if ( node . children && isNotSvg ( node ) ) {
12+ for ( const child of node . children ) {
13+ if ( checkChildNode ( child ) ) {
14+ return true ;
15+ }
16+ }
17+ }
18+
19+ return false ;
20+ } ;
21+
22+ module . exports = {
23+ name : "htmlacademy/section-has-heading" ,
24+ lint ( node , rule_config , { report } ) {
25+ if ( isSectionElement ( node ) && ! checkChildNode ( node ) ) {
26+ report ( {
27+ position : node . loc ,
28+ message : "The <section> element must contain a heading of any level." ,
29+ } ) ;
30+ }
31+ }
32+ } ;
You can’t perform that action at this time.
0 commit comments