@markuplint/rules 2.0.0-dev.23 → 2.0.0-rc.5

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 (63) hide show
  1. package/lib/attr-check.d.ts +8 -1
  2. package/lib/attr-check.js +53 -455
  3. package/lib/attr-duplication/index.d.ts +1 -1
  4. package/lib/attr-duplication/index.js +0 -2
  5. package/lib/attr-equal-space-after/index.js +0 -1
  6. package/lib/attr-equal-space-before/index.js +0 -1
  7. package/lib/attr-spacing/index.js +0 -1
  8. package/lib/attr-value-quotes/index.js +0 -1
  9. package/lib/case-sensitive-attr-name/index.d.ts +6 -2
  10. package/lib/case-sensitive-attr-name/index.js +30 -8
  11. package/lib/case-sensitive-tag-name/index.js +0 -1
  12. package/lib/character-reference/index.d.ts +1 -2
  13. package/lib/character-reference/index.js +0 -2
  14. package/lib/class-naming/index.js +23 -23
  15. package/lib/create-message.d.ts +5 -0
  16. package/lib/create-message.js +270 -0
  17. package/lib/debug.d.ts +3 -0
  18. package/lib/debug.js +6 -0
  19. package/lib/deprecated-attr/index.d.ts +1 -1
  20. package/lib/deprecated-attr/index.js +2 -5
  21. package/lib/deprecated-element/index.d.ts +1 -1
  22. package/lib/deprecated-element/index.js +1 -3
  23. package/lib/disallowed-element/index.d.ts +2 -0
  24. package/lib/disallowed-element/index.js +34 -0
  25. package/lib/helpers.d.ts +15 -9
  26. package/lib/helpers.js +63 -68
  27. package/lib/id-duplication/index.d.ts +1 -1
  28. package/lib/id-duplication/index.js +1 -3
  29. package/lib/index.d.ts +28 -11
  30. package/lib/index.js +16 -0
  31. package/lib/ineffective-attr/index.d.ts +2 -0
  32. package/lib/ineffective-attr/index.js +40 -0
  33. package/lib/invalid-attr/index.d.ts +4 -2
  34. package/lib/invalid-attr/index.js +25 -9
  35. package/lib/landmark-roles/index.js +1 -2
  36. package/lib/no-boolean-attr-value/index.d.ts +2 -0
  37. package/lib/no-boolean-attr-value/index.js +47 -0
  38. package/lib/no-default-value/index.d.ts +2 -0
  39. package/lib/no-default-value/index.js +38 -0
  40. package/lib/no-hard-code-id/index.d.ts +2 -0
  41. package/lib/no-hard-code-id/index.js +27 -0
  42. package/lib/no-refer-to-non-existent-id/index.d.ts +2 -0
  43. package/lib/no-refer-to-non-existent-id/index.js +110 -0
  44. package/lib/no-use-event-handler-attr/index.d.ts +5 -0
  45. package/lib/no-use-event-handler-attr/index.js +37 -0
  46. package/lib/permitted-contents/index.js +24 -13
  47. package/lib/permitted-contents/types.d.ts +8 -0
  48. package/lib/permitted-contents/types.js +2 -0
  49. package/lib/require-element/index.d.ts +2 -0
  50. package/lib/require-element/index.js +38 -0
  51. package/lib/required-attr/index.d.ts +5 -1
  52. package/lib/required-attr/index.js +60 -19
  53. package/lib/required-element/index.d.ts +5 -0
  54. package/lib/required-element/index.js +44 -0
  55. package/lib/required-h1/index.d.ts +2 -3
  56. package/lib/required-h1/index.js +2 -3
  57. package/lib/wai-aria/index.d.ts +1 -1
  58. package/lib/wai-aria/index.js +23 -24
  59. package/package.json +10 -5
  60. package/schema.json +24 -0
  61. package/tsconfig.tsbuildinfo +1 -1
  62. package/lib/primitive-check.d.ts +0 -48
  63. package/lib/primitive-check.js +0 -109
