zemdomu 1.0.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.
- package/README.md +112 -0
- package/out/index.js +6 -0
- package/out/linter.js +138 -0
- package/out/rules/enforceHeadingOrder.js +39 -0
- package/out/rules/enforceListNesting.js +78 -0
- package/out/rules/preventEmptyInlineTags.js +83 -0
- package/out/rules/requireAltText.js +78 -0
- package/out/rules/requireAltTextJSX.js +63 -0
- package/out/rules/requireButtonText.js +78 -0
- package/out/rules/requireHrefOnAnchors.js +66 -0
- package/out/rules/requireHtmlLang.js +72 -0
- package/out/rules/requireIframeTitle.js +69 -0
- package/out/rules/requireImageInputAlt.js +69 -0
- package/out/rules/requireLabelForFormControls.js +84 -0
- package/out/rules/requireLinkText.js +86 -0
- package/out/rules/requireNavLinks.js +48 -0
- package/out/rules/requireSectionHeading.js +48 -0
- package/out/rules/requireTableCaption.js +48 -0
- package/out/rules/singleH1.js +33 -0
- package/out/rules/uniqueIds.js +33 -0
- package/out/rules/utils.js +50 -0
- package/out/simpleHtmlParser.js +78 -0
- package/package.json +30 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getAttr = getAttr;
|
|
37
|
+
exports.getJsxAttr = getJsxAttr;
|
|
38
|
+
exports.getTag = getTag;
|
|
39
|
+
const t = __importStar(require("@babel/types"));
|
|
40
|
+
function getAttr(node, name) {
|
|
41
|
+
return node.attrs[name];
|
|
42
|
+
}
|
|
43
|
+
function getJsxAttr(opening, name) {
|
|
44
|
+
const attr = opening.attributes.find((a) => t.isJSXAttribute(a) && t.isJSXIdentifier(a.name) && a.name.name === name);
|
|
45
|
+
return attr && t.isStringLiteral(attr.value) ? attr.value.value : undefined;
|
|
46
|
+
}
|
|
47
|
+
function getTag(path) {
|
|
48
|
+
const opening = path.node.openingElement;
|
|
49
|
+
return t.isJSXIdentifier(opening.name) ? opening.name.name.toLowerCase() : '';
|
|
50
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = parse;
|
|
4
|
+
function parseAttributes(str) {
|
|
5
|
+
const attrs = {};
|
|
6
|
+
str.replace(/([\w-:]+)(?:\s*=\s*("[^"]*"|'[^']*'|[^\s"'>]+))?/g, (_, name, value) => {
|
|
7
|
+
if (value === undefined) {
|
|
8
|
+
attrs[name] = '';
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
attrs[name] = value.replace(/^['"]|['"]$/g, '');
|
|
12
|
+
}
|
|
13
|
+
return '';
|
|
14
|
+
});
|
|
15
|
+
return attrs;
|
|
16
|
+
}
|
|
17
|
+
function* tokenize(html) {
|
|
18
|
+
let i = 0;
|
|
19
|
+
while (i < html.length) {
|
|
20
|
+
if (html.startsWith('<!--', i)) {
|
|
21
|
+
const end = html.indexOf('-->', i + 4);
|
|
22
|
+
const text = html.slice(i + 4, end === -1 ? html.length : end);
|
|
23
|
+
yield { type: 'comment', text, index: i };
|
|
24
|
+
i = end === -1 ? html.length : end + 3;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (html[i] === '<') {
|
|
28
|
+
const close = html.slice(i).match(/^<\/(\s*[\w-:]+)\s*>/);
|
|
29
|
+
if (close) {
|
|
30
|
+
yield { type: 'close', tag: close[1].trim().toLowerCase(), index: i };
|
|
31
|
+
i += close[0].length;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const open = html.slice(i).match(/^<\s*([\w-:]+)([^>]*?)(\/)?>/);
|
|
35
|
+
if (open) {
|
|
36
|
+
const [, tag, attrs, self] = open;
|
|
37
|
+
yield {
|
|
38
|
+
type: 'open',
|
|
39
|
+
tag: tag.toLowerCase(),
|
|
40
|
+
attrs: parseAttributes(attrs),
|
|
41
|
+
selfClosing: !!self,
|
|
42
|
+
index: i
|
|
43
|
+
};
|
|
44
|
+
i += open[0].length;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const next = html.indexOf('<', i);
|
|
49
|
+
const end = next === -1 ? html.length : next;
|
|
50
|
+
const text = html.slice(i, end);
|
|
51
|
+
yield { type: 'text', text, index: i };
|
|
52
|
+
i = end;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function parse(html) {
|
|
56
|
+
const root = { type: 'element', tagName: 'root', attrs: {}, children: [], startIndex: 0 };
|
|
57
|
+
const stack = [root];
|
|
58
|
+
for (const token of tokenize(html)) {
|
|
59
|
+
const parent = stack[stack.length - 1];
|
|
60
|
+
if (token.type === 'open') {
|
|
61
|
+
const node = { type: 'element', tagName: token.tag, attrs: token.attrs || {}, children: [], startIndex: token.index, selfClosing: token.selfClosing };
|
|
62
|
+
parent.children.push(node);
|
|
63
|
+
if (!token.selfClosing)
|
|
64
|
+
stack.push(node);
|
|
65
|
+
}
|
|
66
|
+
else if (token.type === 'close') {
|
|
67
|
+
if (stack.length > 1)
|
|
68
|
+
stack.pop();
|
|
69
|
+
}
|
|
70
|
+
else if (token.type === 'text') {
|
|
71
|
+
parent.children.push({ type: 'text', text: token.text || '', startIndex: token.index });
|
|
72
|
+
}
|
|
73
|
+
else if (token.type === 'comment') {
|
|
74
|
+
parent.children.push({ type: 'comment', text: token.text || '', startIndex: token.index });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return root;
|
|
78
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zemdomu",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Hello",
|
|
5
|
+
"main": "./out/index.js",
|
|
6
|
+
"files": ["out"],
|
|
7
|
+
"private": false,
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc -p tsconfig.json",
|
|
10
|
+
"test": "npm run compile && node tests/linter-labels.test.js && node tests/unique-ids.test.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/babel__traverse": "^7.20.7",
|
|
17
|
+
"@types/babel-traverse": "^6.25.10",
|
|
18
|
+
"@types/babel-types": "^7.0.16",
|
|
19
|
+
"typescript": "^5.8.2",
|
|
20
|
+
"@types/node": "^22.15.17",
|
|
21
|
+
"@types/jest": "^29.5.3",
|
|
22
|
+
"esbuild": "^0.25.5",
|
|
23
|
+
"jest": "^29.7.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@babel/parser": "^7.27.0",
|
|
27
|
+
"@babel/traverse": "^7.27.0",
|
|
28
|
+
"@babel/types": "^7.27.0"
|
|
29
|
+
}
|
|
30
|
+
}
|