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.
@@ -0,0 +1,66 @@
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.default = requireHrefOnAnchors;
37
+ const t = __importStar(require("@babel/types"));
38
+ const utils_1 = require("./utils");
39
+ function requireHrefOnAnchors() {
40
+ return {
41
+ name: 'requireHrefOnAnchors',
42
+ enterHtml(node) {
43
+ if (node.type === 'element' && node.tagName === 'a') {
44
+ const href = node.attrs.href;
45
+ if (!href || !href.trim()) {
46
+ return [{ line: 0, column: 0, message: '<a> tag missing non-empty href attribute', rule: 'requireHrefOnAnchors' }];
47
+ }
48
+ }
49
+ return [];
50
+ },
51
+ enterJsx(path) {
52
+ var _a, _b, _c, _d;
53
+ const opening = path.node.openingElement;
54
+ const tag = t.isJSXIdentifier(opening.name) ? opening.name.name.toLowerCase() : '';
55
+ if (tag === 'a') {
56
+ const href = (0, utils_1.getJsxAttr)(opening, 'href');
57
+ if (!href || !href.trim()) {
58
+ const line = ((_b = (_a = opening.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
59
+ const column = (_d = (_c = opening.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
60
+ return [{ line, column, message: '<a> tag missing non-empty href attribute', rule: 'requireHrefOnAnchors' }];
61
+ }
62
+ }
63
+ return [];
64
+ },
65
+ };
66
+ }
@@ -0,0 +1,72 @@
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.default = requireHtmlLang;
37
+ const t = __importStar(require("@babel/types"));
38
+ const utils_1 = require("./utils");
39
+ function requireHtmlLang() {
40
+ let seen = false;
41
+ return {
42
+ name: 'requireHtmlLang',
43
+ enterHtml(node) {
44
+ if (!seen && node.type === 'element' && node.tagName === 'html') {
45
+ seen = true;
46
+ const lang = node.attrs.lang;
47
+ if (lang === undefined) {
48
+ return [{ line: 0, column: 0, message: '<html> element missing lang attribute', rule: 'requireHtmlLang' }];
49
+ }
50
+ if (!String(lang).trim()) {
51
+ return [{ line: 0, column: 0, message: '<html> lang attribute is empty', rule: 'requireHtmlLang' }];
52
+ }
53
+ }
54
+ return [];
55
+ },
56
+ enterJsx(path) {
57
+ var _a, _b, _c, _d;
58
+ const opening = path.node.openingElement;
59
+ const tag = t.isJSXIdentifier(opening.name) ? opening.name.name.toLowerCase() : '';
60
+ if (!seen && tag === 'html') {
61
+ seen = true;
62
+ const lang = (0, utils_1.getJsxAttr)(opening, 'lang');
63
+ if (lang === undefined || !lang.trim()) {
64
+ const line = ((_b = (_a = opening.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
65
+ const column = (_d = (_c = opening.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
66
+ return [{ line, column, message: '<html> element missing lang attribute', rule: 'requireHtmlLang' }];
67
+ }
68
+ }
69
+ return [];
70
+ },
71
+ };
72
+ }
@@ -0,0 +1,69 @@
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.default = requireIframeTitle;
37
+ const t = __importStar(require("@babel/types"));
38
+ const utils_1 = require("./utils");
39
+ function requireIframeTitle() {
40
+ return {
41
+ name: 'requireIframeTitle',
42
+ enterHtml(node) {
43
+ if (node.type === 'element' && node.tagName === 'iframe') {
44
+ const title = node.attrs.title;
45
+ if (title === undefined) {
46
+ return [{ line: 0, column: 0, message: '<iframe> missing title attribute', rule: 'requireIframeTitle' }];
47
+ }
48
+ if (!String(title).trim()) {
49
+ return [{ line: 0, column: 0, message: '<iframe> title attribute is empty', rule: 'requireIframeTitle' }];
50
+ }
51
+ }
52
+ return [];
53
+ },
54
+ enterJsx(path) {
55
+ var _a, _b, _c, _d;
56
+ const opening = path.node.openingElement;
57
+ const tag = t.isJSXIdentifier(opening.name) ? opening.name.name.toLowerCase() : '';
58
+ if (tag === 'iframe') {
59
+ const title = (0, utils_1.getJsxAttr)(opening, 'title');
60
+ if (!title || !title.trim()) {
61
+ const line = ((_b = (_a = opening.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
62
+ const column = (_d = (_c = opening.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
63
+ return [{ line, column, message: '<iframe> missing title attribute', rule: 'requireIframeTitle' }];
64
+ }
65
+ }
66
+ return [];
67
+ },
68
+ };
69
+ }
@@ -0,0 +1,69 @@
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.default = requireImageInputAlt;
37
+ const t = __importStar(require("@babel/types"));
38
+ const utils_1 = require("./utils");
39
+ function requireImageInputAlt() {
40
+ return {
41
+ name: 'requireImageInputAlt',
42
+ enterHtml(node) {
43
+ if (node.type === 'element' && node.tagName === 'input' && node.attrs.type && node.attrs.type.toLowerCase() === 'image') {
44
+ const alt = node.attrs.alt;
45
+ if (alt === undefined || !String(alt).trim()) {
46
+ return [{ line: 0, column: 0, message: '<input type="image"> missing alt attribute', rule: 'requireImageInputAlt' }];
47
+ }
48
+ }
49
+ return [];
50
+ },
51
+ enterJsx(path) {
52
+ var _a, _b, _c, _d;
53
+ const opening = path.node.openingElement;
54
+ const tag = t.isJSXIdentifier(opening.name) ? opening.name.name.toLowerCase() : '';
55
+ if (tag === 'input') {
56
+ const type = (0, utils_1.getJsxAttr)(opening, 'type');
57
+ if (type && type.toLowerCase() === 'image') {
58
+ const alt = (0, utils_1.getJsxAttr)(opening, 'alt');
59
+ if (!alt || !alt.trim()) {
60
+ const line = ((_b = (_a = opening.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
61
+ const column = (_d = (_c = opening.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
62
+ return [{ line, column, message: '<input type="image"> missing alt attribute', rule: 'requireImageInputAlt' }];
63
+ }
64
+ }
65
+ }
66
+ return [];
67
+ },
68
+ };
69
+ }
@@ -0,0 +1,84 @@
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.default = requireLabelForFormControls;
37
+ const t = __importStar(require("@babel/types"));
38
+ const utils_1 = require("./utils");
39
+ function requireLabelForFormControls() {
40
+ const labels = new Set();
41
+ return {
42
+ name: 'requireLabelForFormControls',
43
+ enterHtml(node) {
44
+ if (node.type === 'element') {
45
+ if (node.tagName === 'label' && node.attrs['for'])
46
+ labels.add(node.attrs['for']);
47
+ if (['input', 'select', 'textarea'].includes(node.tagName)) {
48
+ const id = node.attrs.id;
49
+ const aria = node.attrs['aria-label'];
50
+ if (!aria || !aria.trim()) {
51
+ if (!id)
52
+ return [{ line: 0, column: 0, message: 'Form control missing id or aria-label', rule: 'requireLabelForFormControls' }];
53
+ if (!labels.has(id))
54
+ return [{ line: 0, column: 0, message: `Form control with id="${id}" missing <label for="${id}">`, rule: 'requireLabelForFormControls' }];
55
+ }
56
+ }
57
+ }
58
+ return [];
59
+ },
60
+ enterJsx(path) {
61
+ var _a, _b, _c, _d;
62
+ const opening = path.node.openingElement;
63
+ const tag = t.isJSXIdentifier(opening.name) ? opening.name.name.toLowerCase() : '';
64
+ if (tag === 'label') {
65
+ const htmlFor = (0, utils_1.getJsxAttr)(opening, 'for');
66
+ if (htmlFor)
67
+ labels.add(htmlFor);
68
+ }
69
+ if (['input', 'select', 'textarea'].includes(tag)) {
70
+ const id = (0, utils_1.getJsxAttr)(opening, 'id');
71
+ const aria = (0, utils_1.getJsxAttr)(opening, 'aria-label');
72
+ if (!aria || !aria.trim()) {
73
+ const line = ((_b = (_a = opening.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
74
+ const column = (_d = (_c = opening.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
75
+ if (!id)
76
+ return [{ line, column, message: 'Form control missing id or aria-label', rule: 'requireLabelForFormControls' }];
77
+ if (!labels.has(id))
78
+ return [{ line, column, message: `Form control with id="${id}" missing <label for="${id}">`, rule: 'requireLabelForFormControls' }];
79
+ }
80
+ }
81
+ return [];
82
+ },
83
+ };
84
+ }
@@ -0,0 +1,86 @@
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.default = requireLinkText;
37
+ const t = __importStar(require("@babel/types"));
38
+ const utils_1 = require("./utils");
39
+ function requireLinkText() {
40
+ const stack = [];
41
+ return {
42
+ name: 'requireLinkText',
43
+ enterHtml(node) {
44
+ if (node.type === 'element' && node.tagName === 'a') {
45
+ stack.push({ found: false });
46
+ }
47
+ else if (node.type === 'text') {
48
+ if (stack.length && node.text.trim())
49
+ stack[stack.length - 1].found = true;
50
+ }
51
+ return [];
52
+ },
53
+ exitHtml(node) {
54
+ if (node.type === 'element' && node.tagName === 'a') {
55
+ const entry = stack.pop();
56
+ if (entry && !entry.found)
57
+ return [{ line: 0, column: 0, message: '<a> tag missing link text', rule: 'requireLinkText' }];
58
+ }
59
+ return [];
60
+ },
61
+ enterJsx(path) {
62
+ const tag = (0, utils_1.getTag)(path);
63
+ if (tag === 'a')
64
+ stack.push({ found: false });
65
+ return [];
66
+ },
67
+ exitJsx(path) {
68
+ var _a, _b, _c, _d, _e;
69
+ const tag = (0, utils_1.getTag)(path);
70
+ if (tag === 'a') {
71
+ const entry = stack.pop();
72
+ let hasText = false;
73
+ const parent = (_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.node;
74
+ if (parent && Array.isArray(parent.children)) {
75
+ hasText = parent.children.some(c => (t.isJSXText(c) && c.value.trim()) || t.isJSXExpressionContainer(c));
76
+ }
77
+ if (entry && !(entry.found || hasText)) {
78
+ const line = ((_c = (_b = path.node.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _c !== void 0 ? _c : 1) - 1;
79
+ const column = (_e = (_d = path.node.loc) === null || _d === void 0 ? void 0 : _d.start.column) !== null && _e !== void 0 ? _e : 0;
80
+ return [{ line, column, message: '<a> tag missing link text', rule: 'requireLinkText' }];
81
+ }
82
+ }
83
+ return [];
84
+ },
85
+ };
86
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = requireNavLinks;
4
+ const utils_1 = require("./utils");
5
+ function requireNavLinks() {
6
+ const stack = [];
7
+ return {
8
+ name: 'requireNavLinks',
9
+ enterHtml(node) {
10
+ if (node.type === 'element') {
11
+ if (node.tagName === 'nav')
12
+ stack.push({ hasLink: false });
13
+ if (node.tagName === 'a' && stack.length)
14
+ stack[stack.length - 1].hasLink = true;
15
+ }
16
+ return [];
17
+ },
18
+ exitHtml(node) {
19
+ if (node.type === 'element' && node.tagName === 'nav') {
20
+ const entry = stack.pop();
21
+ if (entry && !entry.hasLink)
22
+ return [{ line: 0, column: 0, message: '<nav> contains no links', rule: 'requireNavLinks' }];
23
+ }
24
+ return [];
25
+ },
26
+ enterJsx(path) {
27
+ const tag = (0, utils_1.getTag)(path);
28
+ if (tag === 'nav')
29
+ stack.push({ hasLink: false });
30
+ if (tag === 'a' && stack.length)
31
+ stack[stack.length - 1].hasLink = true;
32
+ return [];
33
+ },
34
+ exitJsx(path) {
35
+ var _a, _b, _c, _d;
36
+ const tag = (0, utils_1.getTag)(path);
37
+ if (tag === 'nav') {
38
+ const entry = stack.pop();
39
+ if (entry && !entry.hasLink) {
40
+ const line = ((_b = (_a = path.node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
41
+ const column = (_d = (_c = path.node.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
42
+ return [{ line, column, message: '<nav> contains no links', rule: 'requireNavLinks' }];
43
+ }
44
+ }
45
+ return [];
46
+ },
47
+ };
48
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = requireSectionHeading;
4
+ const utils_1 = require("./utils");
5
+ function requireSectionHeading() {
6
+ const stack = [];
7
+ return {
8
+ name: 'requireSectionHeading',
9
+ enterHtml(node) {
10
+ if (node.type === 'element') {
11
+ if (node.tagName === 'section')
12
+ stack.push({ found: false });
13
+ if (/^h[1-6]$/i.test(node.tagName) && stack.length)
14
+ stack[stack.length - 1].found = true;
15
+ }
16
+ return [];
17
+ },
18
+ exitHtml(node) {
19
+ if (node.type === 'element' && node.tagName === 'section') {
20
+ const s = stack.pop();
21
+ if (s && !s.found)
22
+ return [{ line: 0, column: 0, message: '<section> missing heading (<h1>-<h6>)', rule: 'requireSectionHeading' }];
23
+ }
24
+ return [];
25
+ },
26
+ enterJsx(path) {
27
+ const tag = (0, utils_1.getTag)(path);
28
+ if (tag === 'section')
29
+ stack.push({ found: false });
30
+ if (/^h[1-6]$/.test(tag) && stack.length)
31
+ stack[stack.length - 1].found = true;
32
+ return [];
33
+ },
34
+ exitJsx(path) {
35
+ var _a, _b, _c, _d;
36
+ const tag = (0, utils_1.getTag)(path);
37
+ if (tag === 'section') {
38
+ const s = stack.pop();
39
+ if (s && !s.found) {
40
+ const line = ((_b = (_a = path.node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
41
+ const column = (_d = (_c = path.node.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
42
+ return [{ line, column, message: '<section> missing heading (<h1>-<h6>)', rule: 'requireSectionHeading' }];
43
+ }
44
+ }
45
+ return [];
46
+ },
47
+ };
48
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = requireTableCaption;
4
+ const utils_1 = require("./utils");
5
+ function requireTableCaption() {
6
+ const stack = [];
7
+ return {
8
+ name: 'requireTableCaption',
9
+ enterHtml(node) {
10
+ if (node.type === 'element') {
11
+ if (node.tagName === 'table')
12
+ stack.push({ found: false });
13
+ if (node.tagName === 'caption' && stack.length)
14
+ stack[stack.length - 1].found = true;
15
+ }
16
+ return [];
17
+ },
18
+ exitHtml(node) {
19
+ if (node.type === 'element' && node.tagName === 'table') {
20
+ const entry = stack.pop();
21
+ if (entry && !entry.found)
22
+ return [{ line: 0, column: 0, message: '<table> missing <caption>', rule: 'requireTableCaption' }];
23
+ }
24
+ return [];
25
+ },
26
+ enterJsx(path) {
27
+ const tag = (0, utils_1.getTag)(path);
28
+ if (tag === 'table')
29
+ stack.push({ found: false });
30
+ if (tag === 'caption' && stack.length)
31
+ stack[stack.length - 1].found = true;
32
+ return [];
33
+ },
34
+ exitJsx(path) {
35
+ var _a, _b, _c, _d;
36
+ const tag = (0, utils_1.getTag)(path);
37
+ if (tag === 'table') {
38
+ const entry = stack.pop();
39
+ if (entry && !entry.found) {
40
+ const line = ((_b = (_a = path.node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
41
+ const column = (_d = (_c = path.node.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
42
+ return [{ line, column, message: '<table> missing <caption>', rule: 'requireTableCaption' }];
43
+ }
44
+ }
45
+ return [];
46
+ },
47
+ };
48
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = singleH1;
4
+ const utils_1 = require("./utils");
5
+ function singleH1() {
6
+ let count = 0;
7
+ return {
8
+ name: 'singleH1',
9
+ init() { count = 0; },
10
+ enterHtml(node) {
11
+ if (node.type === 'element' && node.tagName === 'h1') {
12
+ count++;
13
+ if (count > 1) {
14
+ return [{ line: 0, column: 0, message: 'Only one <h1> allowed per document', rule: 'singleH1' }];
15
+ }
16
+ }
17
+ return [];
18
+ },
19
+ enterJsx(path) {
20
+ var _a, _b, _c, _d;
21
+ const tag = (0, utils_1.getTag)(path);
22
+ if (tag === 'h1') {
23
+ count++;
24
+ if (count > 1) {
25
+ const line = ((_b = (_a = path.node.openingElement.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
26
+ const column = (_d = (_c = path.node.openingElement.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
27
+ return [{ line, column, message: 'Only one <h1> allowed per document', rule: 'singleH1' }];
28
+ }
29
+ }
30
+ return [];
31
+ },
32
+ };
33
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = uniqueIds;
4
+ const utils_1 = require("./utils");
5
+ function uniqueIds() {
6
+ const ids = new Set();
7
+ return {
8
+ name: 'uniqueIds',
9
+ enterHtml(node) {
10
+ if (node.type === 'element' && node.attrs.id) {
11
+ const id = String(node.attrs.id);
12
+ if (ids.has(id)) {
13
+ return [{ line: 0, column: 0, message: `Duplicate id "${id}"`, rule: 'uniqueIds' }];
14
+ }
15
+ ids.add(id);
16
+ }
17
+ return [];
18
+ },
19
+ enterJsx(path) {
20
+ var _a, _b, _c, _d;
21
+ const id = (0, utils_1.getJsxAttr)(path.node.openingElement, 'id');
22
+ if (id) {
23
+ if (ids.has(id)) {
24
+ const line = ((_b = (_a = path.node.openingElement.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
25
+ const column = (_d = (_c = path.node.openingElement.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
26
+ return [{ line, column, message: `Duplicate id "${id}"`, rule: 'uniqueIds' }];
27
+ }
28
+ ids.add(id);
29
+ }
30
+ return [];
31
+ },
32
+ };
33
+ }