@html-eslint/eslint-plugin 0.17.2 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -16,7 +16,19 @@ module.exports = {
|
|
|
16
16
|
},
|
|
17
17
|
|
|
18
18
|
fixable: true,
|
|
19
|
-
schema: [
|
|
19
|
+
schema: [
|
|
20
|
+
{
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
skip: {
|
|
24
|
+
type: "array",
|
|
25
|
+
items: {
|
|
26
|
+
type: "string",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
20
32
|
messages: {
|
|
21
33
|
[MESSAGE_IDS.EXPECT_NEW_LINE_AFTER]:
|
|
22
34
|
"There should be a linebreak after {{tag}}.",
|
|
@@ -26,6 +38,11 @@ module.exports = {
|
|
|
26
38
|
},
|
|
27
39
|
|
|
28
40
|
create(context) {
|
|
41
|
+
const option = context.options[0] || { skip: [] };
|
|
42
|
+
const skipTags = option.skip;
|
|
43
|
+
|
|
44
|
+
let isInSkipTags = false;
|
|
45
|
+
|
|
29
46
|
function checkSiblings(siblings) {
|
|
30
47
|
siblings
|
|
31
48
|
.filter((node) => node.type !== "Text")
|
|
@@ -78,10 +95,24 @@ module.exports = {
|
|
|
78
95
|
}
|
|
79
96
|
return {
|
|
80
97
|
[["Tag", "Program"].join(",")](node) {
|
|
98
|
+
if (isInSkipTags) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
81
102
|
const children = node.type === "Program" ? node.body : node.children;
|
|
82
103
|
checkSiblings(children);
|
|
104
|
+
if (skipTags.includes(node.name)) {
|
|
105
|
+
isInSkipTags = true;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
83
108
|
checkChild(node, children);
|
|
84
109
|
},
|
|
110
|
+
"Tag:exit"(node) {
|
|
111
|
+
if (skipTags.includes(node.name)) {
|
|
112
|
+
isInSkipTags = false;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
85
116
|
};
|
|
86
117
|
},
|
|
87
118
|
};
|
|
@@ -15,19 +15,37 @@ module.exports = {
|
|
|
15
15
|
},
|
|
16
16
|
|
|
17
17
|
fixable: null,
|
|
18
|
-
schema: [
|
|
18
|
+
schema: [
|
|
19
|
+
{
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
substitute: {
|
|
23
|
+
type: "array",
|
|
24
|
+
items: {
|
|
25
|
+
type: "string",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
19
31
|
messages: {
|
|
20
32
|
[MESSAGE_IDS.MISSING_ALT]: "Missing `alt` attribute at `<img>` tag",
|
|
21
33
|
},
|
|
22
34
|
},
|
|
23
35
|
|
|
24
36
|
create(context) {
|
|
37
|
+
const substitute =
|
|
38
|
+
(context.options &&
|
|
39
|
+
context.options[0] &&
|
|
40
|
+
context.options[0].substitute) ||
|
|
41
|
+
[];
|
|
42
|
+
|
|
25
43
|
return {
|
|
26
44
|
Tag(node) {
|
|
27
45
|
if (node.name !== "img") {
|
|
28
46
|
return;
|
|
29
47
|
}
|
|
30
|
-
if (!hasAltAttrAndValue(node)) {
|
|
48
|
+
if (!hasAltAttrAndValue(node, substitute)) {
|
|
31
49
|
context.report({
|
|
32
50
|
node: {
|
|
33
51
|
loc: {
|
|
@@ -44,10 +62,13 @@ module.exports = {
|
|
|
44
62
|
},
|
|
45
63
|
};
|
|
46
64
|
|
|
47
|
-
function hasAltAttrAndValue(node) {
|
|
65
|
+
function hasAltAttrAndValue(node, substitute = []) {
|
|
48
66
|
return node.attributes.some((attr) => {
|
|
49
67
|
if (attr.key && attr.value) {
|
|
50
|
-
return
|
|
68
|
+
return (
|
|
69
|
+
(attr.key.value === "alt" || substitute.includes(attr.key.value)) &&
|
|
70
|
+
typeof attr.value.value === "string"
|
|
71
|
+
);
|
|
51
72
|
}
|
|
52
73
|
});
|
|
53
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@html-eslint/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "ESLint plugin for html",
|
|
5
5
|
"author": "yeonjuan",
|
|
6
6
|
"homepage": "https://github.com/yeonjuan/html-eslint#readme",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"accessibility"
|
|
41
41
|
],
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@html-eslint/parser": "^0.
|
|
43
|
+
"@html-eslint/parser": "^0.19.0",
|
|
44
44
|
"@types/eslint": "^7.2.10",
|
|
45
45
|
"@types/estree": "^0.0.47",
|
|
46
46
|
"es-html-parser": "^0.0.8",
|
|
47
47
|
"typescript": "^4.4.4"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "9b8998a8253a7e6ad18c75ef7dedd23e0b0ec1f4"
|
|
50
50
|
}
|