zemdomu 1.3.4 → 1.3.6
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/out/component-analyzer.js +44 -20
- package/out/project-linter.js +4 -0
- package/out/rules/enforceHeadingOrder.js +25 -6
- package/out/src/component-analyzer.js +44 -20
- package/out/src/project-linter.js +4 -0
- package/out/src/rules/enforceHeadingOrder.js +25 -6
- package/out/tests/crossComponent/cross-heading-order.test.js +4 -0
- package/package.json +8 -1
|
@@ -218,16 +218,29 @@ class ComponentAnalyzer {
|
|
|
218
218
|
return a.column - b.column;
|
|
219
219
|
});
|
|
220
220
|
for (const heading of sortedHeadings) {
|
|
221
|
-
if (lastHeadingLevel
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
221
|
+
if (lastHeadingLevel) {
|
|
222
|
+
if (heading.level > lastHeadingLevel + 1) {
|
|
223
|
+
componentDef.issues.set('enforceHeadingOrder', [
|
|
224
|
+
...(componentDef.issues.get('enforceHeadingOrder') || []),
|
|
225
|
+
{
|
|
226
|
+
line: heading.line,
|
|
227
|
+
column: heading.column,
|
|
228
|
+
message: `Heading level skipped: <h${heading.level}> after <h${lastHeadingLevel}>`,
|
|
229
|
+
rule: 'enforceHeadingOrder'
|
|
230
|
+
}
|
|
231
|
+
]);
|
|
232
|
+
}
|
|
233
|
+
else if (heading.level === 1 && lastHeadingLevel !== 1) {
|
|
234
|
+
componentDef.issues.set('enforceHeadingOrder', [
|
|
235
|
+
...(componentDef.issues.get('enforceHeadingOrder') || []),
|
|
236
|
+
{
|
|
237
|
+
line: heading.line,
|
|
238
|
+
column: heading.column,
|
|
239
|
+
message: `Heading level skipped: <h${heading.level}> after <h${lastHeadingLevel}>`,
|
|
240
|
+
rule: 'enforceHeadingOrder'
|
|
241
|
+
}
|
|
242
|
+
]);
|
|
243
|
+
}
|
|
231
244
|
}
|
|
232
245
|
lastHeadingLevel = heading.level;
|
|
233
246
|
}
|
|
@@ -376,7 +389,7 @@ class ComponentAnalyzer {
|
|
|
376
389
|
* and checks for heading level issues
|
|
377
390
|
*/
|
|
378
391
|
analyzeHeadingHierarchy(component, results, depth = 0) {
|
|
379
|
-
var _a, _b, _c;
|
|
392
|
+
var _a, _b, _c, _d, _e, _f;
|
|
380
393
|
if (this.maxDepth !== undefined && depth > this.maxDepth)
|
|
381
394
|
return;
|
|
382
395
|
if (this.processingComponentStack.has(component.filePath)) {
|
|
@@ -389,15 +402,26 @@ class ComponentAnalyzer {
|
|
|
389
402
|
// Check for heading level issues
|
|
390
403
|
let lastLevel = 0;
|
|
391
404
|
for (const heading of allHeadings) {
|
|
392
|
-
if (lastLevel > 0
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
405
|
+
if (lastLevel > 0) {
|
|
406
|
+
if (heading.heading.level > lastLevel + 1) {
|
|
407
|
+
// We found a heading level skip
|
|
408
|
+
results.push({
|
|
409
|
+
filePath: ((_a = heading.usageLocation) === null || _a === void 0 ? void 0 : _a.filePath) || heading.heading.filePath,
|
|
410
|
+
line: ((_b = heading.usageLocation) === null || _b === void 0 ? void 0 : _b.line) || heading.heading.line,
|
|
411
|
+
column: ((_c = heading.usageLocation) === null || _c === void 0 ? void 0 : _c.column) || heading.heading.column,
|
|
412
|
+
message: `Cross-component heading level skipped: <h${heading.heading.level}> after <h${lastLevel}>`,
|
|
413
|
+
rule: 'enforceHeadingOrder'
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
else if (heading.heading.level === 1 && lastLevel !== 1) {
|
|
417
|
+
results.push({
|
|
418
|
+
filePath: ((_d = heading.usageLocation) === null || _d === void 0 ? void 0 : _d.filePath) || heading.heading.filePath,
|
|
419
|
+
line: ((_e = heading.usageLocation) === null || _e === void 0 ? void 0 : _e.line) || heading.heading.line,
|
|
420
|
+
column: ((_f = heading.usageLocation) === null || _f === void 0 ? void 0 : _f.column) || heading.heading.column,
|
|
421
|
+
message: `Cross-component heading level skipped: <h${heading.heading.level}> after <h${lastLevel}>`,
|
|
422
|
+
rule: 'enforceHeadingOrder'
|
|
423
|
+
});
|
|
424
|
+
}
|
|
401
425
|
}
|
|
402
426
|
lastLevel = heading.heading.level;
|
|
403
427
|
}
|
package/out/project-linter.js
CHANGED
|
@@ -42,10 +42,14 @@ const path_1 = __importDefault(require("path"));
|
|
|
42
42
|
const ts = __importStar(require("typescript"));
|
|
43
43
|
const linter_1 = require("./linter");
|
|
44
44
|
const component_analyzer_1 = require("./component-analyzer");
|
|
45
|
+
const component_path_resolver_1 = require("./component-path-resolver");
|
|
45
46
|
const collectLocalDeps_1 = require("./utils/collectLocalDeps");
|
|
46
47
|
class ProjectLinter {
|
|
47
48
|
constructor(options = {}) {
|
|
49
|
+
var _a;
|
|
48
50
|
this.opts = options;
|
|
51
|
+
const rootDir = (_a = this.opts.rootDir) !== null && _a !== void 0 ? _a : process.cwd();
|
|
52
|
+
component_path_resolver_1.ComponentPathResolver.setRootDir(rootDir);
|
|
49
53
|
this.analyzer = new component_analyzer_1.ComponentAnalyzer(this.opts, options.perf);
|
|
50
54
|
}
|
|
51
55
|
clear() {
|
|
@@ -4,18 +4,30 @@ exports.default = enforceHeadingOrder;
|
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
function enforceHeadingOrder() {
|
|
6
6
|
let last = 0;
|
|
7
|
+
let seen = false;
|
|
7
8
|
return {
|
|
8
9
|
name: 'enforceHeadingOrder',
|
|
9
|
-
init() {
|
|
10
|
+
init() {
|
|
11
|
+
last = 0;
|
|
12
|
+
seen = false;
|
|
13
|
+
},
|
|
10
14
|
enterHtml(node) {
|
|
11
15
|
if (node.type === 'element' && /^h[1-6]$/.test(node.tagName)) {
|
|
12
16
|
const lvl = parseInt(node.tagName.charAt(1), 10);
|
|
17
|
+
let message = null;
|
|
13
18
|
if (last && lvl > last + 1) {
|
|
14
|
-
|
|
19
|
+
message = `Heading level skipped: <${node.tagName}> after <h${last}>`;
|
|
20
|
+
}
|
|
21
|
+
else if (seen && lvl === 1 && last !== 1) {
|
|
22
|
+
message = `Heading level skipped: <${node.tagName}> after <h${last}>`;
|
|
23
|
+
}
|
|
24
|
+
last = lvl;
|
|
25
|
+
seen = true;
|
|
26
|
+
if (message) {
|
|
15
27
|
last = lvl;
|
|
16
28
|
return [{ line: 0, column: 0, message, rule: 'enforceHeadingOrder' }];
|
|
17
29
|
}
|
|
18
|
-
|
|
30
|
+
return [];
|
|
19
31
|
}
|
|
20
32
|
return [];
|
|
21
33
|
},
|
|
@@ -24,14 +36,21 @@ function enforceHeadingOrder() {
|
|
|
24
36
|
const tag = (0, utils_1.getTag)(path);
|
|
25
37
|
if (/^h[1-6]$/.test(tag)) {
|
|
26
38
|
const lvl = parseInt(tag.charAt(1), 10);
|
|
39
|
+
let message = null;
|
|
27
40
|
if (last && lvl > last + 1) {
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
message = `Heading level skipped: <${tag}> after <h${last}>`;
|
|
42
|
+
}
|
|
43
|
+
else if (seen && lvl === 1 && last !== 1) {
|
|
44
|
+
message = `Heading level skipped: <${tag}> after <h${last}>`;
|
|
45
|
+
}
|
|
46
|
+
last = lvl;
|
|
47
|
+
seen = true;
|
|
48
|
+
if (message) {
|
|
30
49
|
const line = ((_b = (_a = path.node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
|
|
31
50
|
const column = (_d = (_c = path.node.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
|
|
32
51
|
return [{ line, column, message, rule: 'enforceHeadingOrder' }];
|
|
33
52
|
}
|
|
34
|
-
|
|
53
|
+
return [];
|
|
35
54
|
}
|
|
36
55
|
return [];
|
|
37
56
|
},
|
|
@@ -218,16 +218,29 @@ class ComponentAnalyzer {
|
|
|
218
218
|
return a.column - b.column;
|
|
219
219
|
});
|
|
220
220
|
for (const heading of sortedHeadings) {
|
|
221
|
-
if (lastHeadingLevel
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
221
|
+
if (lastHeadingLevel) {
|
|
222
|
+
if (heading.level > lastHeadingLevel + 1) {
|
|
223
|
+
componentDef.issues.set('enforceHeadingOrder', [
|
|
224
|
+
...(componentDef.issues.get('enforceHeadingOrder') || []),
|
|
225
|
+
{
|
|
226
|
+
line: heading.line,
|
|
227
|
+
column: heading.column,
|
|
228
|
+
message: `Heading level skipped: <h${heading.level}> after <h${lastHeadingLevel}>`,
|
|
229
|
+
rule: 'enforceHeadingOrder'
|
|
230
|
+
}
|
|
231
|
+
]);
|
|
232
|
+
}
|
|
233
|
+
else if (heading.level === 1 && lastHeadingLevel !== 1) {
|
|
234
|
+
componentDef.issues.set('enforceHeadingOrder', [
|
|
235
|
+
...(componentDef.issues.get('enforceHeadingOrder') || []),
|
|
236
|
+
{
|
|
237
|
+
line: heading.line,
|
|
238
|
+
column: heading.column,
|
|
239
|
+
message: `Heading level skipped: <h${heading.level}> after <h${lastHeadingLevel}>`,
|
|
240
|
+
rule: 'enforceHeadingOrder'
|
|
241
|
+
}
|
|
242
|
+
]);
|
|
243
|
+
}
|
|
231
244
|
}
|
|
232
245
|
lastHeadingLevel = heading.level;
|
|
233
246
|
}
|
|
@@ -376,7 +389,7 @@ class ComponentAnalyzer {
|
|
|
376
389
|
* and checks for heading level issues
|
|
377
390
|
*/
|
|
378
391
|
analyzeHeadingHierarchy(component, results, depth = 0) {
|
|
379
|
-
var _a, _b, _c;
|
|
392
|
+
var _a, _b, _c, _d, _e, _f;
|
|
380
393
|
if (this.maxDepth !== undefined && depth > this.maxDepth)
|
|
381
394
|
return;
|
|
382
395
|
if (this.processingComponentStack.has(component.filePath)) {
|
|
@@ -389,15 +402,26 @@ class ComponentAnalyzer {
|
|
|
389
402
|
// Check for heading level issues
|
|
390
403
|
let lastLevel = 0;
|
|
391
404
|
for (const heading of allHeadings) {
|
|
392
|
-
if (lastLevel > 0
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
405
|
+
if (lastLevel > 0) {
|
|
406
|
+
if (heading.heading.level > lastLevel + 1) {
|
|
407
|
+
// We found a heading level skip
|
|
408
|
+
results.push({
|
|
409
|
+
filePath: ((_a = heading.usageLocation) === null || _a === void 0 ? void 0 : _a.filePath) || heading.heading.filePath,
|
|
410
|
+
line: ((_b = heading.usageLocation) === null || _b === void 0 ? void 0 : _b.line) || heading.heading.line,
|
|
411
|
+
column: ((_c = heading.usageLocation) === null || _c === void 0 ? void 0 : _c.column) || heading.heading.column,
|
|
412
|
+
message: `Cross-component heading level skipped: <h${heading.heading.level}> after <h${lastLevel}>`,
|
|
413
|
+
rule: 'enforceHeadingOrder'
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
else if (heading.heading.level === 1 && lastLevel !== 1) {
|
|
417
|
+
results.push({
|
|
418
|
+
filePath: ((_d = heading.usageLocation) === null || _d === void 0 ? void 0 : _d.filePath) || heading.heading.filePath,
|
|
419
|
+
line: ((_e = heading.usageLocation) === null || _e === void 0 ? void 0 : _e.line) || heading.heading.line,
|
|
420
|
+
column: ((_f = heading.usageLocation) === null || _f === void 0 ? void 0 : _f.column) || heading.heading.column,
|
|
421
|
+
message: `Cross-component heading level skipped: <h${heading.heading.level}> after <h${lastLevel}>`,
|
|
422
|
+
rule: 'enforceHeadingOrder'
|
|
423
|
+
});
|
|
424
|
+
}
|
|
401
425
|
}
|
|
402
426
|
lastLevel = heading.heading.level;
|
|
403
427
|
}
|
|
@@ -42,10 +42,14 @@ const path_1 = __importDefault(require("path"));
|
|
|
42
42
|
const ts = __importStar(require("typescript"));
|
|
43
43
|
const linter_1 = require("./linter");
|
|
44
44
|
const component_analyzer_1 = require("./component-analyzer");
|
|
45
|
+
const component_path_resolver_1 = require("./component-path-resolver");
|
|
45
46
|
const collectLocalDeps_1 = require("./utils/collectLocalDeps");
|
|
46
47
|
class ProjectLinter {
|
|
47
48
|
constructor(options = {}) {
|
|
49
|
+
var _a;
|
|
48
50
|
this.opts = options;
|
|
51
|
+
const rootDir = (_a = this.opts.rootDir) !== null && _a !== void 0 ? _a : process.cwd();
|
|
52
|
+
component_path_resolver_1.ComponentPathResolver.setRootDir(rootDir);
|
|
49
53
|
this.analyzer = new component_analyzer_1.ComponentAnalyzer(this.opts, options.perf);
|
|
50
54
|
}
|
|
51
55
|
clear() {
|
|
@@ -4,18 +4,30 @@ exports.default = enforceHeadingOrder;
|
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
function enforceHeadingOrder() {
|
|
6
6
|
let last = 0;
|
|
7
|
+
let seen = false;
|
|
7
8
|
return {
|
|
8
9
|
name: 'enforceHeadingOrder',
|
|
9
|
-
init() {
|
|
10
|
+
init() {
|
|
11
|
+
last = 0;
|
|
12
|
+
seen = false;
|
|
13
|
+
},
|
|
10
14
|
enterHtml(node) {
|
|
11
15
|
if (node.type === 'element' && /^h[1-6]$/.test(node.tagName)) {
|
|
12
16
|
const lvl = parseInt(node.tagName.charAt(1), 10);
|
|
17
|
+
let message = null;
|
|
13
18
|
if (last && lvl > last + 1) {
|
|
14
|
-
|
|
19
|
+
message = `Heading level skipped: <${node.tagName}> after <h${last}>`;
|
|
20
|
+
}
|
|
21
|
+
else if (seen && lvl === 1 && last !== 1) {
|
|
22
|
+
message = `Heading level skipped: <${node.tagName}> after <h${last}>`;
|
|
23
|
+
}
|
|
24
|
+
last = lvl;
|
|
25
|
+
seen = true;
|
|
26
|
+
if (message) {
|
|
15
27
|
last = lvl;
|
|
16
28
|
return [{ line: 0, column: 0, message, rule: 'enforceHeadingOrder' }];
|
|
17
29
|
}
|
|
18
|
-
|
|
30
|
+
return [];
|
|
19
31
|
}
|
|
20
32
|
return [];
|
|
21
33
|
},
|
|
@@ -24,14 +36,21 @@ function enforceHeadingOrder() {
|
|
|
24
36
|
const tag = (0, utils_1.getTag)(path);
|
|
25
37
|
if (/^h[1-6]$/.test(tag)) {
|
|
26
38
|
const lvl = parseInt(tag.charAt(1), 10);
|
|
39
|
+
let message = null;
|
|
27
40
|
if (last && lvl > last + 1) {
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
message = `Heading level skipped: <${tag}> after <h${last}>`;
|
|
42
|
+
}
|
|
43
|
+
else if (seen && lvl === 1 && last !== 1) {
|
|
44
|
+
message = `Heading level skipped: <${tag}> after <h${last}>`;
|
|
45
|
+
}
|
|
46
|
+
last = lvl;
|
|
47
|
+
seen = true;
|
|
48
|
+
if (message) {
|
|
30
49
|
const line = ((_b = (_a = path.node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
|
|
31
50
|
const column = (_d = (_c = path.node.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
|
|
32
51
|
return [{ line, column, message, rule: 'enforceHeadingOrder' }];
|
|
33
52
|
}
|
|
34
|
-
|
|
53
|
+
return [];
|
|
35
54
|
}
|
|
36
55
|
return [];
|
|
37
56
|
},
|
|
@@ -41,5 +41,9 @@ describe("cross component heading order", () => {
|
|
|
41
41
|
assert_1.default.ok(((_a = byRule["singleH1"]) !== null && _a !== void 0 ? _a : 0) >= 1, "Expected at least one singleH1");
|
|
42
42
|
assert_1.default.ok(((_b = byRule["enforceHeadingOrder"]) !== null && _b !== void 0 ? _b : 0) >= 1, // set to >=2 if you expect more
|
|
43
43
|
"Expected at least one enforceHeadingOrder");
|
|
44
|
+
const usageLocations = results
|
|
45
|
+
.filter((r) => r.rule === "enforceHeadingOrder" && "filePath" in r && r.filePath)
|
|
46
|
+
.map((r) => path_1.default.basename(r.filePath));
|
|
47
|
+
assert_1.default.ok(usageLocations.includes("SubSection.tsx"), "Expected heading order issue to surface on the component that renders the offending child");
|
|
44
48
|
});
|
|
45
49
|
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zemdomu",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "Semantic HTML linter for HTML, JSX, and TSX. Detects accessibility, SEO, and structure issues before deployment.",
|
|
5
5
|
"main": "./out/index.js",
|
|
6
6
|
"types": "./out/index.d.ts",
|
|
7
7
|
"bin": {
|
|
8
8
|
"zemdomu": "./out/cli.js"
|
|
9
9
|
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./out/index.d.ts",
|
|
13
|
+
"default": "./out/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./*": "./out/*"
|
|
16
|
+
},
|
|
10
17
|
"files": [
|
|
11
18
|
"out",
|
|
12
19
|
"README.md",
|