Skip to content

Commit facbec4

Browse files
Merge branch 'main' into feature/space-beetwen-comments
# Conflicts: # CHANGELOG.md
2 parents 397c994 + 696c2a7 commit facbec4

File tree

10 files changed

+67
-39
lines changed

10 files changed

+67
-39
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Changelog
22

3-
## 1.0.10
3+
## 1.0.11
44
Added [htmlacademy/space-between-comments](rules/space-between-comments/README.md)
55

6+
## 1.0.10
7+
`attr-req-value` can now accept regex for ignore
8+
69
## 1.0.9
710
Fixed `req-charset-utf` rule
811

package-lock.json

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "linthtml-rules-htmlacademy",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "Кастомные правила для linthtml от HTML Academy",
55
"main": "index.js",
66
"repository": "htmlacademy/linthtml-rules-htmlacademy",
@@ -13,7 +13,7 @@
1313
"license": "ISC",
1414
"devDependencies": {
1515
"@linthtml/dom-utils": "0.9.5",
16-
"eslint": "8.52.0",
16+
"eslint": "8.55.0",
1717
"eslint-config-htmlacademy": "10.0.1"
1818
}
1919
}

rules/a-target-rel/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
```
1515

1616
Следующие шаблоны **не** считаются проблемами:
17-
1817
```html
1918
<a href="https://htmlacademy.pro" target="_blank" rel="noreferrer noopener">Link</a>
2019

rules/attr-delimiter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# htmlacademy/attr-delimiter
22

3-
Это правило запрещает использование пробелов, разделяющих ключ атрибута и значение, т.е. до или после символа `=`. Технически пробелы разрешены спецификацией HTML5.
3+
Это правило запрещает использование пробелов, разделяющих ключ атрибута и значение, то есть до или после символа `=`. Технически пробелы разрешены спецификацией HTML5.
44
Использование пробелов в этом контексте может быть признаком опечатки.
55

66
## true

rules/attr-req-value/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
```
2828

2929
### ignore
30-
Игнорирует перечисленный список атрибутов
30+
Игнорирует перечисленный список атрибутов. Принимает значения `string|regex`
3131

3232
```js
3333
{
3434
'htmlacademy/attr-req-value': [true,
3535
{
36-
ignore: ['alt']
36+
ignore: ['alt', '/^data-/']
3737
}
3838
]
3939
}
@@ -49,4 +49,5 @@
4949

5050
```html
5151
<img src="images/image.jpg" width="100" height="100" alt="">
52+
<section data-test></section>
5253
```

rules/attr-req-value/index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
'use strict';
22
// eslint-disable-next-line camelcase
3-
const { is_tag_node, has_non_empty_attribute, is_boolean_attribute} = require('@linthtml/dom-utils');
3+
const { is_tag_node, has_non_empty_attribute, is_boolean_attribute } = require('@linthtml/dom-utils');
4+
const matchesIgnoreList = (attributeName, ignoreList) => ignoreList.some((ignoreItem) => {
5+
if (typeof ignoreItem === 'string') {
6+
const regexString = ignoreItem.startsWith('/') && ignoreItem.endsWith('/') ? ignoreItem.slice(1, -1) : ignoreItem;
7+
const regex = new RegExp(regexString);
8+
return regex.test(attributeName);
9+
} else if (ignoreItem instanceof RegExp) {
10+
return ignoreItem.test(attributeName);
11+
} else {
12+
return attributeName === ignoreItem;
13+
}
14+
});
15+
416

517
module.exports = {
618
name: 'htmlacademy/attr-req-value',
@@ -12,18 +24,19 @@ module.exports = {
1224
const name = attribute.name.chars.toLowerCase();
1325

1426
// eslint-disable-next-line camelcase
15-
if (!has_non_empty_attribute(node, name) && !is_boolean_attribute(attribute) && !rule_config.ignore?.includes(name)) {
27+
if (!has_non_empty_attribute(node, name) && !is_boolean_attribute(attribute) && !matchesIgnoreList(name, rule_config.ignore)
28+
) {
1629
report({
1730
code: 'E006',
1831
position: attribute.loc,
1932
meta: {
2033
data: {
21-
attribute: name
22-
}
23-
}
34+
attribute: name,
35+
},
36+
},
2437
});
2538
}
2639
});
2740
}
28-
}
41+
},
2942
};

rules/charset-position/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# htmlacademy/charset-position
22

3-
Правило позиционирование `<meta charset="">` в `<head>`. Правило принимает значения `true` или `false`
3+
Правило позиционирования `<meta charset="">` в `<head>`. Правило принимает значения `true` или `false`
44

55
## true
66
`<meta charset="">` указан первым непосредственным ребёнком в `<head>`.

rules/link-req-content/README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,24 @@
1111

1212
Проблемными считаются следующие шаблоны:
1313
```html
14-
<a><img src="cat.gif"></a>
14+
<a>
15+
<img src="images/cat.gif" width="100" height="1000">
16+
</a>
17+
18+
<a href="#">
19+
<svg>...</svg>
20+
</a>
1521
```
1622

1723
Следующие шаблоны **не** считаются проблемами:
1824
```html
19-
<a>lorem ipsum</a>
20-
<a><img src="cat.gif" alt="cat page"></a>
21-
<a aria-label="lorem ipsum"></a>
25+
<a href="#">
26+
lorem ipsum
27+
</a>
28+
29+
<a href="#">
30+
<img src="images/cat.gif" width="100" height="100" alt="cat page">
31+
</a>
32+
33+
<a href="#" aria-label="lorem ipsum"></a>
2234
```

rules/no-blocking-script/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# htmlacademy/no-blocking-script
22

3-
Правило проверяет расположение скриптов в разметке.
3+
Правило проверяет расположение скриптов в разметке. Правило принимает значения `true` или `false`.
44

55
## true
66
Скрипты должны быть подключены в самом низу страницы, чтобы при её загрузке не блокировать отображение содержимого.

0 commit comments

Comments
 (0)