testaro 32.2.2 → 32.2.3
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.
- package/package.json +1 -1
- package/testaro/headingAmb.js +17 -15
package/package.json
CHANGED
package/testaro/headingAmb.js
CHANGED
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
/*
|
|
24
24
|
headingAmb
|
|
25
25
|
Related to ASLint rule headings-sibling-unique.
|
|
26
|
-
This test reports
|
|
27
|
-
contents.
|
|
26
|
+
This test reports adjacent headings with the same levels and text contents.
|
|
28
27
|
*/
|
|
29
28
|
|
|
30
29
|
// ########## IMPORTS
|
|
@@ -49,21 +48,24 @@ exports.reporter = async (page, withItems) => {
|
|
|
49
48
|
const badIndexes = [];
|
|
50
49
|
// For each heading:
|
|
51
50
|
headings.forEach((heading, index) => {
|
|
52
|
-
//
|
|
53
|
-
const
|
|
54
|
-
|
|
51
|
+
// Get its level.
|
|
52
|
+
const level = heading.level;
|
|
53
|
+
// If there are prior non-inferior headings and the last one has the same-level and text:
|
|
54
|
+
// Get the prior headings.
|
|
55
|
+
const priorHeadings = headings.slice(0, index);
|
|
56
|
+
// Get the non-inferior ones among them.
|
|
57
|
+
const nonInferiors = priorHeadings.filter(priorHeading => priorHeading.level <= level);
|
|
58
|
+
// If there are any:
|
|
59
|
+
const nonInferiorCount = nonInferiors.length;
|
|
60
|
+
if (nonInferiorCount) {
|
|
61
|
+
// Get the last of them.
|
|
62
|
+
const prior = nonInferiors[nonInferiorCount - 1];
|
|
63
|
+
// If they have the same level and text:
|
|
55
64
|
if (['tagName', 'textContent'].every(property => prior[property] === heading[property])) {
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
headings
|
|
59
|
-
.slice(priorIndex + 1, index)
|
|
60
|
-
.every(betweenHeading => betweenHeading.tagName[1] >= heading.tagName[1])
|
|
61
|
-
) {
|
|
62
|
-
// Add the index of the later heading to the index of violating headings.
|
|
63
|
-
badIndexes.push(headings.indexOf(heading));
|
|
64
|
-
}
|
|
65
|
+
// Add the index of the later heading to the index of violating headings.
|
|
66
|
+
badIndexes.push(index);
|
|
65
67
|
}
|
|
66
|
-
}
|
|
68
|
+
}
|
|
67
69
|
});
|
|
68
70
|
return badIndexes;
|
|
69
71
|
});
|