zemdomu 1.1.1 → 1.1.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/out/linter.js +164 -138
- package/out/project-linter.js +87 -87
- package/out/rules/enforceListNesting.js +81 -78
- package/out/rules/noTabindexGreaterThanZero.js +33 -0
- package/out/rules/preventEmptyInlineTags.js +85 -83
- package/out/rules/requireLinkText.js +86 -86
- package/package.json +2 -2
package/out/linter.js
CHANGED
|
@@ -1,138 +1,164 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.lint = lint;
|
|
7
|
-
const simpleHtmlParser_1 = require("./simpleHtmlParser");
|
|
8
|
-
const parser_1 = require("@babel/parser");
|
|
9
|
-
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
10
|
-
const requireAltText_1 = __importDefault(require("./rules/requireAltText"));
|
|
11
|
-
const requireSectionHeading_1 = __importDefault(require("./rules/requireSectionHeading"));
|
|
12
|
-
const enforceHeadingOrder_1 = __importDefault(require("./rules/enforceHeadingOrder"));
|
|
13
|
-
const singleH1_1 = __importDefault(require("./rules/singleH1"));
|
|
14
|
-
const requireLabelForFormControls_1 = __importDefault(require("./rules/requireLabelForFormControls"));
|
|
15
|
-
const enforceListNesting_1 = __importDefault(require("./rules/enforceListNesting"));
|
|
16
|
-
const requireLinkText_1 = __importDefault(require("./rules/requireLinkText"));
|
|
17
|
-
const requireTableCaption_1 = __importDefault(require("./rules/requireTableCaption"));
|
|
18
|
-
const preventEmptyInlineTags_1 = __importDefault(require("./rules/preventEmptyInlineTags"));
|
|
19
|
-
const requireHrefOnAnchors_1 = __importDefault(require("./rules/requireHrefOnAnchors"));
|
|
20
|
-
const requireButtonText_1 = __importDefault(require("./rules/requireButtonText"));
|
|
21
|
-
const requireIframeTitle_1 = __importDefault(require("./rules/requireIframeTitle"));
|
|
22
|
-
const requireHtmlLang_1 = __importDefault(require("./rules/requireHtmlLang"));
|
|
23
|
-
const requireImageInputAlt_1 = __importDefault(require("./rules/requireImageInputAlt"));
|
|
24
|
-
const requireNavLinks_1 = __importDefault(require("./rules/requireNavLinks"));
|
|
25
|
-
const uniqueIds_1 = __importDefault(require("./rules/uniqueIds"));
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.lint = lint;
|
|
7
|
+
const simpleHtmlParser_1 = require("./simpleHtmlParser");
|
|
8
|
+
const parser_1 = require("@babel/parser");
|
|
9
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
10
|
+
const requireAltText_1 = __importDefault(require("./rules/requireAltText"));
|
|
11
|
+
const requireSectionHeading_1 = __importDefault(require("./rules/requireSectionHeading"));
|
|
12
|
+
const enforceHeadingOrder_1 = __importDefault(require("./rules/enforceHeadingOrder"));
|
|
13
|
+
const singleH1_1 = __importDefault(require("./rules/singleH1"));
|
|
14
|
+
const requireLabelForFormControls_1 = __importDefault(require("./rules/requireLabelForFormControls"));
|
|
15
|
+
const enforceListNesting_1 = __importDefault(require("./rules/enforceListNesting"));
|
|
16
|
+
const requireLinkText_1 = __importDefault(require("./rules/requireLinkText"));
|
|
17
|
+
const requireTableCaption_1 = __importDefault(require("./rules/requireTableCaption"));
|
|
18
|
+
const preventEmptyInlineTags_1 = __importDefault(require("./rules/preventEmptyInlineTags"));
|
|
19
|
+
const requireHrefOnAnchors_1 = __importDefault(require("./rules/requireHrefOnAnchors"));
|
|
20
|
+
const requireButtonText_1 = __importDefault(require("./rules/requireButtonText"));
|
|
21
|
+
const requireIframeTitle_1 = __importDefault(require("./rules/requireIframeTitle"));
|
|
22
|
+
const requireHtmlLang_1 = __importDefault(require("./rules/requireHtmlLang"));
|
|
23
|
+
const requireImageInputAlt_1 = __importDefault(require("./rules/requireImageInputAlt"));
|
|
24
|
+
const requireNavLinks_1 = __importDefault(require("./rules/requireNavLinks"));
|
|
25
|
+
const uniqueIds_1 = __importDefault(require("./rules/uniqueIds"));
|
|
26
|
+
const noTabindexGreaterThanZero_1 = __importDefault(require("./rules/noTabindexGreaterThanZero"));
|
|
27
|
+
const builtInRules = {
|
|
28
|
+
requireSectionHeading: requireSectionHeading_1.default,
|
|
29
|
+
enforceHeadingOrder: enforceHeadingOrder_1.default,
|
|
30
|
+
singleH1: singleH1_1.default,
|
|
31
|
+
requireAltText: requireAltText_1.default,
|
|
32
|
+
requireLabelForFormControls: requireLabelForFormControls_1.default,
|
|
33
|
+
enforceListNesting: enforceListNesting_1.default,
|
|
34
|
+
requireLinkText: requireLinkText_1.default,
|
|
35
|
+
requireTableCaption: requireTableCaption_1.default,
|
|
36
|
+
preventEmptyInlineTags: preventEmptyInlineTags_1.default,
|
|
37
|
+
requireHrefOnAnchors: requireHrefOnAnchors_1.default,
|
|
38
|
+
requireButtonText: requireButtonText_1.default,
|
|
39
|
+
requireIframeTitle: requireIframeTitle_1.default,
|
|
40
|
+
requireHtmlLang: requireHtmlLang_1.default,
|
|
41
|
+
requireImageInputAlt: requireImageInputAlt_1.default,
|
|
42
|
+
requireNavLinks: requireNavLinks_1.default,
|
|
43
|
+
uniqueIds: uniqueIds_1.default,
|
|
44
|
+
noTabindexGreaterThanZero: noTabindexGreaterThanZero_1.default,
|
|
45
|
+
};
|
|
46
|
+
const defaultOptions = {
|
|
47
|
+
rules: {
|
|
48
|
+
requireSectionHeading: true,
|
|
49
|
+
enforceHeadingOrder: true,
|
|
50
|
+
singleH1: true,
|
|
51
|
+
requireAltText: true,
|
|
52
|
+
requireLabelForFormControls: true,
|
|
53
|
+
enforceListNesting: true,
|
|
54
|
+
requireLinkText: true,
|
|
55
|
+
requireTableCaption: true,
|
|
56
|
+
preventEmptyInlineTags: true,
|
|
57
|
+
requireHrefOnAnchors: true,
|
|
58
|
+
requireButtonText: true,
|
|
59
|
+
requireIframeTitle: true,
|
|
60
|
+
requireHtmlLang: true,
|
|
61
|
+
requireImageInputAlt: true,
|
|
62
|
+
requireNavLinks: true,
|
|
63
|
+
uniqueIds: true,
|
|
64
|
+
noTabindexGreaterThanZero: true,
|
|
65
|
+
},
|
|
66
|
+
customRules: [],
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Lint HTML/JSX/TSX content.
|
|
70
|
+
*/
|
|
71
|
+
function lint(content, options = defaultOptions) {
|
|
72
|
+
var _a;
|
|
73
|
+
const opts = {
|
|
74
|
+
rules: { ...defaultOptions.rules, ...(options.rules || {}) },
|
|
75
|
+
customRules: (_a = options.customRules) !== null && _a !== void 0 ? _a : defaultOptions.customRules,
|
|
76
|
+
};
|
|
77
|
+
const results = [];
|
|
78
|
+
const activeRules = [];
|
|
79
|
+
for (const name in opts.rules) {
|
|
80
|
+
const enabled = opts.rules[name];
|
|
81
|
+
if (enabled && builtInRules[name]) {
|
|
82
|
+
activeRules.push(builtInRules[name]());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (opts.customRules)
|
|
86
|
+
activeRules.push(...opts.customRules);
|
|
87
|
+
activeRules.forEach(r => r.init && r.init());
|
|
88
|
+
let ast = null;
|
|
89
|
+
try {
|
|
90
|
+
ast = (0, parser_1.parse)(content, {
|
|
91
|
+
sourceType: 'module',
|
|
92
|
+
plugins: ['typescript', 'jsx'],
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
ast = null;
|
|
97
|
+
}
|
|
98
|
+
if (ast) {
|
|
99
|
+
(0, traverse_1.default)(ast, {
|
|
100
|
+
JSXElement: {
|
|
101
|
+
enter(path) {
|
|
102
|
+
var _a;
|
|
103
|
+
for (const rule of activeRules) {
|
|
104
|
+
if (rule.enterJsx) {
|
|
105
|
+
try {
|
|
106
|
+
results.push(...rule.enterJsx(path));
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
console.error(`[ZemDomu] Error in rule ${rule.name} (${(_a = opts.filePath) !== null && _a !== void 0 ? _a : 'unknown'}):`, e);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
exit(path) {
|
|
115
|
+
var _a;
|
|
116
|
+
for (const rule of activeRules) {
|
|
117
|
+
if (rule.exitJsx) {
|
|
118
|
+
try {
|
|
119
|
+
results.push(...rule.exitJsx(path));
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
console.error(`[ZemDomu] Error in rule ${rule.name} (${(_a = opts.filePath) !== null && _a !== void 0 ? _a : 'unknown'}):`, e);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
activeRules.forEach(r => r.end && results.push(...r.end()));
|
|
130
|
+
return results;
|
|
131
|
+
}
|
|
132
|
+
const root = (0, simpleHtmlParser_1.parse)(content);
|
|
133
|
+
const walk = (node) => {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
for (const rule of activeRules) {
|
|
136
|
+
if (rule.enterHtml) {
|
|
137
|
+
try {
|
|
138
|
+
results.push(...rule.enterHtml(node));
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
console.error(`[ZemDomu] Error in rule ${rule.name} (${(_a = opts.filePath) !== null && _a !== void 0 ? _a : 'unknown'}):`, e);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (node.children) {
|
|
146
|
+
for (const child of node.children) {
|
|
147
|
+
walk(child);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
for (const rule of activeRules) {
|
|
151
|
+
if (rule.exitHtml) {
|
|
152
|
+
try {
|
|
153
|
+
results.push(...rule.exitHtml(node));
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
console.error(`[ZemDomu] Error in rule ${rule.name} (${(_b = opts.filePath) !== null && _b !== void 0 ? _b : 'unknown'}):`, e);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
walk(root);
|
|
162
|
+
activeRules.forEach(r => r.end && results.push(...r.end()));
|
|
163
|
+
return results;
|
|
164
|
+
}
|
package/out/project-linter.js
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
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.ProjectLinter = void 0;
|
|
37
|
-
const fs = __importStar(require("fs/promises"));
|
|
38
|
-
const linter_1 = require("./linter");
|
|
39
|
-
const component_analyzer_1 = require("./component-analyzer");
|
|
40
|
-
class ProjectLinter {
|
|
41
|
-
constructor(options = {}) {
|
|
42
|
-
this.opts = options;
|
|
43
|
-
this.analyzer = new component_analyzer_1.ComponentAnalyzer(this.opts);
|
|
44
|
-
}
|
|
45
|
-
clear() {
|
|
46
|
-
this.analyzer = new component_analyzer_1.ComponentAnalyzer(this.opts);
|
|
47
|
-
}
|
|
48
|
-
async lintFile(filePath, content) {
|
|
49
|
-
if (!content) {
|
|
50
|
-
content = await fs.readFile(filePath, 'utf8');
|
|
51
|
-
}
|
|
52
|
-
const results = (0, linter_1.lint)(content, this.opts);
|
|
53
|
-
const byFile = new Map();
|
|
54
|
-
byFile.set(filePath, [...results]);
|
|
55
|
-
const xmlMode = /\.(jsx|tsx)$/.test(filePath);
|
|
56
|
-
if (xmlMode) {
|
|
57
|
-
const component = await this.analyzer.analyzeFile(filePath);
|
|
58
|
-
if (component) {
|
|
59
|
-
this.analyzer.registerComponent(component, results);
|
|
60
|
-
}
|
|
61
|
-
if (this.opts.crossComponentAnalysis) {
|
|
62
|
-
const cross = this.analyzer.analyzeComponentTree();
|
|
63
|
-
for (const r of cross) {
|
|
64
|
-
if (!r.filePath)
|
|
65
|
-
continue;
|
|
66
|
-
if (!byFile.has(r.filePath))
|
|
67
|
-
byFile.set(r.filePath, []);
|
|
68
|
-
byFile.get(r.filePath).push(r);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return byFile;
|
|
73
|
-
}
|
|
74
|
-
async lintFiles(filePaths) {
|
|
75
|
-
const aggregated = new Map();
|
|
76
|
-
for (const filePath of filePaths) {
|
|
77
|
-
const fileMap = await this.lintFile(filePath);
|
|
78
|
-
for (const [fp, res] of fileMap.entries()) {
|
|
79
|
-
if (!aggregated.has(fp))
|
|
80
|
-
aggregated.set(fp, []);
|
|
81
|
-
aggregated.get(fp).push(...res);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return aggregated;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.ProjectLinter = ProjectLinter;
|
|
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.ProjectLinter = void 0;
|
|
37
|
+
const fs = __importStar(require("fs/promises"));
|
|
38
|
+
const linter_1 = require("./linter");
|
|
39
|
+
const component_analyzer_1 = require("./component-analyzer");
|
|
40
|
+
class ProjectLinter {
|
|
41
|
+
constructor(options = {}) {
|
|
42
|
+
this.opts = options;
|
|
43
|
+
this.analyzer = new component_analyzer_1.ComponentAnalyzer(this.opts);
|
|
44
|
+
}
|
|
45
|
+
clear() {
|
|
46
|
+
this.analyzer = new component_analyzer_1.ComponentAnalyzer(this.opts);
|
|
47
|
+
}
|
|
48
|
+
async lintFile(filePath, content) {
|
|
49
|
+
if (!content) {
|
|
50
|
+
content = await fs.readFile(filePath, 'utf8');
|
|
51
|
+
}
|
|
52
|
+
const results = (0, linter_1.lint)(content, { ...this.opts, filePath });
|
|
53
|
+
const byFile = new Map();
|
|
54
|
+
byFile.set(filePath, [...results]);
|
|
55
|
+
const xmlMode = /\.(jsx|tsx)$/.test(filePath);
|
|
56
|
+
if (xmlMode) {
|
|
57
|
+
const component = await this.analyzer.analyzeFile(filePath);
|
|
58
|
+
if (component) {
|
|
59
|
+
this.analyzer.registerComponent(component, results);
|
|
60
|
+
}
|
|
61
|
+
if (this.opts.crossComponentAnalysis) {
|
|
62
|
+
const cross = this.analyzer.analyzeComponentTree();
|
|
63
|
+
for (const r of cross) {
|
|
64
|
+
if (!r.filePath)
|
|
65
|
+
continue;
|
|
66
|
+
if (!byFile.has(r.filePath))
|
|
67
|
+
byFile.set(r.filePath, []);
|
|
68
|
+
byFile.get(r.filePath).push(r);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return byFile;
|
|
73
|
+
}
|
|
74
|
+
async lintFiles(filePaths) {
|
|
75
|
+
const aggregated = new Map();
|
|
76
|
+
for (const filePath of filePaths) {
|
|
77
|
+
const fileMap = await this.lintFile(filePath);
|
|
78
|
+
for (const [fp, res] of fileMap.entries()) {
|
|
79
|
+
if (!aggregated.has(fp))
|
|
80
|
+
aggregated.set(fp, []);
|
|
81
|
+
aggregated.get(fp).push(...res);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return aggregated;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.ProjectLinter = ProjectLinter;
|
|
@@ -1,78 +1,81 @@
|
|
|
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 = enforceListNesting;
|
|
37
|
-
const t = __importStar(require("@babel/types"));
|
|
38
|
-
const utils_1 = require("./utils");
|
|
39
|
-
function enforceListNesting() {
|
|
40
|
-
const stack = [];
|
|
41
|
-
return {
|
|
42
|
-
name: 'enforceListNesting',
|
|
43
|
-
enterHtml(node) {
|
|
44
|
-
if (node.type === 'element') {
|
|
45
|
-
stack.push(node.tagName);
|
|
46
|
-
if (node.tagName === 'li') {
|
|
47
|
-
const parent = stack[stack.length - 2];
|
|
48
|
-
if (!parent || !['ul', 'ol'].includes(parent)) {
|
|
49
|
-
return [{ line: 0, column: 0, message: '<li> must be inside a <ul> or <ol>', rule: 'enforceListNesting' }];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return [];
|
|
54
|
-
},
|
|
55
|
-
exitHtml(node) {
|
|
56
|
-
if (node.type === 'element') {
|
|
57
|
-
stack.pop();
|
|
58
|
-
}
|
|
59
|
-
return [];
|
|
60
|
-
},
|
|
61
|
-
enterJsx(path) {
|
|
62
|
-
var _a, _b, _c, _d, _e, _f;
|
|
63
|
-
const tag = (0, utils_1.getTag)(path);
|
|
64
|
-
if (tag === 'li') {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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 = enforceListNesting;
|
|
37
|
+
const t = __importStar(require("@babel/types"));
|
|
38
|
+
const utils_1 = require("./utils");
|
|
39
|
+
function enforceListNesting() {
|
|
40
|
+
const stack = [];
|
|
41
|
+
return {
|
|
42
|
+
name: 'enforceListNesting',
|
|
43
|
+
enterHtml(node) {
|
|
44
|
+
if (node.type === 'element') {
|
|
45
|
+
stack.push(node.tagName);
|
|
46
|
+
if (node.tagName === 'li') {
|
|
47
|
+
const parent = stack[stack.length - 2];
|
|
48
|
+
if (!parent || !['ul', 'ol'].includes(parent)) {
|
|
49
|
+
return [{ line: 0, column: 0, message: '<li> must be inside a <ul> or <ol>', rule: 'enforceListNesting' }];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return [];
|
|
54
|
+
},
|
|
55
|
+
exitHtml(node) {
|
|
56
|
+
if (node.type === 'element') {
|
|
57
|
+
stack.pop();
|
|
58
|
+
}
|
|
59
|
+
return [];
|
|
60
|
+
},
|
|
61
|
+
enterJsx(path) {
|
|
62
|
+
var _a, _b, _c, _d, _e, _f;
|
|
63
|
+
const tag = (0, utils_1.getTag)(path);
|
|
64
|
+
if (tag === 'li') {
|
|
65
|
+
const parentNode = (_b = (_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.parentPath) === null || _b === void 0 ? void 0 : _b.node;
|
|
66
|
+
let inList = false;
|
|
67
|
+
if (parentNode && t.isJSXElement(parentNode)) {
|
|
68
|
+
const open = parentNode.openingElement;
|
|
69
|
+
const pTag = t.isJSXIdentifier(open.name) ? open.name.name.toLowerCase() : '';
|
|
70
|
+
inList = ['ul', 'ol'].includes(pTag);
|
|
71
|
+
}
|
|
72
|
+
if (!inList) {
|
|
73
|
+
const line = ((_d = (_c = path.node.loc) === null || _c === void 0 ? void 0 : _c.start.line) !== null && _d !== void 0 ? _d : 1) - 1;
|
|
74
|
+
const column = (_f = (_e = path.node.loc) === null || _e === void 0 ? void 0 : _e.start.column) !== null && _f !== void 0 ? _f : 0;
|
|
75
|
+
return [{ line, column, message: '<li> must be inside a <ul> or <ol>', rule: 'enforceListNesting' }];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return [];
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = noTabindexGreaterThanZero;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
function noTabindexGreaterThanZero() {
|
|
6
|
+
const message = 'Tabindex greater than 0 should be avoided';
|
|
7
|
+
return {
|
|
8
|
+
name: 'noTabindexGreaterThanZero',
|
|
9
|
+
enterHtml(node) {
|
|
10
|
+
if (node.type === 'element' && node.attrs.tabindex !== undefined) {
|
|
11
|
+
const value = Number(node.attrs.tabindex);
|
|
12
|
+
if (!Number.isNaN(value) && value > 0) {
|
|
13
|
+
return [{ line: 0, column: 0, message, rule: 'noTabindexGreaterThanZero' }];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return [];
|
|
17
|
+
},
|
|
18
|
+
enterJsx(path) {
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
|
+
const opening = path.node.openingElement;
|
|
21
|
+
const tabindex = (0, utils_1.getJsxAttr)(opening, 'tabindex');
|
|
22
|
+
if (tabindex !== undefined) {
|
|
23
|
+
const value = Number(tabindex);
|
|
24
|
+
if (!Number.isNaN(value) && value > 0) {
|
|
25
|
+
const line = ((_b = (_a = opening.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 1) - 1;
|
|
26
|
+
const column = (_d = (_c = opening.loc) === null || _c === void 0 ? void 0 : _c.start.column) !== null && _d !== void 0 ? _d : 0;
|
|
27
|
+
return [{ line, column, message, rule: 'noTabindexGreaterThanZero' }];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return [];
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,83 +1,85 @@
|
|
|
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 = preventEmptyInlineTags;
|
|
37
|
-
const t = __importStar(require("@babel/types"));
|
|
38
|
-
const utils_1 = require("./utils");
|
|
39
|
-
const inlineTags = new Set(['strong', 'em', 'b', 'i', 'u', 'small', 'mark', 'del', 'ins']);
|
|
40
|
-
function preventEmptyInlineTags() {
|
|
41
|
-
const stack = [];
|
|
42
|
-
return {
|
|
43
|
-
name: 'preventEmptyInlineTags',
|
|
44
|
-
enterHtml(node) {
|
|
45
|
-
if (node.type === 'element' && inlineTags.has(node.tagName)) {
|
|
46
|
-
stack.push({ tag: node.tagName, found: false });
|
|
47
|
-
}
|
|
48
|
-
else if (node.type === 'text') {
|
|
49
|
-
if (stack.length && node.text.trim())
|
|
50
|
-
stack[stack.length - 1].found = true;
|
|
51
|
-
}
|
|
52
|
-
return [];
|
|
53
|
-
},
|
|
54
|
-
exitHtml(node) {
|
|
55
|
-
if (node.type === 'element' && inlineTags.has(node.tagName)) {
|
|
56
|
-
const e = stack.pop();
|
|
57
|
-
if (e && !e.found)
|
|
58
|
-
return [{ line: 0, column: 0, message: `<${e.tag}> tag should not be empty`, rule: 'preventEmptyInlineTags' }];
|
|
59
|
-
}
|
|
60
|
-
return [];
|
|
61
|
-
},
|
|
62
|
-
enterJsx(path) {
|
|
63
|
-
const tag = (0, utils_1.getTag)(path);
|
|
64
|
-
if (inlineTags.has(tag))
|
|
65
|
-
stack.push({ tag, found: false });
|
|
66
|
-
return [];
|
|
67
|
-
},
|
|
68
|
-
exitJsx(path) {
|
|
69
|
-
var _a, _b, _c, _d, _e;
|
|
70
|
-
const tag = (0, utils_1.getTag)(path);
|
|
71
|
-
if (inlineTags.has(tag)) {
|
|
72
|
-
const e = stack.pop();
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
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 = preventEmptyInlineTags;
|
|
37
|
+
const t = __importStar(require("@babel/types"));
|
|
38
|
+
const utils_1 = require("./utils");
|
|
39
|
+
const inlineTags = new Set(['strong', 'em', 'b', 'i', 'u', 'small', 'mark', 'del', 'ins']);
|
|
40
|
+
function preventEmptyInlineTags() {
|
|
41
|
+
const stack = [];
|
|
42
|
+
return {
|
|
43
|
+
name: 'preventEmptyInlineTags',
|
|
44
|
+
enterHtml(node) {
|
|
45
|
+
if (node.type === 'element' && inlineTags.has(node.tagName)) {
|
|
46
|
+
stack.push({ tag: node.tagName, found: false });
|
|
47
|
+
}
|
|
48
|
+
else if (node.type === 'text') {
|
|
49
|
+
if (stack.length && node.text.trim())
|
|
50
|
+
stack[stack.length - 1].found = true;
|
|
51
|
+
}
|
|
52
|
+
return [];
|
|
53
|
+
},
|
|
54
|
+
exitHtml(node) {
|
|
55
|
+
if (node.type === 'element' && inlineTags.has(node.tagName)) {
|
|
56
|
+
const e = stack.pop();
|
|
57
|
+
if (e && !e.found)
|
|
58
|
+
return [{ line: 0, column: 0, message: `<${e.tag}> tag should not be empty`, rule: 'preventEmptyInlineTags' }];
|
|
59
|
+
}
|
|
60
|
+
return [];
|
|
61
|
+
},
|
|
62
|
+
enterJsx(path) {
|
|
63
|
+
const tag = (0, utils_1.getTag)(path);
|
|
64
|
+
if (inlineTags.has(tag))
|
|
65
|
+
stack.push({ tag, found: false });
|
|
66
|
+
return [];
|
|
67
|
+
},
|
|
68
|
+
exitJsx(path) {
|
|
69
|
+
var _a, _b, _c, _d, _e;
|
|
70
|
+
const tag = (0, utils_1.getTag)(path);
|
|
71
|
+
if (inlineTags.has(tag)) {
|
|
72
|
+
const e = stack.pop();
|
|
73
|
+
const parentNode = (_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.node;
|
|
74
|
+
const hasText = t.isJSXElement(parentNode) &&
|
|
75
|
+
parentNode.children.some(c => (t.isJSXText(c) && c.value.trim()) || t.isJSXExpressionContainer(c));
|
|
76
|
+
if (e && !(e.found || hasText)) {
|
|
77
|
+
const line = ((_c = (_b = path.node.loc) === null || _b === void 0 ? void 0 : _b.start.line) !== null && _c !== void 0 ? _c : 1) - 1;
|
|
78
|
+
const column = (_e = (_d = path.node.loc) === null || _d === void 0 ? void 0 : _d.start.column) !== null && _e !== void 0 ? _e : 0;
|
|
79
|
+
return [{ line, column, message: `<${tag}> tag should not be empty`, rule: 'preventEmptyInlineTags' }];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return [];
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -1,86 +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
|
|
74
|
-
if (
|
|
75
|
-
hasText =
|
|
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
|
-
}
|
|
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 parentNode = (_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.node;
|
|
74
|
+
if (t.isJSXElement(parentNode) && Array.isArray(parentNode.children)) {
|
|
75
|
+
hasText = parentNode.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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zemdomu",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Hello",
|
|
5
5
|
"main": "./out/index.js",
|
|
6
6
|
"files": [
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc -p tsconfig.json",
|
|
12
12
|
"compile": "tsc -p tsconfig.json",
|
|
13
|
-
"test": "npm run compile && node tests/unique-ids.test.js && node tests/label-form-control.test.js && node tests/cross-component.test.js && node tests/heading-order.test.js && node tests/prevent-empty-inline.test.js && node tests/section-heading.test.js && node tests/img-alt.test.js && node tests/button-accessibility.test.js && node tests/html-lang.test.js && node tests/table-caption.test.js && node tests/all-rules.test.js"
|
|
13
|
+
"test": "npm run compile && node tests/unique-ids.test.js && node tests/label-form-control.test.js && node tests/cross-component.test.js && node tests/heading-order.test.js && node tests/prevent-empty-inline.test.js && node tests/section-heading.test.js && node tests/img-alt.test.js && node tests/button-accessibility.test.js && node tests/html-lang.test.js && node tests/tabindex.test.js && node tests/table-caption.test.js && node tests/all-rules.test.js && node tests/robustness.test.js"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [],
|
|
16
16
|
"author": "",
|