@markuplint/rules 3.0.0-canary.3 → 3.0.0-dev.177

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 (163) hide show
  1. package/README.md +1 -1
  2. package/lib/attr-check.d.ts +20 -8
  3. package/lib/attr-check.js +31 -22
  4. package/lib/attr-duplication/index.d.ts +3 -1
  5. package/lib/attr-duplication/index.js +2 -1
  6. package/lib/attr-value-quotes/index.d.ts +2 -2
  7. package/lib/case-sensitive-attr-name/index.d.ts +1 -1
  8. package/lib/case-sensitive-tag-name/index.d.ts +1 -1
  9. package/lib/character-reference/index.d.ts +1 -1
  10. package/lib/class-naming/index.d.ts +1 -1
  11. package/lib/class-naming/index.js +2 -4
  12. package/lib/create-message.d.ts +13 -2
  13. package/lib/create-message.js +4 -3
  14. package/lib/debug.js +1 -1
  15. package/lib/deprecated-attr/index.d.ts +3 -1
  16. package/lib/deprecated-element/index.d.ts +3 -1
  17. package/lib/deprecated-element/index.js +2 -2
  18. package/lib/disallowed-element/index.d.ts +1 -1
  19. package/lib/doctype/index.d.ts +2 -2
  20. package/lib/end-tag/index.d.ts +1 -1
  21. package/lib/helpers.d.ts +37 -22
  22. package/lib/helpers.js +27 -14
  23. package/lib/id-duplication/index.d.ts +3 -1
  24. package/lib/index.d.ts +243 -3
  25. package/lib/index.js +6 -1
  26. package/lib/ineffective-attr/index.d.ts +3 -1
  27. package/lib/ineffective-attr/index.js +2 -5
  28. package/lib/invalid-attr/index.d.ts +39 -12
  29. package/lib/invalid-attr/index.js +153 -27
  30. package/lib/label-has-control/index.d.ts +3 -1
  31. package/lib/landmark-roles/index.d.ts +3 -3
  32. package/lib/landmark-roles/index.js +9 -5
  33. package/lib/no-boolean-attr-value/index.d.ts +3 -1
  34. package/lib/no-default-value/index.d.ts +3 -1
  35. package/lib/no-empty-palpable-content/index.d.ts +3 -3
  36. package/lib/no-empty-palpable-content/index.js +11 -3
  37. package/lib/no-hard-code-id/index.d.ts +3 -1
  38. package/lib/no-refer-to-non-existent-id/index.d.ts +9 -4
  39. package/lib/no-refer-to-non-existent-id/index.js +65 -5
  40. package/lib/no-use-event-handler-attr/index.d.ts +2 -2
  41. package/lib/no-use-event-handler-attr/index.js +4 -4
  42. package/lib/permitted-contents/choice.d.ts +8 -1
  43. package/lib/permitted-contents/choice.js +37 -2
  44. package/lib/permitted-contents/complex-branch.d.ts +8 -1
  45. package/lib/permitted-contents/complex-branch.js +4 -2
  46. package/lib/permitted-contents/content-model.d.ts +1 -1
  47. package/lib/permitted-contents/content-model.js +7 -3
  48. package/lib/permitted-contents/count-pattern.d.ts +18 -2
  49. package/lib/permitted-contents/count-pattern.js +71 -64
  50. package/lib/permitted-contents/debug.browser.d.ts +30 -0
  51. package/lib/permitted-contents/debug.browser.js +14 -0
  52. package/lib/permitted-contents/debug.d.ts +2 -1
  53. package/lib/permitted-contents/debug.js +9 -1
  54. package/lib/permitted-contents/index.d.ts +1 -1
  55. package/lib/permitted-contents/index.js +12 -15
  56. package/lib/permitted-contents/matches-selector.d.ts +7 -2
  57. package/lib/permitted-contents/matches-selector.js +8 -6
  58. package/lib/permitted-contents/order.d.ts +8 -1
  59. package/lib/permitted-contents/order.js +25 -15
  60. package/lib/permitted-contents/recursive-branch.d.ts +8 -1
  61. package/lib/permitted-contents/recursive-branch.js +5 -3
  62. package/lib/permitted-contents/represent-transparent-nodes.d.ts +7 -3
  63. package/lib/permitted-contents/represent-transparent-nodes.js +4 -5
  64. package/lib/permitted-contents/start.d.ts +7 -1
  65. package/lib/permitted-contents/start.js +5 -3
  66. package/lib/permitted-contents/transparent.d.ts +2 -2
  67. package/lib/permitted-contents/transparent.js +11 -14
  68. package/lib/permitted-contents/types.d.ts +35 -28
  69. package/lib/permitted-contents/utils.d.ts +96 -28
  70. package/lib/permitted-contents/utils.js +135 -17
  71. package/lib/placeholder-label-option/index.d.ts +2 -0
  72. package/lib/placeholder-label-option/index.js +88 -0
  73. package/lib/require-accessible-name/index.d.ts +2 -2
  74. package/lib/require-accessible-name/index.js +5 -5
  75. package/lib/require-datetime/index.d.ts +6 -0
  76. package/lib/require-datetime/index.js +34 -0
  77. package/lib/require-datetime/types.d.ts +10 -0
  78. package/lib/require-datetime/types.js +2 -0
  79. package/lib/require-datetime/utils.d.ts +11 -0
  80. package/lib/require-datetime/utils.js +137 -0
  81. package/lib/required-attr/index.d.ts +3 -3
  82. package/lib/required-attr/index.js +19 -16
  83. package/lib/required-element/index.d.ts +2 -2
  84. package/lib/required-element/index.js +3 -2
  85. package/lib/required-h1/index.d.ts +3 -3
  86. package/lib/required-h1/index.js +4 -3
  87. package/lib/use-list/index.d.ts +3 -3
  88. package/lib/use-list/index.js +7 -5
  89. package/lib/wai-aria/checkings/_.d.ts +15 -0
  90. package/lib/wai-aria/checkings/_.js +27 -0
  91. package/lib/wai-aria/checkings/abstract-role.js +1 -1
  92. package/lib/wai-aria/checkings/default-value.d.ts +7 -3
  93. package/lib/wai-aria/checkings/deprecated-props.d.ts +8 -4
  94. package/lib/wai-aria/checkings/disallowed-prop.d.ts +8 -4
  95. package/lib/wai-aria/checkings/disallowed-prop.js +27 -3
  96. package/lib/wai-aria/checkings/implicit-props.d.ts +8 -4
  97. package/lib/wai-aria/checkings/implicit-props.js +3 -2
  98. package/lib/wai-aria/checkings/implicit-role.js +1 -1
  99. package/lib/wai-aria/checkings/interaction-in-hidden.js +3 -1
  100. package/lib/wai-aria/checkings/no-global-prop.d.ts +7 -3
  101. package/lib/wai-aria/checkings/non-existent-role.js +1 -1
  102. package/lib/wai-aria/checkings/permitted-roles.js +1 -1
  103. package/lib/wai-aria/checkings/presentational-children.js +4 -2
  104. package/lib/wai-aria/checkings/required-owned-elements.d.ts +7 -3
  105. package/lib/wai-aria/checkings/required-owned-elements.js +28 -12
  106. package/lib/wai-aria/checkings/required-prop copy.d.ts +15 -0
  107. package/lib/wai-aria/checkings/required-prop copy.js +27 -0
  108. package/lib/wai-aria/checkings/required-prop.d.ts +12 -6
  109. package/lib/wai-aria/checkings/unadopted-explicit-roles.d.ts +15 -0
  110. package/lib/wai-aria/checkings/unadopted-explicit-roles.js +17 -0
  111. package/lib/wai-aria/checkings/value.d.ts +15 -6
  112. package/lib/wai-aria/checkings/value.js +3 -1
  113. package/lib/wai-aria/index.d.ts +1 -1
  114. package/lib/wai-aria/index.js +13 -12
  115. package/lib/wai-aria/types.d.ts +10 -10
  116. package/lib/xxx/index.d.ts +2 -0
  117. package/lib/xxx/index.js +32 -0
  118. package/package.json +16 -11
  119. package/schema.json +6 -0
  120. package/test/attr-check.spec.js +77 -0
  121. package/test/attr-duplication/index.spec.js +159 -0
  122. package/test/attr-value-quotes/index.spec.js +133 -0
  123. package/test/case-sensitive-attr-name/index.spec.js +65 -0
  124. package/test/case-sensitive-tag-name/index.spec.js +80 -0
  125. package/test/character-reference/index.spec.js +57 -0
  126. package/test/class-naming/index.spec.js +470 -0
  127. package/test/create-message.spec.js +497 -0
  128. package/test/deprecated-attr/index.spec.js +48 -0
  129. package/test/deprecated-element/index.spec.js +48 -0
  130. package/test/disallowed-element/index.spec.js +90 -0
  131. package/test/doctype/index.spec.js +50 -0
  132. package/test/end-tag/index.spec.js +162 -0
  133. package/test/id-duplication/index.spec.js +47 -0
  134. package/test/ineffective-attr/index.spec.js +31 -0
  135. package/test/invalid-attr/index.spec.js +1632 -0
  136. package/test/label-has-control/index.spec.js +29 -0
  137. package/test/landmark-roles/index.spec.js +187 -0
  138. package/test/no-boolean-attr-value/index.spec.js +41 -0
  139. package/test/no-default-value/index.spec.js +74 -0
  140. package/test/no-empty-palpable-content/index.spec.js +115 -0
  141. package/test/no-hard-code-id/index.spec.js +100 -0
  142. package/test/no-refer-to-non-existent-id/index.spec.js +254 -0
  143. package/test/no-use-event-handler-attr/index.spec.js +57 -0
  144. package/test/permitted-contents/choice.spec.js +174 -0
  145. package/test/permitted-contents/count-pattern.spec.js +308 -0
  146. package/test/permitted-contents/index.spec.js +1371 -0
  147. package/test/permitted-contents/matches-selector.spec.js +59 -0
  148. package/test/permitted-contents/order.spec.js +351 -0
  149. package/test/permitted-contents/recursive-branch.spec.js +41 -0
  150. package/test/permitted-contents/represent-transparent-nodes.spec.js +24 -0
  151. package/test/permitted-contents/start.spec.js +67 -0
  152. package/test/placeholder-label-option/index.spec.js +113 -0
  153. package/test/require-accessible-name/index.spec.js +446 -0
  154. package/test/require-datetime/index.spec.js +54 -0
  155. package/test/require-datetime/utils.spec.js +52 -0
  156. package/test/required-attr/index.spec.js +414 -0
  157. package/test/required-element/index.spec.js +188 -0
  158. package/test/required-h1/index.spec.js +69 -0
  159. package/test/use-list/index.spec.js +109 -0
  160. package/test/wai-aria/checkings/value.spec.js +33 -0
  161. package/test/wai-aria/index.spec.js +1173 -0
  162. package/tsconfig.test.json +0 -3
  163. package/tsconfig.tsbuildinfo +0 -1
