@markuplint/rules 2.4.3 → 3.0.0-alpha.1

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.
Files changed (118) hide show
  1. package/README.md +2 -6
  2. package/lib/attr-check.js +1 -1
  3. package/lib/attr-duplication/index.js +10 -7
  4. package/lib/attr-value-quotes/index.js +22 -26
  5. package/lib/case-sensitive-attr-name/index.d.ts +1 -5
  6. package/lib/case-sensitive-attr-name/index.js +52 -82
  7. package/lib/case-sensitive-tag-name/index.js +39 -31
  8. package/lib/character-reference/index.d.ts +2 -1
  9. package/lib/character-reference/index.js +6 -8
  10. package/lib/class-naming/index.js +12 -12
  11. package/lib/create-message.d.ts +1 -1
  12. package/lib/create-message.js +5 -5
  13. package/lib/deprecated-attr/index.js +17 -18
  14. package/lib/deprecated-element/index.js +5 -7
  15. package/lib/disallowed-element/index.js +8 -9
  16. package/lib/doctype/index.d.ts +1 -1
  17. package/lib/doctype/index.js +8 -8
  18. package/lib/end-tag/index.js +5 -2
  19. package/lib/helpers.d.ts +15 -28
  20. package/lib/helpers.js +42 -156
  21. package/lib/id-duplication/index.js +4 -6
  22. package/lib/index.d.ts +12 -21
  23. package/lib/index.js +0 -8
  24. package/lib/ineffective-attr/index.js +20 -28
  25. package/lib/invalid-attr/index.js +83 -83
  26. package/lib/landmark-roles/index.d.ts +2 -2
  27. package/lib/landmark-roles/index.js +10 -10
  28. package/lib/no-boolean-attr-value/index.js +34 -35
  29. package/lib/no-default-value/index.js +21 -25
  30. package/lib/no-hard-code-id/index.js +10 -14
  31. package/lib/no-refer-to-non-existent-id/index.d.ts +4 -1
  32. package/lib/no-refer-to-non-existent-id/index.js +77 -83
  33. package/lib/no-use-event-handler-attr/index.js +21 -23
  34. package/lib/permitted-contents/choice.d.ts +3 -0
  35. package/lib/permitted-contents/choice.js +37 -0
  36. package/lib/permitted-contents/complex-branch.d.ts +13 -0
  37. package/lib/permitted-contents/complex-branch.js +27 -0
  38. package/lib/permitted-contents/content-model.d.ts +2 -0
  39. package/lib/permitted-contents/content-model.js +49 -0
  40. package/lib/permitted-contents/count-pattern.d.ts +13 -0
  41. package/lib/permitted-contents/count-pattern.js +155 -0
  42. package/lib/permitted-contents/debug.d.ts +2 -0
  43. package/lib/permitted-contents/debug.js +5 -0
  44. package/lib/permitted-contents/index.d.ts +2 -5
  45. package/lib/permitted-contents/index.js +78 -249
  46. package/lib/permitted-contents/matches-selector.d.ts +3 -0
  47. package/lib/permitted-contents/matches-selector.js +185 -0
  48. package/lib/permitted-contents/order.d.ts +13 -0
  49. package/lib/permitted-contents/order.js +89 -0
  50. package/lib/permitted-contents/recursive-branch.d.ts +4 -0
  51. package/lib/permitted-contents/recursive-branch.js +43 -0
  52. package/lib/permitted-contents/represent-transparent-nodes.d.ts +6 -0
  53. package/lib/permitted-contents/represent-transparent-nodes.js +79 -0
  54. package/lib/permitted-contents/start.d.ts +12 -0
  55. package/lib/permitted-contents/start.js +71 -0
  56. package/lib/permitted-contents/transparent.d.ts +2 -0
  57. package/lib/permitted-contents/transparent.js +34 -0
  58. package/lib/permitted-contents/types.d.ts +45 -0
  59. package/lib/permitted-contents/types.js +2 -0
  60. package/lib/permitted-contents/utils.d.ts +32 -0
  61. package/lib/permitted-contents/utils.js +184 -0
  62. package/lib/require-accessible-name/index.d.ts +5 -1
  63. package/lib/require-accessible-name/index.js +11 -4
  64. package/lib/required-attr/index.js +16 -25
  65. package/lib/required-element/index.d.ts +1 -1
  66. package/lib/required-element/index.js +6 -6
  67. package/lib/required-h1/index.d.ts +2 -2
  68. package/lib/required-h1/index.js +3 -3
  69. package/lib/use-list/index.js +2 -2
  70. package/lib/wai-aria/checkings/abstract-role.d.ts +3 -0
  71. package/lib/wai-aria/checkings/abstract-role.js +22 -0
  72. package/lib/wai-aria/checkings/default-value.d.ts +6 -0
  73. package/lib/wai-aria/checkings/default-value.js +17 -0
  74. package/lib/wai-aria/checkings/deprecated-props.d.ts +7 -0
  75. package/lib/wai-aria/checkings/deprecated-props.js +18 -0
  76. package/lib/wai-aria/checkings/disallowed-prop.d.ts +7 -0
  77. package/lib/wai-aria/checkings/disallowed-prop.js +22 -0
  78. package/lib/wai-aria/checkings/implicit-props.d.ts +7 -0
  79. package/lib/wai-aria/checkings/implicit-props.js +50 -0
  80. package/lib/wai-aria/checkings/implicit-role.d.ts +3 -0
  81. package/lib/wai-aria/checkings/implicit-role.js +21 -0
  82. package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +11 -0
  83. package/lib/wai-aria/checkings/interaction-in-hidden.js +47 -0
  84. package/lib/wai-aria/checkings/no-global-prop.d.ts +6 -0
  85. package/lib/wai-aria/checkings/no-global-prop.js +14 -0
  86. package/lib/wai-aria/checkings/non-existant-role.d.ts +3 -0
  87. package/lib/wai-aria/checkings/non-existant-role.js +28 -0
  88. package/lib/wai-aria/checkings/permitted-roles.d.ts +3 -0
  89. package/lib/wai-aria/checkings/permitted-roles.js +28 -0
  90. package/lib/wai-aria/checkings/presentational-children.d.ts +29 -0
  91. package/lib/wai-aria/checkings/presentational-children.js +60 -0
  92. package/lib/wai-aria/checkings/required-owned-elements.d.ts +11 -0
  93. package/lib/wai-aria/checkings/required-owned-elements.js +63 -0
  94. package/lib/wai-aria/checkings/required-prop.d.ts +9 -0
  95. package/lib/wai-aria/checkings/required-prop.js +27 -0
  96. package/lib/wai-aria/checkings/value.d.ts +7 -0
  97. package/lib/wai-aria/checkings/value.js +21 -0
  98. package/lib/wai-aria/index.d.ts +1 -8
  99. package/lib/wai-aria/index.js +66 -207
  100. package/lib/wai-aria/types.d.ts +13 -0
  101. package/lib/wai-aria/types.js +2 -0
  102. package/package.json +8 -7
  103. package/schema.json +0 -12
  104. package/tsconfig.tsbuildinfo +1 -1
  105. package/lib/attr-equal-space-after/index.d.ts +0 -3
  106. package/lib/attr-equal-space-after/index.js +0 -90
  107. package/lib/attr-equal-space-before/index.d.ts +0 -3
  108. package/lib/attr-equal-space-before/index.js +0 -90
  109. package/lib/attr-spacing/index.d.ts +0 -6
  110. package/lib/attr-spacing/index.js +0 -100
  111. package/lib/indentation/index.d.ts +0 -7
  112. package/lib/indentation/index.js +0 -208
  113. package/lib/permitted-contents/array.combination.d.ts +0 -1
  114. package/lib/permitted-contents/array.combination.js +0 -33
  115. package/lib/permitted-contents/permitted-content.spec-to-regexp.d.ts +0 -11
  116. package/lib/permitted-contents/permitted-content.spec-to-regexp.js +0 -225
  117. package/lib/permitted-contents/unfold-content-models-to-tags.d.ts +0 -2
  118. package/lib/permitted-contents/unfold-content-models-to-tags.js +0 -8