@@ -1,21 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
- const helpers_1 = require("../helpers");
5
4
  exports.default = (0, ml_core_1.createRule)({
6
5
  defaultServerity: 'warning',
7
- defaultValue: 'no-upper',
8
- defaultOptions: null,
6
+ defaultValue: 'lower',
9
7
  async verify({ document, report, t }) {
10
8
  await document.walkOn('Element', async (node) => {
11
9
  if (node.isForeignElement || node.isCustomElement) {
12
10
  return;
13
11
  }
12
+ let value;
13
+ // Convert deprecated value
14
+ switch (node.rule.value) {
15
+ case 'no-lower':
16
+ value = 'upper';
17
+ break;
18
+ case 'no-upper':
19
+ value = 'lower';
20
+ break;
21
+ default:
22
+ value = node.rule.value;
23
+ }
14
24
  const ms = node.rule.severity === 'error' ? 'must' : 'should';
15
- const deny = node.rule.value === 'no-upper' ? /[A-Z]/ : /[a-z]/;
16
- const cases = node.rule.value === 'no-upper' ? 'lower' : 'upper';
25
+ const deny = value === 'lower' ? /[A-Z]/ : /[a-z]/;
26
+ const cases = value === 'lower' ? 'lower' : 'upper';
17
27
  const message = t(`{0} ${ms} be {1}`, t('{0} of {1}', 'attribute names', 'HTML elements'), `${cases}case`);
18
- const attrSpecs = (0, helpers_1.getAttrSpecs)(node.nameWithNS, document.specs);
28
+ const attrSpecs = (0, ml_core_1.getAttrSpecs)(node.nameWithNS, document.specs);
19
29
  for (const attr of node.attributes) {
20
30
  if (attr.attrType === 'ps-attr') {
21
31
  continue;
@@ -51,7 +61,19 @@ exports.default = (0, ml_core_1.createRule)({
51
61
  if (node.isForeignElement || node.isCustomElement) {
52
62
  return;
53
63
  }
54
- const attrSpecs = (0, helpers_1.getAttrSpecs)(node.nameWithNS, document.specs);
64
+ const attrSpecs = (0, ml_core_1.getAttrSpecs)(node.nameWithNS, document.specs);
65
+ let value;
66
+ // Convert deprecated value
67
+ switch (node.rule.value) {
68
+ case 'no-lower':
69
+ value = 'upper';
70
+ break;
71
+ case 'no-upper':
72
+ value = 'lower';
73
+ break;
74
+ default:
75
+ value = node.rule.value;
76
+ }
55
77
  if (node.attributes) {
56
78
  for (const attr of node.attributes) {
57
79
  if (attr.attrType === 'ps-attr') {
@@ -71,7 +93,7 @@ exports.default = (0, ml_core_1.createRule)({
71
93
  continue;
72
94
  }
73
95
  }
74
- if (node.rule.value === 'no-upper') {
96
+ if (value === 'lower') {
75
97
  attr.name.fix(attr.name.raw.toLowerCase());
76
98
  }
77
99
  else {
@@ -4,7 +4,6 @@ const ml_core_1 = require("@markuplint/ml-core");
4
4
  exports.default = (0, ml_core_1.createRule)({
5
5
  defaultServerity: 'warning',
6
6
  defaultValue: 'lower',
7
- defaultOptions: null,
8
7
  async verify({ document, report, t }) {
9
8
  await document.walk(async (node) => {
10
9
  if ('fixNodeName' in node) {
@@ -1,3 +1,2 @@
1
- export declare type Value = boolean;
2
- declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, null>;
1
+ declare const _default: import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, null>;
3
2
  export default _default;
@@ -4,8 +4,6 @@ const ml_core_1 = require("@markuplint/ml-core");
4
4
  const defaultChars = ['"', '&', '<', '>'];
5
5
  const ignoreParentElement = ['script', 'style'];
6
6
  exports.default = (0, ml_core_1.createRule)({
7
- defaultValue: true,
8
- defaultOptions: null,
9
7
  async verify({ document, report, t }) {
10
8
  const targetNodes = [];
11
9
  await document.walkOn('Text', async (node) => {
@@ -5,31 +5,31 @@ const helpers_1 = require("../helpers");
5
5
  exports.default = (0, ml_core_1.createRule)({
6
6
  defaultServerity: 'warning',
7
7
  defaultValue: null,
8
- defaultOptions: null,
9
8
  async verify({ document, report, t }) {
10
9
  await document.walkOn('Element', async (node) => {
11
- if (node.rule.value) {
12
- const classPatterns = Array.isArray(node.rule.value) ? node.rule.value : [node.rule.value];
13
- const attrs = node.getAttributeToken('class');
14
- for (const attr of attrs) {
15
- if (attr.attrType === 'html-attr' && attr.isDynamicValue) {
16
- continue;
17
- }
18
- const classAttr = attr.getValue();
19
- const classList = classAttr.potential
20
- .split(/\s+/g)
21
- .map(c => c.trim())
22
- .filter(c => c);
23
- for (const className of classList) {
24
- if (!classPatterns.some(pattern => (0, helpers_1.match)(className, pattern))) {
25
- report({
26
- scope: node,
27
- message: t('{0} is unmatched with the below patterns: {1}', t('the "{0}" {1}', className, 'class name'), `"${classPatterns.join('", "')}"`),
28
- line: classAttr.line,
29
- col: classAttr.col,
30
- raw: classAttr.raw,
31
- });
32
- }
10
+ if (!node.rule.value) {
11
+ return;
12
+ }
13
+ const classPatterns = Array.isArray(node.rule.value) ? node.rule.value : [node.rule.value];
14
+ const attrs = node.getAttributeToken('class');
15
+ for (const attr of attrs) {
16
+ if (attr.attrType === 'html-attr' && attr.isDynamicValue) {
17
+ continue;
18
+ }
19
+ const classAttr = attr.getValue();
20
+ const classList = classAttr.potential
21
+ .split(/\s+/g)
22
+ .map(c => c.trim())
23
+ .filter(c => c);
24
+ for (const className of classList) {
25
+ if (!classPatterns.some(pattern => (0, helpers_1.match)(className, pattern))) {
26
+ report({
27
+ scope: node,
28
+ message: t('{0} is unmatched with the below patterns: {1}', t('the "{0*}" {1}', className, 'class name'), `"${classPatterns.join('", "')}"`),
29
+ line: classAttr.line,
30
+ col: classAttr.col,
31
+ raw: classAttr.raw,
32
+ });
33
33
  }
34
34
  }
35
35
  }
@@ -0,0 +1,5 @@
1
+ import type { Translator } from '@markuplint/i18n';
2
+ import type { AttributeType } from '@markuplint/ml-spec';
3
+ import type { UnmatchedResult } from '@markuplint/types';
4
+ export declare function createMessageValueExpected(t: Translator, baseTarget: string, type: AttributeType, matches: UnmatchedResult): string;
5
+ export declare function __createMessageValueExpected(t: Translator, baseTarget: string, expected: string | null, matches: Pick<UnmatchedResult, 'partName' | 'reason' | 'raw' | 'candicate' | 'ref' | 'extra'>): string;
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.__createMessageValueExpected = exports.createMessageValueExpected = void 0;
4
+ const types_1 = require("@markuplint/types");
5
+ function createMessageValueExpected(t, baseTarget, type, matches) {
6
+ let target = baseTarget;
7
+ let listDescriptionPart;
8
+ let tokenType;
9
+ if ((0, types_1.isList)(type)) {
10
+ listDescriptionPart = t('{0} expects {1:c}', target, type.separator === 'space' ? 'space-separated list' : 'comma-separated list');
11
+ tokenType = type.token;
12
+ target = 'the content of the list';
13
+ }
14
+ else {
15
+ tokenType = type;
16
+ }
17
+ const expected = createExpectedObject(tokenType, matches, t);
18
+ const message = [listDescriptionPart, __createMessageValueExpected(t, target, expected, matches)]
19
+ .filter(s => s)
20
+ .join(t('. '));
21
+ return message;
22
+ }
23
+ exports.createMessageValueExpected = createMessageValueExpected;
24
+ function __createMessageValueExpected(t, baseTarget, expected, matches) {
25
+ let target = baseTarget;
26
+ let reasonPart;
27
+ let expectPart;
28
+ let unnecessaryPart;
29
+ let candicatePart;
30
+ let expectOrNeed = 'expects';
31
+ if (matches.partName) {
32
+ if (matches.partName === 'the content of the list') {
33
+ target = 'the content of the list';
34
+ }
35
+ else {
36
+ target = t('{0} part of {1}', t('the {0}', matches.partName), target);
37
+ }
38
+ }
39
+ switch (matches.reason) {
40
+ case 'doesnt-exist-in-enum': {
41
+ break;
42
+ }
43
+ case 'duplicated': {
44
+ reasonPart = t('{0} is {1:c}', target, 'duplicated');
45
+ target = 'it';
46
+ break;
47
+ }
48
+ case 'empty-token': {
49
+ reasonPart = t('{0} must not be {1}', target, 'empty');
50
+ target = 'it';
51
+ break;
52
+ }
53
+ case 'extra-token': {
54
+ const token = matches.partName || 'token';
55
+ reasonPart = t('Found {0}', t('extra {0}', token)) + ' ' + t([matches.raw]);
56
+ if (matches.extra) {
57
+ const extra = expectValueToWord(t, matches.extra, 'Any');
58
+ unnecessaryPart = t("It doesn't need {0}", extra);
59
+ }
60
+ break;
61
+ }
62
+ case 'illegal-combination': {
63
+ reasonPart = t('Found {0}', t('an {0}', 'illegal combination'));
64
+ break;
65
+ }
66
+ case 'illegal-order': {
67
+ break;
68
+ }
69
+ case 'missing-comma': {
70
+ if (matches.partName) {
71
+ reasonPart = t('Missing {0} in {1}', t('a {0}', 'comma'), t('the {0} part', matches.partName));
72
+ target = 'it';
73
+ }
74
+ else {
75
+ reasonPart = t('Missing {0}', t('a {0}', 'comma'));
76
+ }
77
+ break;
78
+ }
79
+ case 'missing-token': {
80
+ if (matches.partName) {
81
+ const part = t('the {0} part', matches.partName);
82
+ reasonPart = t('Missing {0}', part);
83
+ if (!expected) {
84
+ expected = part;
85
+ target = baseTarget;
86
+ }
87
+ }
88
+ else {
89
+ reasonPart = t('Missing {0}', t('a {0}', 'token'));
90
+ }
91
+ expectOrNeed = 'needs';
92
+ break;
93
+ }
94
+ case 'must-be-percent-encoded': {
95
+ break;
96
+ }
97
+ case 'must-be-serialized': {
98
+ break;
99
+ }
100
+ case 'out-of-range': {
101
+ break;
102
+ }
103
+ case 'syntax-error': {
104
+ break;
105
+ }
106
+ case 'typo': {
107
+ break;
108
+ }
109
+ case 'unexpected-comma': {
110
+ reasonPart = t('Found {0}', t('unexpected {0}', 'comma'));
111
+ break;
112
+ }
113
+ case 'unexpected-newline': {
114
+ reasonPart = t('Found {0}', t('unexpected {0}', 'newline'));
115
+ break;
116
+ }
117
+ case 'unexpected-space': {
118
+ reasonPart = t('Found {0}', t('unexpected {0}', 'whitespace'));
119
+ break;
120
+ }
121
+ case 'unexpected-token': {
122
+ const chars = t('unexpected {0}', 'characters');
123
+ if (matches.partName) {
124
+ const part = t('the {0} part', matches.partName);
125
+ reasonPart = t('{0} includes {1}', part, chars);
126
+ target = 'it';
127
+ }
128
+ else {
129
+ reasonPart = t('It includes {0}', chars);
130
+ }
131
+ break;
132
+ }
133
+ default: {
134
+ if ('type' in matches.reason) {
135
+ switch (matches.reason.type) {
136
+ case 'out-of-range-length-digit': {
137
+ const { gte, lte } = matches.reason;
138
+ let expectedDigits = null;
139
+ if (lte != null && gte === lte) {
140
+ expectedDigits = t('{0} digits', gte);
141
+ }
142
+ else if (lte != null) {
143
+ expectedDigits = t('{0} to {1} digits', gte, lte);
144
+ }
145
+ else {
146
+ expectedDigits = t('{0} or more digits', gte);
147
+ }
148
+ if (!expected) {
149
+ expected = expectedDigits;
150
+ }
151
+ else if (expected && expectedDigits) {
152
+ expected = t('{0:c} and {1:c}', expectedDigits, expected);
153
+ }
154
+ break;
155
+ }
156
+ case 'out-of-range': {
157
+ const expectedNum = createExpectedNumber(t, {
158
+ ...matches.reason,
159
+ type: 'integer',
160
+ });
161
+ if (!expected) {
162
+ expected = expectedNum;
163
+ }
164
+ else if (expected) {
165
+ expected = t('{0:c} and {1:c}', expectedNum, expected);
166
+ }
167
+ break;
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
173
+ if (expected) {
174
+ if (target === 'it') {
175
+ if (expectOrNeed === 'expects') {
176
+ expectPart = t('It expects {0:c}', expected);
177
+ }
178
+ else {
179
+ expectPart = t('It needs {0}', expected);
180
+ }
181
+ }
182
+ else {
183
+ if (expectOrNeed === 'expects') {
184
+ expectPart = t('{0} expects {1:c}', target, expected);
185
+ }
186
+ else {
187
+ expectPart = t('{0} needs {1}', target, expected);
188
+ }
189
+ }
190
+ }
191
+ if (matches.candicate) {
192
+ candicatePart = t('Did you mean "{0*}"?', matches.candicate);
193
+ }
194
+ let message = [reasonPart, unnecessaryPart, expectPart, candicatePart].filter(s => s).join(t('. '));
195
+ if (matches.ref) {
196
+ message += ` (${matches.ref})`;
197
+ }
198
+ return message;
199
+ }
200
+ exports.__createMessageValueExpected = __createMessageValueExpected;
201
+ function createExpectedObject(type, matches, t) {
202
+ var _a;
203
+ const expectedObject = [];
204
+ if ((_a = matches.expects) === null || _a === void 0 ? void 0 : _a.length) {
205
+ expectedObject.push(...matches.expects.map(expect => {
206
+ return expectValueToWord(t, expect, type);
207
+ }));
208
+ }
209
+ else if ((0, types_1.isKeyword)(type)) {
210
+ if (type[0] === '<') {
211
+ expectedObject.push(t('the CSS Syntax "{0}"', type));
212
+ }
213
+ }
214
+ else if ((0, types_1.isEnum)(type)) {
215
+ expectedObject.push(...type.enum);
216
+ }
217
+ else {
218
+ expectedObject.push(createExpectedNumber(t, type));
219
+ }
220
+ const expects = expectedObject.length === 0
221
+ ? null
222
+ : 1 < expectedObject.length
223
+ ? t('either {0}', t(expectedObject))
224
+ : expectedObject[0];
225
+ return expects;
226
+ }
227
+ function expectValueToWord(t, expect, type) {
228
+ switch (expect.type) {
229
+ case 'common':
230
+ return expect.value;
231
+ case 'const':
232
+ return expect.value ? `%${expect.value}%` : '';
233
+ case 'format':
234
+ return t('the {0} format', expect.value);
235
+ case 'regxp':
236
+ return t('{0} ({1})', 'regular expression', expect.value);
237
+ case 'syntax':
238
+ if ((0, types_1.isKeyword)(type) && type[0] === '<') {
239
+ return t('the CSS Syntax "{0}"', expect.value);
240
+ }
241
+ return t('{0} syntax', expect.value);
242
+ }
243
+ }
244
+ function createExpectedNumber(t, type) {
245
+ if (type.gt != null) {
246
+ if (type.lt != null) {
247
+ return t('{0} greater than {1} less than {2}', type.type, type.gt, type.lt);
248
+ }
249
+ if (type.lte != null) {
250
+ return t('{0} greater than {1} less than or equal to {2}', type.type, type.gt, type.lte);
251
+ }
252
+ return t('{0} greater than {1}', type.type, type.gt);
253
+ }
254
+ if (type.gte != null) {
255
+ if (type.lt != null) {
256
+ return t('{0} greater than or equal to {1} less than {2}', type.type, type.gte, type.lt);
257
+ }
258
+ if (type.lte != null) {
259
+ return t('{0} greater than or equal to {1} less than or equal to {2}', type.type, type.gte, type.lte);
260
+ }
261
+ return t('{0} greater than or equal to {1}', type.type, type.gte);
262
+ }
263
+ if (type.lt != null) {
264
+ return t('{0} less than {1}', type.type, type.lt);
265
+ }
266
+ if (type.lte != null) {
267
+ return t('{0} less than or equal to {1}', type.type, type.lte);
268
+ }
269
+ return type.type;
270
+ }
package/lib/debug.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import debug from 'debug';
2
+ export declare type Log = debug.Debugger;
3
+ export declare const log: debug.Debugger;
package/lib/debug.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.log = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
6
+ exports.log = (0, debug_1.default)('markuplint-rules');
@@ -1,2 +1,2 @@
1
- declare const _default: import("@markuplint/ml-core").RuleSeed<null, null>;
1
+ declare const _default: import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, null>;
2
2
  export default _default;
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
- const helpers_1 = require("../helpers");
5
4
  exports.default = (0, ml_core_1.createRule)({
6
- defaultValue: null,
7
- defaultOptions: null,
8
5
  async verify({ document, report, t }) {
9
6
  await document.walkOn('Element', async (element) => {
10
- const attrSpecs = (0, helpers_1.getAttrSpecs)(element.nameWithNS, document.specs);
7
+ const attrSpecs = (0, ml_core_1.getAttrSpecs)(element.nameWithNS, document.specs);
11
8
  if (!attrSpecs) {
12
9
  return;
13
10
  }
@@ -18,7 +15,7 @@ exports.default = (0, ml_core_1.createRule)({
18
15
  return;
19
16
  }
20
17
  if (attrSpec.deprecated || attrSpec.obsolete) {
21
- const message = t('{0} is {1:c}', t('the "{0}" {1}', name.potential, 'attribute'), attrSpec.obsolete ? 'obsolete' : 'deprecated');
18
+ const message = t('{0} is {1:c}', t('the "{0*}" {1}', name.potential, 'attribute'), attrSpec.obsolete ? 'obsolete' : 'deprecated');
22
19
  report({
23
20
  scope: element,
24
21
  message,
@@ -1,2 +1,2 @@
1
- declare const _default: import("@markuplint/ml-core").RuleSeed<null, null>;
1
+ declare const _default: import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, null>;
2
2
  export default _default;
@@ -5,8 +5,6 @@ const html_spec_1 = (0, tslib_1.__importDefault)(require("@markuplint/html-spec"
5
5
  const ml_core_1 = require("@markuplint/ml-core");
6
6
  const ml_spec_1 = require("@markuplint/ml-spec");
7
7
  exports.default = (0, ml_core_1.createRule)({
8
- defaultValue: null,
9
- defaultOptions: null,
10
8
  async verify({ document, report, t }) {
11
9
  await document.walkOn('Element', async (el) => {
12
10
  const ns = el.ns;
@@ -15,7 +13,7 @@ exports.default = (0, ml_core_1.createRule)({
15
13
  }
16
14
  const spec = (0, ml_spec_1.getSpecByTagName)(el.nameWithNS, html_spec_1.default);
17
15
  if (spec && (spec.obsolete || spec.deprecated || spec.nonStandard)) {
18
- const message = t('{0} is {1:c}', t('the "{0}" {1}', el.nodeName, 'element'), spec.deprecated ? 'deprecated' : spec.obsolete ? 'obsolete' : 'non-standard');
16
+ const message = t('{0} is {1:c}', t('the "{0*}" {1}', el.nodeName, 'element'), spec.deprecated ? 'deprecated' : spec.obsolete ? 'obsolete' : 'non-standard');
19
17
  report({
20
18
  scope: el,
21
19
  message,
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@markuplint/ml-core").RuleSeed<string[], null>;
2
+ export default _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ml_core_1 = require("@markuplint/ml-core");
4
+ exports.default = (0, ml_core_1.createRule)({
5
+ defaultValue: [],
6
+ defaultOptions: null,
7
+ async verify({ document, report, t, globalRule }) {
8
+ for (const query of globalRule.value) {
9
+ const elements = document.matchNodes(query);
10
+ for (const el of elements) {
11
+ const message = t('{0} is disallowed', t('the "{0*}" {1}', query, 'element'));
12
+ report({
13
+ scope: el,
14
+ message,
15
+ });
16
+ }
17
+ }
18
+ await document.walkOn('Element', el => {
19
+ if (el.rule.value === globalRule.value) {
20
+ return;
21
+ }
22
+ for (const query of el.rule.value) {
23
+ const elements = el.querySelectorAll(query);
24
+ for (const el of elements) {
25
+ const message = t('{0} is disallowed', t('the "{0*}" {1}', query, 'element'));
26
+ report({
27
+ scope: el,
28
+ message,
29
+ });
30
+ }
31
+ }
32
+ });
33
+ },
34
+ });
package/lib/helpers.d.ts CHANGED
@@ -1,7 +1,7 @@
1
+ import type { Log } from './debug';
1
2
  import type { Translator } from '@markuplint/i18n';
2
3
  import type { Element, RuleConfigValue } from '@markuplint/ml-core';
3
4
  import type { ARIRRoleAttribute, Attribute, MLMLSpec, PermittedRoles } from '@markuplint/ml-spec';
4
- export declare function getAttrSpecs(nameWithNS: string, { specs, def }: MLMLSpec): Attribute[] | null;
5
5
  export declare function attrMatches<T extends RuleConfigValue, R>(node: Element<T, R>, condition: Attribute['condition']): boolean;
6
6
  export declare function match(needle: string, pattern: string): boolean;
7
7
  /**
@@ -20,16 +20,22 @@ export declare function match(needle: string, pattern: string): boolean;
20
20
  * Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
21
21
  */
22
22
  export declare const rePCENChar: string;
23
- export declare function htmlSpec(nameWithNS: string): import("@markuplint/ml-spec").ElementSpec | null;
24
- export declare function isValidAttr(t: Translator, name: string, value: string, isDynamicValue: boolean, node: Element<any, any>, attrSpecs: Attribute[]): false | {
23
+ export declare function htmlSpec(specs: Readonly<MLMLSpec>, nameWithNS: string): import("@markuplint/ml-spec").ElementSpec | null;
24
+ export declare function isValidAttr(t: Translator, name: string, value: string, isDynamicValue: boolean, node: Element<any, any>, attrSpecs: Attribute[], log?: Log): false | {
25
25
  invalidType: "non-existent" | "invalid-value";
26
26
  message: string;
27
+ loc?: {
28
+ raw: string;
29
+ line: number;
30
+ col: number;
31
+ } | undefined;
27
32
  };
28
- export declare function ariaSpec(): {
33
+ export declare function toNormalizedValue(value: string, spec: Attribute): string;
34
+ export declare function ariaSpec(specs: Readonly<MLMLSpec>): {
29
35
  roles: ARIRRoleAttribute[];
30
36
  ariaAttrs: import("@markuplint/ml-spec").ARIAAttribute[];
31
37
  };
32
- export declare function getRoleSpec(roleName: string): {
38
+ export declare function getRoleSpec(specs: Readonly<MLMLSpec>, roleName: string): {
33
39
  name: string;
34
40
  isAbstract: boolean;
35
41
  statesAndProps: import("@markuplint/ml-spec").ARIARoleOwnedPropOrState[];
@@ -42,9 +48,9 @@ export declare function getRoleSpec(roleName: string): {
42
48
  * - If `true`, this mean is "Any".
43
49
  * - If `false`, this mean is "No".
44
50
  */
45
- export declare function getPermittedRoles(el: Element<any, any>): PermittedRoles;
46
- export declare function getImplicitRole(el: Element<any, any>): string | false;
47
- export declare function getComputedRole(el: Element<any, any>): {
51
+ export declare function getPermittedRoles(specs: Readonly<MLMLSpec>, el: Element<any, any>): PermittedRoles;
52
+ export declare function getImplicitRole(specs: Readonly<MLMLSpec>, el: Element<any, any>): string | false;
53
+ export declare function getComputedRole(specs: Readonly<MLMLSpec>, el: Element<any, any>): {
48
54
  name: string;
49
55
  isImplicit: boolean;
50
56
  } | null;
@@ -57,7 +63,7 @@ export declare function getComputedRole(el: Element<any, any>): {
57
63
  * @param tokenEnum
58
64
  */
59
65
  export declare function checkAriaValue(type: string, value: string, tokenEnum: string[]): boolean;
60
- export declare function checkAria(attrName: string, currentValue: string, role?: string): {
66
+ export declare function checkAria(specs: Readonly<MLMLSpec>, attrName: string, currentValue: string, role?: string): {
61
67
  currentValue: string;
62
68
  isValid: boolean;
63
69
  } | {