package/lib/index.d.ts CHANGED
@@ -1,3 +1,243 @@
1
- import type { AnyRuleSeed } from '@markuplint/ml-core';
2
- declare const _default: Record<string, AnyRuleSeed>;
3
- export default _default;
1
+ declare const rules: {
2
+ readonly 'attr-duplication': Readonly<
3
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
4
+ >;
5
+ readonly 'attr-value-quotes': Readonly<
6
+ import('@markuplint/ml-core').RuleSeed<import('./attr-value-quotes').Type, undefined>
7
+ >;
8
+ readonly 'case-sensitive-attr-name': Readonly<
9
+ import('@markuplint/ml-core').RuleSeed<import('./case-sensitive-attr-name').Value, undefined>
10
+ >;
11
+ readonly 'case-sensitive-tag-name': Readonly<
12
+ import('@markuplint/ml-core').RuleSeed<import('./case-sensitive-tag-name').Value, undefined>
13
+ >;
14
+ readonly 'character-reference': Readonly<
15
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
16
+ >;
17
+ readonly 'class-naming': Readonly<
18
+ import('@markuplint/ml-core').RuleSeed<import('./class-naming').Value, undefined>
19
+ >;
20
+ readonly 'deprecated-attr': Readonly<
21
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
22
+ >;
23
+ readonly 'deprecated-element': Readonly<
24
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
25
+ >;
26
+ readonly 'disallowed-element': Readonly<import('@markuplint/ml-core').RuleSeed<string[], undefined>>;
27
+ readonly doctype: Readonly<
28
+ import('@markuplint/ml-core').RuleSeed<
29
+ 'always',
30
+ {
31
+ denyObsoleteType: boolean;
32
+ }
33
+ >
34
+ >;
35
+ readonly 'end-tag': Readonly<import('@markuplint/ml-core').RuleSeed<boolean, undefined>>;
36
+ readonly 'id-duplication': Readonly<
37
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
38
+ >;
39
+ readonly 'ineffective-attr': Readonly<
40
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
41
+ >;
42
+ readonly 'invalid-attr': Readonly<
43
+ import('@markuplint/ml-core').RuleSeed<
44
+ boolean,
45
+ {
46
+ allowAttrs?:
47
+ | Record<
48
+ string,
49
+ | {
50
+ enum: [string, ...string[]];
51
+ }
52
+ | {
53
+ pattern: string;
54
+ }
55
+ | {
56
+ type: import('packages/@markuplint/ml-spec/lib').AttributeType;
57
+ }
58
+ >
59
+ | (
60
+ | string
61
+ | {
62
+ name: string;
63
+ value:
64
+ | import('packages/@markuplint/ml-spec/lib').AttributeType
65
+ | (
66
+ | {
67
+ enum: [string, ...string[]];
68
+ }
69
+ | {
70
+ pattern: string;
71
+ }
72
+ | {
73
+ type: import('packages/@markuplint/ml-spec/lib').AttributeType;
74
+ }
75
+ );
76
+ }
77
+ )[]
78
+ | undefined;
79
+ disallowAttrs?:
80
+ | Record<
81
+ string,
82
+ | {
83
+ enum: [string, ...string[]];
84
+ }
85
+ | {
86
+ pattern: string;
87
+ }
88
+ | {
89
+ type: import('packages/@markuplint/ml-spec/lib').AttributeType;
90
+ }
91
+ >
92
+ | (
93
+ | string
94
+ | {
95
+ name: string;
96
+ value:
97
+ | import('packages/@markuplint/ml-spec/lib').AttributeType
98
+ | (
99
+ | {
100
+ enum: [string, ...string[]];
101
+ }
102
+ | {
103
+ pattern: string;
104
+ }
105
+ | {
106
+ type: import('packages/@markuplint/ml-spec/lib').AttributeType;
107
+ }
108
+ );
109
+ }
110
+ )[]
111
+ | undefined;
112
+ ignoreAttrNamePrefix?: string | string[] | undefined;
113
+ allowToAddPropertiesForPretender?: boolean | undefined;
114
+ attrs?:
115
+ | Record<
116
+ string,
117
+ | (
118
+ | {
119
+ enum: [string, ...string[]];
120
+ }
121
+ | {
122
+ pattern: string;
123
+ }
124
+ | {
125
+ type: import('packages/@markuplint/ml-spec/lib').AttributeType;
126
+ }
127
+ )
128
+ | {
129
+ disallowed: true;
130
+ }
131
+ >
132
+ | undefined;
133
+ }
134
+ >
135
+ >;
136
+ readonly 'label-has-control': Readonly<
137
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
138
+ >;
139
+ readonly 'landmark-roles': Readonly<
140
+ import('@markuplint/ml-core').RuleSeed<
141
+ boolean,
142
+ {
143
+ ignoreRoles: (
144
+ | ('banner' | 'main' | 'complementary' | 'contentinfo')
145
+ | 'form'
146
+ | 'navigation'
147
+ | 'region'
148
+ )[];
149
+ labelEachArea: boolean;
150
+ }
151
+ >
152
+ >;
153
+ readonly 'no-boolean-attr-value': Readonly<
154
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
155
+ >;
156
+ readonly 'no-default-value': Readonly<
157
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
158
+ >;
159
+ readonly 'no-empty-palpable-content': Readonly<
160
+ import('@markuplint/ml-core').RuleSeed<
161
+ boolean,
162
+ {
163
+ extendsExposableElements?: boolean | undefined;
164
+ ignoreIfAriaBusy?: boolean | undefined;
165
+ }
166
+ >
167
+ >;
168
+ readonly 'no-hard-code-id': Readonly<
169
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
170
+ >;
171
+ readonly 'no-refer-to-non-existent-id': Readonly<
172
+ import('@markuplint/ml-core').RuleSeed<
173
+ import('@markuplint/ml-core').RuleConfigValue,
174
+ {
175
+ ariaVersion: '1.1' | '1.2' | '1.3';
176
+ fragmentRefersNameAttr: boolean;
177
+ }
178
+ >
179
+ >;
180
+ readonly 'no-use-event-handler-attr': Readonly<
181
+ import('@markuplint/ml-core').RuleSeed<
182
+ boolean,
183
+ {
184
+ ignore?: string | string[] | undefined;
185
+ }
186
+ >
187
+ >;
188
+ readonly 'permitted-contents': Readonly<
189
+ import('@markuplint/ml-core').RuleSeed<
190
+ import('./permitted-contents/types').TagRule[],
191
+ import('./permitted-contents/types').Options
192
+ >
193
+ >;
194
+ readonly 'placeholder-label-option': Readonly<import('@markuplint/ml-core').RuleSeed<boolean, undefined>>;
195
+ readonly 'require-accessible-name': Readonly<
196
+ import('@markuplint/ml-core').RuleSeed<
197
+ boolean,
198
+ {
199
+ ariaVersion: '1.1' | '1.2' | '1.3';
200
+ }
201
+ >
202
+ >;
203
+ readonly 'require-datetime': Readonly<
204
+ import('@markuplint/ml-core').RuleSeed<
205
+ boolean,
206
+ {
207
+ langs?: import('./require-datetime/types').Lang[] | undefined;
208
+ }
209
+ >
210
+ >;
211
+ readonly 'required-attr': Readonly<
212
+ import('@markuplint/ml-core').RuleSeed<
213
+ | string
214
+ | (
215
+ | string
216
+ | {
217
+ name: string;
218
+ value?: string | string[] | undefined;
219
+ }
220
+ )[],
221
+ undefined
222
+ >
223
+ >;
224
+ readonly 'required-element': Readonly<
225
+ import('@markuplint/ml-core').RuleSeed<
226
+ string[],
227
+ {
228
+ ignoreHasMutableContents: boolean;
229
+ }
230
+ >
231
+ >;
232
+ readonly 'required-h1': Readonly<import('@markuplint/ml-core').RuleSeed<boolean, import('./required-h1').Options>>;
233
+ readonly 'use-list': Readonly<
234
+ import('@markuplint/ml-core').RuleSeed<
235
+ readonly string[],
236
+ {
237
+ spaceNeededBullets?: string[] | undefined;
238
+ }
239
+ >
240
+ >;
241
+ readonly 'wai-aria': Readonly<import('@markuplint/ml-core').RuleSeed<boolean, import('./wai-aria/types').Options>>;
242
+ };
243
+ export default rules;
package/lib/index.js CHANGED
@@ -24,13 +24,15 @@ const no_hard_code_id_1 = tslib_1.__importDefault(require("./no-hard-code-id"));
24
24
  const no_refer_to_non_existent_id_1 = tslib_1.__importDefault(require("./no-refer-to-non-existent-id"));