@@ -1,225 +0,0 @@
1
- "use strict";
2
- var _TagList_list;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const tslib_1 = require("tslib");
5
- const helpers_1 = require("../helpers");
6
- const array_combination_1 = tslib_1.__importDefault(require("./array.combination"));
7
- const unfold_content_models_to_tags_1 = tslib_1.__importDefault(require("./unfold-content-models-to-tags"));
8
- const ALL = '(?:<[^>]+>)?';
9
- const ___TRANSPARENT___ = '___TRANSPARENT___';
10
- const ___InTRANSPARENT = '___InTRANSPARENT';
11
- const CUSTOM_ELEMENT = `(?:<[a-z](?:${helpers_1.rePCENChar})*\\-(?:${helpers_1.rePCENChar})*>)`;
12
- class ExpGenerator {
13
- constructor(_id) {
14
- this._id = _id;
15
- this._idCounter = 0;
16
- }
17
- specToRegExp(contentRule, parentExp = null, ownNS = null) {
18
- if (contentRule === true) {
19
- return new RegExp(`^(?:${ALL})+$`);
20
- }
21
- if (contentRule === false) {
22
- return new RegExp('^$');
23
- }
24
- const parentPattern = parentExp ? parentExp.source.replace(/^\^|\$$/g, '') : ALL;
25
- const pattern = this._toPattern(contentRule, null, ownNS, 1, 1).replace(___TRANSPARENT___, () => `(?<TRANSPARENT_${this._id}${this._idCounter++}>${parentPattern})`);
26
- return new RegExp(`^${pattern}$`, 'i');
27
- }
28
- _toPattern(contentRule, ignore, ownNS, min, max) {
29
- if (isTarget(contentRule)) {
30
- return this._targetTags(contentRule, ignore, ownNS, min, max);
31
- }
32
- let notAllowedDescendantsNamedCapture = '';
33
- const exp = [];
34
- for (const nodeRule of contentRule) {
35
- let pattern = '';
36
- if (isRequiredContents(nodeRule)) {
37
- if (nodeRule.notAllowedDescendants) {
38
- notAllowedDescendantsNamedCapture = nodeRule.notAllowedDescendants
39
- .map(r => r.replace('#', '_'))
40
- .join('_');
41
- if (nodeRule.require === '#transparent') {
42
- notAllowedDescendantsNamedCapture += `${___InTRANSPARENT}`;
43
- }
44
- }
45
- pattern = this._targetTags(nodeRule.require, nodeRule.ignore || null, ownNS, nodeRule.min || 1, nodeRule.max || nodeRule.min || 1);
46
- }
47
- else if (isOptionalContents(nodeRule)) {
48
- if (nodeRule.notAllowedDescendants) {
49
- notAllowedDescendantsNamedCapture = nodeRule.notAllowedDescendants
50
- .map(r => r.replace('#', '_'))
51
- .join('_');
52
- if (nodeRule.optional === '#transparent') {
53
- notAllowedDescendantsNamedCapture += `${___InTRANSPARENT}`;
54
- }
55
- }
56
- pattern = this._targetTags(nodeRule.optional, nodeRule.ignore || null, ownNS, 0, nodeRule.max || 1);
57
- }
58
- else if (isOneOrMoreContents(nodeRule)) {
59
- if (nodeRule.notAllowedDescendants) {
60
- notAllowedDescendantsNamedCapture = nodeRule.notAllowedDescendants
61
- .map(r => r.replace('#', '_'))
62
- .join('_');
63
- if (nodeRule.oneOrMore === '#transparent') {
64
- notAllowedDescendantsNamedCapture += `${___InTRANSPARENT}`;
65
- }
66
- }
67
- pattern = this._toPattern(nodeRule.oneOrMore, nodeRule.ignore || null, ownNS, 1, nodeRule.max || Infinity);
68
- }
69
- else if (isZeroOrMoreContents(nodeRule)) {
70
- if (nodeRule.notAllowedDescendants) {
71
- notAllowedDescendantsNamedCapture = nodeRule.notAllowedDescendants
72
- .map(r => r.replace('#', '_'))
73
- .join('_');
74
- if (nodeRule.zeroOrMore === '#transparent') {
75
- notAllowedDescendantsNamedCapture += `${___InTRANSPARENT}`;
76
- }
77
- }
78
- pattern = this._toPattern(nodeRule.zeroOrMore, nodeRule.ignore || null, ownNS, 0, nodeRule.max || Infinity);
79
- }
80
- else if (isChoiceContents(nodeRule)) {
81
- pattern = `(?:${nodeRule.choice.map(choice => this._toPattern(choice, null, ownNS, 1, 1)).join('|')})`;
82
- }
83
- else if (isInterleaveContents(nodeRule)) {
84
- pattern = this._interleavePattern(nodeRule.interleave, ownNS);
85
- }
86
- exp.push(pattern);
87
- }
88
- const range = createRange(min, max);
89
- const c = notAllowedDescendantsNamedCapture
90
- ? `?<NAD_${this._id}${this._idCounter++}_${notAllowedDescendantsNamedCapture}>`
91
- : '?:';
92
- if (1 === exp.length && range === '') {
93
- if (notAllowedDescendantsNamedCapture) {
94
- return `(${c}${exp[0]})`;
95
- }
96
- return exp[0];
97
- }
98
- if (range === '') {
99
- if (notAllowedDescendantsNamedCapture) {
100
- return `(${c}${exp.join('')})`;
101
- }
102
- return exp.join('');
103
- }
104
- return `(${c}${exp.join('')})${range}`;
105
- }
106
- _interleavePattern(contents, ownNS) {
107
- const interleave = contents.map(content => this._toPattern(content, null, ownNS, 1, 1));
108
- const patterns = (0, array_combination_1.default)(interleave).map((pattern, i) => pattern.join('').replace(/(\(\?<[A-Z]+_)([0-9]+)_/g, ($0, $1, $2) => `${$1}${$2}${i}_`));
109
- return join(patterns);
110
- }
111
- _targetTags(target, ignore, ownNS, min, max) {
112
- const tagList = this._resolveTags(target, ownNS);
113
- const ignoreList = ignore ? this._resolveTags(ignore, ownNS) : null;
114
- if (ignoreList) {
115
- ignoreList.forEach(ignore => tagList.delete(ignore));
116
- }
117
- return join(Array.from(tagList), createRange(min, max));
118
- }
119
- _resolveTags(target, ownNS) {
120
- const list = Array.isArray(target) ? target : [target];
121
- const tagList = new TagList();
122
- for (const name of list) {
123
- if (name !== '#text' && name[0] === '#') {
124
- switch (name) {
125
- case '#transparent': {
126
- tagList.addPattern(___TRANSPARENT___);
127
- break;
128
- }
129
- case '#custom': {
130
- tagList.addPattern(CUSTOM_ELEMENT);
131
- break;
132
- }
133
- default: {
134
- const selectors = (0, unfold_content_models_to_tags_1.default)(name);
135
- const counter = this._idCounter++;
136
- selectors.forEach(selector => {
137
- if (selector === '#custom') {
138
- tagList.addPattern(CUSTOM_ELEMENT);
139
- return;
140
- }
141
- if (/]$/i.test(selector)) {
142
- const [, tagName] = /^([^[\]]+)\[[^\]]+\]$/.exec(selector) || [];
143
- // ACM = Attributes by content model
144
- const exp = `(?<ACM_${this._id}${counter}_${name.slice(1)}_${tagName}><${tagName}>)`;
145
- tagList.addPattern(exp);
146
- return;
147
- }
148
- tagList.addTag(selector, ownNS);
149
- });
150
- }
151
- }
152
- continue;
153
- }
154
- tagList.addTag(name, ownNS);
155
- }
156
- return tagList.result();
157
- }
158
- }
159
- exports.default = ExpGenerator;
160
- class TagList {
161
- constructor() {
162
- _TagList_list.set(this, new Set());
163
- }
164
- addPattern(pattern) {
165
- tslib_1.__classPrivateFieldGet(this, _TagList_list, "f").add(pattern);
166
- }
167
- addTag(tagNameOrSelector, ownNS) {
168
- if (ownNS) {
169
- tagNameOrSelector = tagNameOrSelector.replace(new RegExp(`^${ownNS}:`, 'i'), '');
170
- }
171
- tslib_1.__classPrivateFieldGet(this, _TagList_list, "f").add(`<${tagNameOrSelector}>`);
172
- }
173
- result() {
174
- return tslib_1.__classPrivateFieldGet(this, _TagList_list, "f");
175
- }
176
- }
177
- _TagList_list = new WeakMap();
178
- function isRequiredContents(contents) {
179
- return 'require' in contents;
180
- }
181
- function isOptionalContents(contents) {
182
- return 'optional' in contents;
183
- }
184
- function isOneOrMoreContents(contents) {
185
- return 'oneOrMore' in contents;
186
- }
187
- function isZeroOrMoreContents(contents) {
188
- return 'zeroOrMore' in contents;
189
- }
190
- function isChoiceContents(contents) {
191
- return 'choice' in contents;
192
- }
193
- function isInterleaveContents(contents) {
194
- return 'interleave' in contents;
195
- }
196
- function createRange(min, max) {
197
- let result = `{${min},${max}}`;
198
- switch (result) {
199
- case '{0,1}':
200
- result = '?';
201
- break;
202
- case '{1,1}':
203
- result = '';
204
- break;
205
- case '{0,Infinity}':
206
- result = '*';
207
- break;
208
- case '{1,Infinity}':
209
- result = '+';
210
- break;
211
- }
212
- return result;
213
- }
214
- function isTarget(contentRule) {
215
- if (typeof contentRule === 'string') {
216
- return true;
217
- }
218
- return contentRule.some((i) => typeof i === 'string');
219
- }
220
- function join(pattern, range = '') {
221
- if (1 === pattern.length && range === '') {
222
- return pattern[0];
223
- }
224
- return `(?:${pattern.join('|')})${range}`;
225
- }
@@ -1,2 +0,0 @@
1
- import type { ContentModel } from '@markuplint/ml-spec';
2
- export default function unfoldContentModelsToTags(contentModel: ContentModel): string[];
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const html_spec_1 = require("@markuplint/html-spec");
4
- function unfoldContentModelsToTags(contentModel) {
5
- const tags = html_spec_1.def['#contentModels'][contentModel];
6
- return tags && Array.isArray(tags) ? tags.sort() : [];
7
- }
8
- exports.default = unfoldContentModelsToTags;