25
25
  const no_use_event_handler_attr_1 = tslib_1.__importDefault(require("./no-use-event-handler-attr"));
26
26
  const permitted_contents_1 = tslib_1.__importDefault(require("./permitted-contents"));
27
+ const placeholder_label_option_1 = tslib_1.__importDefault(require("./placeholder-label-option"));
27
28
  const require_accessible_name_1 = tslib_1.__importDefault(require("./require-accessible-name"));
29
+ const require_datetime_1 = tslib_1.__importDefault(require("./require-datetime"));
28
30
  const required_attr_1 = tslib_1.__importDefault(require("./required-attr"));
29
31
  const required_element_1 = tslib_1.__importDefault(require("./required-element"));
30
32
  const required_h1_1 = tslib_1.__importDefault(require("./required-h1"));
31
33
  const use_list_1 = tslib_1.__importDefault(require("./use-list"));
32
34
  const wai_aria_1 = tslib_1.__importDefault(require("./wai-aria"));
33
- exports.default = {
35
+ const rules = {
34
36
  'attr-duplication': attr_duplication_1.default,
35
37
  'attr-value-quotes': attr_value_quotes_1.default,
36
38
  'case-sensitive-attr-name': case_sensitive_attr_name_1.default,
@@ -54,10 +56,13 @@ exports.default = {
54
56
  'no-refer-to-non-existent-id': no_refer_to_non_existent_id_1.default,
55
57
  'no-use-event-handler-attr': no_use_event_handler_attr_1.default,
56
58
  'permitted-contents': permitted_contents_1.default,
59
+ 'placeholder-label-option': placeholder_label_option_1.default,
57
60
  'require-accessible-name': require_accessible_name_1.default,
61
+ 'require-datetime': require_datetime_1.default,
58
62
  'required-attr': required_attr_1.default,
59
63
  'required-element': required_element_1.default,
60
64
  'required-h1': required_h1_1.default,
61
65
  'use-list': use_list_1.default,
62
66
  'wai-aria': wai_aria_1.default,
63
67
  };
68
+ exports.default = rules;
@@ -1,2 +1,4 @@
1
- declare const _default: import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, null>;
1
+ declare const _default: Readonly<
2
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
3
+ >;
2
4
  export default _default;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
+ const shared_1 = require("@markuplint/shared");
4
5
  exports.default = (0, ml_core_1.createRule)({
5
6
  defaultSeverity: 'warning',
6
7
  async verify({ document, report, t }) {
@@ -14,11 +15,7 @@ exports.default = (0, ml_core_1.createRule)({
14
15
  if (!spec) {
15
16
  return;
16
17
  }
17
- const ineffectiveConditions = spec.ineffective
18
- ? Array.isArray(spec.ineffective)
19
- ? spec.ineffective
20
- : [spec.ineffective]
21
- : [];
18
+ const ineffectiveConditions = (0, shared_1.toNoEmptyStringArrayFromStringOrArray)(spec.ineffective);
22
19
  if (ineffectiveConditions.some(selector => attr.ownerElement.matches(selector))) {
23
20
  report({
24
21
  scope: attr,
@@ -1,17 +1,44 @@
1
1
  import type { AttributeType } from '@markuplint/ml-spec';
2
2
  type Option = {
3
- attrs?: Record<string, Rule>;
4
- ignoreAttrNamePrefix?: string | string[];
5
- allowToAddPropertiesForPretender?: boolean;
3
+ /**
4
+ * @since 3.7.0
5
+ */
6
+ allowAttrs?: (string | Attr)[] | Record<string, ValueRule>;
7
+ /**
8
+ * @since 3.7.0
9
+ */
10
+ disallowAttrs?: (string | Attr)[] | Record<string, ValueRule>;
11
+ ignoreAttrNamePrefix?: string | string[];
12
+ allowToAddPropertiesForPretender?: boolean;
13
+ /**
14
+ * @deprecated Since version 3.7.0. Use `allowAttrs` or `disallowAttrs` instead.
15
+ * This option (`attr`) is now considered ambiguous and may lead to confusion.
16
+ * Please use the more explicit `allowAttrs` or `disallowAttrs` option
17
+ * to specify allowed attributes for the `invalid-attr` rule.
18
+ * @see {@link Option.allowAttrs}
19
+ * @see {@link Option.disallowAttrs}
20
+ */
21
+ attrs?: Record<
22
+ string,
23
+ | ValueRule
24
+ | {
25
+ disallowed: true;
26
+ }
27
+ >;
6
28
  };
7
- type Rule = {
8
- enum: [string, ...string[]];
9
- } | {
10
- pattern: string;
11
- } | {
12
- type: AttributeType;
13
- } | {
14
- disallowed: true;
29
+ type Attr = {
30
+ name: string;
31
+ value: AttributeType | ValueRule;
15
32
  };
16
- declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, Option>;
33
+ type ValueRule =
34
+ | {
35
+ enum: [string, ...string[]];
36
+ }
37
+ | {
38
+ pattern: string;
39
+ }
40
+ | {
41
+ type: AttributeType;
42
+ };
43
+ declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<boolean, Option>>;
17
44
  export default _default;
@@ -9,9 +9,9 @@ exports.default = (0, ml_core_1.createRule)({
9
9
  defaultOptions: {},
10
10
  async verify({ document, report, t }) {
11
11
  await document.walkOn('Attr', attr => {
12
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
12
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
13
13
  // Default
14
- const allowToAddPropertiesForPretender = (_a = attr.rule.option.allowToAddPropertiesForPretender) !== null && _a !== void 0 ? _a : true;
14
+ const allowToAddPropertiesForPretender = (_a = attr.rule.options.allowToAddPropertiesForPretender) !== null && _a !== void 0 ? _a : true;
15
15
  if (attr.isDirective) {
16
16
  return;
17
17
  }
@@ -33,50 +33,150 @@ exports.default = (0, ml_core_1.createRule)({
33
33
  }
34
34
  const valueNode = attr.valueNode;
35
35
  const value = attr.value;
36
- if (attr.rule.option.ignoreAttrNamePrefix) {
37
- const ignoreAttrNamePrefixes = Array.isArray(attr.rule.option.ignoreAttrNamePrefix)
38
- ? attr.rule.option.ignoreAttrNamePrefix
39
- : [attr.rule.option.ignoreAttrNamePrefix];
36
+ if (attr.rule.options.ignoreAttrNamePrefix != null) {
37
+ const ignoreAttrNamePrefixes = Array.isArray(attr.rule.options.ignoreAttrNamePrefix)
38
+ ? attr.rule.options.ignoreAttrNamePrefix
39
+ : [attr.rule.options.ignoreAttrNamePrefix];
40
40
  if (ignoreAttrNamePrefixes.some(prefix => name.indexOf(prefix) === 0)) {
41
41
  return;
42
42
  }
43
43
  }
44
44
  let invalid = false;
45
- const customRule = attr.rule.option.attrs ? attr.rule.option.attrs[name] : null;
46
- if (customRule) {
47
- if ('enum' in customRule) {
45
+ const allowAttrs = {};
46
+ const disallowAttrs = {};
47
+ if (attr.rule.options.allowAttrs) {
48
+ if (Array.isArray(attr.rule.options.allowAttrs)) {
49
+ for (const allowAttr of attr.rule.options.allowAttrs) {
50
+ if (typeof allowAttr === 'string') {
51
+ allowAttrs[allowAttr] = { type: 'Any' };
52
+ continue;
53
+ }
54
+ if (isValueRule(allowAttr.value)) {
55
+ allowAttrs[allowAttr.name] = allowAttr.value;
56
+ continue;
57
+ }
58
+ allowAttrs[allowAttr.name] = { type: allowAttr.value };
59
+ }
60
+ }
61
+ else {
62
+ for (const [attrName, valueRule] of Object.entries(attr.rule.options.allowAttrs)) {
63
+ allowAttrs[attrName] = valueRule;
64
+ }
65
+ }
66
+ }
67
+ if (attr.rule.options.disallowAttrs) {
68
+ if (Array.isArray(attr.rule.options.disallowAttrs)) {
69
+ for (const disallowAttr of attr.rule.options.disallowAttrs) {
70
+ if (typeof disallowAttr === 'string') {
71
+ disallowAttrs[disallowAttr] = { type: 'Any' };
72
+ continue;
73
+ }
74
+ if (isValueRule(disallowAttr.value)) {
75
+ disallowAttrs[disallowAttr.name] = disallowAttr.value;
76
+ continue;
77
+ }
78
+ disallowAttrs[disallowAttr.name] = { type: disallowAttr.value };
79
+ }
80
+ }
81
+ else {
82
+ for (const [attrName, valueRule] of Object.entries(attr.rule.options.disallowAttrs)) {
83
+ disallowAttrs[attrName] = valueRule;
84
+ }
85
+ }
86
+ }
87
+ if (attr.rule.options.attrs) {
88
+ for (const [attrName, valueRule] of Object.entries(attr.rule.options.attrs)) {
89
+ if ('disallowed' in valueRule) {
90
+ disallowAttrs[attrName] = { type: 'Any' };
91
+ }
92
+ else {
93
+ allowAttrs[attrName] = valueRule;
94
+ }
95
+ }
96
+ }
97
+ const allowValue = (_b = allowAttrs[name]) !== null && _b !== void 0 ? _b : null;
98
+ const disallowValue = (_c = disallowAttrs[name]) !== null && _c !== void 0 ? _c : null;
99
+ if (allowValue) {
100
+ if ('enum' in allowValue) {
48
101
  invalid = (0, attr_check_1.attrCheck)(t, name.toLowerCase(), value, true, {
49
102
  name,
50
103
  type: {
51
- enum: customRule.enum,
104
+ enum: allowValue.enum,
52
105
  },
53
106
  description: '',
54
107
  });
55
108
  }
56
- else if ('pattern' in customRule) {
57
- if (!(0, helpers_1.match)(value, customRule.pattern)) {
109
+ else if ('pattern' in allowValue) {
110
+ if (!(0, helpers_1.match)(value, allowValue.pattern)) {
111
+ invalid = {
112
+ invalidType: 'invalid-value',
113
+ message: t('{0} is unmatched with the below patterns: {1}', t('the "{0*}" {1}', name, 'attribute'), allowValue.pattern),
114
+ };
115
+ }
116
+ }
117
+ else if ('type' in allowValue) {
118
+ invalid = (0, attr_check_1.attrCheck)(t, name, value, true, { name, type: allowValue.type, description: '' });
119
+ }
120
+ }
121
+ else if (disallowValue) {
122
+ if ('enum' in disallowValue) {
123
+ const checkResult = (0, attr_check_1.attrCheck)(t, name.toLowerCase(), value, true, {
124
+ name,
125
+ type: {
126
+ enum: disallowValue.enum,
127
+ },
128
+ description: '',
129
+ });
130
+ if (checkResult === false) {
58
131
  invalid = {
59
132
  invalidType: 'invalid-value',
60
- message: t('{0} is unmatched with the below patterns: {1}', t('the "{0*}" {1}', name, 'attribute'), customRule.pattern),
133
+ message: t('{0} is disallowed to accept the following values: {1}', t('the "{0*}" {1}', name, 'attribute'), t(disallowValue.enum)),
61
134
  };
62
135
  }
63
136
  }
64
- else if ('type' in customRule) {
65
- invalid = (0, attr_check_1.attrCheck)(t, name, value, true, { name, type: customRule.type, description: '' });
137
+ else if ('pattern' in disallowValue) {
138
+ if ((0, helpers_1.match)(value, disallowValue.pattern)) {
139
+ invalid = {
140
+ invalidType: 'invalid-value',
141
+ message: t('{0} is matched with the below disallowed patterns: {1}', t('the "{0*}" {1}', name, 'attribute'), disallowValue.pattern),
142
+ };
143
+ }
66
144
  }
67
- else if ('disallowed' in customRule && customRule.disallowed) {
68
- invalid = {
69
- invalidType: 'non-existent',
70
- message: t('{0} is disallowed', t('the "{0*}" {1}', name, 'attribute')),
71
- };
145
+ else if ('type' in disallowValue) {
146
+ if (disallowValue.type === 'Any') {
147
+ invalid = {
148
+ invalidType: 'non-existent',
149
+ message: t('{0} is disallowed', t('the "{0*}" {1}', name, 'attribute')),
150
+ };
151
+ }
152
+ else {
153
+ const checkResult = (0, attr_check_1.attrCheck)(t, name, value, true, {
154
+ name,
155
+ type: disallowValue.type,
156
+ description: '',
157
+ });
158
+ if (checkResult === false) {
159
+ invalid = {
160
+ invalidType: 'invalid-value',
161
+ message: t('{0} is disallowed', t('{0} of {1}', t('the {0}', 'type'), t('the "{0*}" {1}', name, 'attribute'))),
162
+ };
163
+ }
164
+ }
72
165
  }
73
166
  }
74
167
  else if (attr.ownerElement.elementType === 'html' && attrSpecs) {
75
168
  log('Checking %s[%s="%s"]', attr.nodeName, name, value);
76
169
  invalid = (0, helpers_1.isValidAttr)(t, name, value, attr.isDynamicValue || false, attr.ownerElement, attrSpecs, log);
77
170
  }
78
- if (invalid) {
171
+ if (invalid !== false) {
79
172
  switch (invalid.invalidType) {
173
+ case 'disallowed-attr': {
174
+ report({
175
+ scope: attr,
176
+ message: invalid.message,
177
+ });
178
+ break;
179
+ }
80
180
  case 'invalid-value': {
81
181
  if (attr.isDynamicValue) {
82
182
  break;
@@ -84,16 +184,16 @@ exports.default = (0, ml_core_1.createRule)({
84
184
  report({
85
185
  scope: attr,
86
186
  message: invalid.message,
87
- line: ((_b = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startLine) !== null && _b !== void 0 ? _b : 0) + ((_d = (_c = invalid.loc) === null || _c === void 0 ? void 0 : _c.line) !== null && _d !== void 0 ? _d : 0),
88
- col: ((_e = invalid.loc) === null || _e === void 0 ? void 0 : _e.line)
89
- ? ((_f = invalid.loc) === null || _f === void 0 ? void 0 : _f.col) + 1
90
- : ((_g = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startCol) !== null && _g !== void 0 ? _g : 0) + ((_j = (_h = invalid.loc) === null || _h === void 0 ? void 0 : _h.col) !== null && _j !== void 0 ? _j : 0),
91
- raw: (_l = (_k = invalid.loc) === null || _k === void 0 ? void 0 : _k.raw) !== null && _l !== void 0 ? _l : value,
187
+ line: ((_d = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startLine) !== null && _d !== void 0 ? _d : 0) + ((_f = (_e = invalid.loc) === null || _e === void 0 ? void 0 : _e.line) !== null && _f !== void 0 ? _f : 0),
188
+ col: invalid.loc && invalid.loc.line > 0
189
+ ? ((_g = invalid.loc) === null || _g === void 0 ? void 0 : _g.col) + 1
190
+ : ((_h = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startCol) !== null && _h !== void 0 ? _h : 0) + ((_k = (_j = invalid.loc) === null || _j === void 0 ? void 0 : _j.col) !== null && _k !== void 0 ? _k : 0),
191
+ raw: (_m = (_l = invalid.loc) === null || _l === void 0 ? void 0 : _l.raw) !== null && _m !== void 0 ? _m : value,
92
192
  });
93
193
  break;
94
194
  }
95
195
  case 'non-existent': {
96
- if (allowToAddPropertiesForPretender && ((_m = attr.ownerElement.pretenderContext) === null || _m === void 0 ? void 0 : _m.type) === 'origin') {
196
+ if (allowToAddPropertiesForPretender && ((_o = attr.ownerElement.pretenderContext) === null || _o === void 0 ? void 0 : _o.type) === 'origin') {
97
197
  return;
98
198
  }
99
199
  const spec = (0, ml_core_1.getSpec)(attr.ownerElement, document.specs.specs);
@@ -113,3 +213,29 @@ exports.default = (0, ml_core_1.createRule)({
113
213
  });
114
214
  },
115
215
  });
216
+ function isValueRule(
217
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
218
+ value) {
219
+ if (typeof value === 'string') {
220
+ return false;
221
+ }
222
+ if ('enum' in value) {
223
+ if (Object.keys(value).length > 1) {
224
+ return false;
225
+ }
226
+ return true;
227
+ }
228
+ if ('token' in value) {
229
+ return false;
230
+ }
231
+ if ('pattern' in value) {
232
+ return true;
233
+ }
234
+ if (value.type === 'integer' || value.type === 'float') {
235
+ return false;
236
+ }
237
+ if (Object.keys(value).length > 1) {
238
+ return false;
239
+ }
240
+ return true;
241
+ }
@@ -1,2 +1,4 @@
1
- declare const _default: import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, null>;
1
+ declare const _default: Readonly<
2
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
3
+ >;
2
4
  export default _default;
@@ -1,8 +1,8 @@
1
1
  type Options = {
2
- ignoreRoles: Roles[];
3
- labelEachArea: boolean;
2
+ ignoreRoles: Roles[];
3
+ labelEachArea: boolean;
4
4
  };
5
5
  type TopLevelRoles = 'banner' | 'main' | 'complementary' | 'contentinfo';
6
6
  type Roles = TopLevelRoles | 'form' | 'navigation' | 'region';
7
- declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, Options>;
7
+ declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<boolean, Options>>;
8
8
  export default _default;
@@ -72,7 +72,7 @@ exports.default = (0, ml_core_1.createRule)({
72
72
  if (el.rule.disabled) {
73
73
  continue;
74
74
  }
75
- if ((_a = el.rule.option.ignoreRoles) === null || _a === void 0 ? void 0 : _a.includes(role)) {
75
+ if ((_a = el.rule.options.ignoreRoles) === null || _a === void 0 ? void 0 : _a.includes(role)) {
76
76
  continue;
77
77
  }
78
78
  if (el.isDescendantByUUIDList(uuidList)) {
@@ -93,7 +93,7 @@ exports.default = (0, ml_core_1.createRule)({
93
93
  if (el.rule.disabled) {
94
94
  continue;
95
95
  }
96
- if (!el.rule.option.labelEachArea) {
96
+ if (!el.rule.options.labelEachArea) {
97
97
  continue;
98
98
  }
99
99
  if (!hasLabel(el)) {
@@ -106,13 +106,17 @@ exports.default = (0, ml_core_1.createRule)({
106
106
  }
107
107
  },
108
108
  });
109
- function landmarkRoleElementUUIDList(roleset) {
109
+ function landmarkRoleElementUUIDList(
110
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
111
+ roleset) {
110
112
  return Object.values(roleset)
111
113
  .map(elements => elements.map(element => element.uuid))
112
114
  .flat();
113
115
  }
114
- function hasLabel(el) {
115
- const hasHeading = !!el.querySelectorAll('h1, h2, h3, h4, h5, h6').length;
116
+ function hasLabel(
117
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
118
+ el) {
119
+ const hasHeading = el.querySelectorAll('h1, h2, h3, h4, h5, h6').length > 0;
116
120
  if (hasHeading && el.matches('[aria-labelledby]')) {
117
121
  return true;
118
122
  }
@@ -1,2 +1,4 @@
1
- declare const _default: import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, null>;
1
+ declare const _default: Readonly<
2
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
3
+ >;
2
4
  export default _default;
@@ -1,2 +1,4 @@
1
- declare const _default: import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, null>;
1
+ declare const _default: Readonly<
2
+ import('@markuplint/ml-core').RuleSeed<import('@markuplint/ml-core').RuleConfigValue, undefined>
3
+ >;
2
4
  export default _default;