@markuplint/rules 3.15.0 → 4.0.0-alpha.10

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 (178) hide show
  1. package/.eslintrc +5 -0
  2. package/LICENSE +1 -1
  3. package/lib/attr-check.d.ts +8 -19
  4. package/lib/attr-check.js +16 -21
  5. package/lib/attr-duplication/index.d.ts +1 -3
  6. package/lib/attr-duplication/index.js +6 -6
  7. package/lib/attr-value-quotes/index.d.ts +2 -2
  8. package/lib/attr-value-quotes/index.js +8 -10
  9. package/lib/case-sensitive-attr-name/index.d.ts +1 -1
  10. package/lib/case-sensitive-attr-name/index.js +12 -13
  11. package/lib/case-sensitive-tag-name/index.d.ts +1 -1
  12. package/lib/case-sensitive-tag-name/index.js +5 -4
  13. package/lib/character-reference/index.d.ts +1 -1
  14. package/lib/character-reference/index.js +13 -12
  15. package/lib/class-naming/index.d.ts +1 -1
  16. package/lib/class-naming/index.js +14 -13
  17. package/lib/create-message.d.ts +2 -12
  18. package/lib/create-message.js +26 -26
  19. package/lib/debug.js +2 -6
  20. package/lib/deprecated-attr/index.d.ts +1 -3
  21. package/lib/deprecated-attr/index.js +9 -9
  22. package/lib/deprecated-element/index.d.ts +1 -3
  23. package/lib/deprecated-element/index.js +7 -6
  24. package/lib/disallowed-element/index.d.ts +1 -1
  25. package/lib/disallowed-element/index.js +9 -8
  26. package/lib/doctype/index.d.ts +2 -2
  27. package/lib/doctype/index.js +5 -4
  28. package/lib/end-tag/index.d.ts +1 -1
  29. package/lib/end-tag/index.js +8 -8
  30. package/lib/helpers.d.ts +17 -35
  31. package/lib/helpers.js +25 -32
  32. package/lib/id-duplication/index.d.ts +1 -3
  33. package/lib/id-duplication/index.js +5 -4
  34. package/lib/index.d.ts +21 -17
  35. package/lib/index.js +63 -66
  36. package/lib/ineffective-attr/index.d.ts +1 -3
  37. package/lib/ineffective-attr/index.js +8 -7
  38. package/lib/invalid-attr/index.d.ts +31 -38
  39. package/lib/invalid-attr/index.js +33 -33
  40. package/lib/label-has-control/index.d.ts +1 -3
  41. package/lib/label-has-control/index.js +5 -4
  42. package/lib/landmark-roles/index.d.ts +3 -3
  43. package/lib/landmark-roles/index.js +16 -18
  44. package/lib/no-boolean-attr-value/index.d.ts +1 -3
  45. package/lib/no-boolean-attr-value/index.js +9 -9
  46. package/lib/no-default-value/index.d.ts +1 -3
  47. package/lib/no-default-value/index.js +12 -12
  48. package/lib/no-empty-palpable-content/index.d.ts +3 -3
  49. package/lib/no-empty-palpable-content/index.js +9 -8
  50. package/lib/no-hard-code-id/index.d.ts +1 -3
  51. package/lib/no-hard-code-id/index.js +5 -4
  52. package/lib/no-refer-to-non-existent-id/index.d.ts +1 -1
  53. package/lib/no-refer-to-non-existent-id/index.js +37 -38
  54. package/lib/no-use-event-handler-attr/index.d.ts +2 -2
  55. package/lib/no-use-event-handler-attr/index.js +7 -6
  56. package/lib/permitted-contents/choice.d.ts +2 -8
  57. package/lib/permitted-contents/choice.js +14 -19
  58. package/lib/permitted-contents/complex-branch.d.ts +2 -8
  59. package/lib/permitted-contents/complex-branch.js +10 -14
  60. package/lib/permitted-contents/content-model.d.ts +1 -1
  61. package/lib/permitted-contents/content-model.js +10 -11
  62. package/lib/permitted-contents/count-pattern.d.ts +3 -18
  63. package/lib/permitted-contents/count-pattern.js +19 -24
  64. package/lib/permitted-contents/debug.browser.d.ts +16 -16
  65. package/lib/permitted-contents/debug.browser.js +9 -12
  66. package/lib/permitted-contents/debug.d.ts +10 -3
  67. package/lib/permitted-contents/debug.js +12 -13
  68. package/lib/permitted-contents/index.d.ts +2 -2
  69. package/lib/permitted-contents/index.js +13 -13
  70. package/lib/permitted-contents/matches-selector.d.ts +2 -7
  71. package/lib/permitted-contents/matches-selector.js +13 -18
  72. package/lib/permitted-contents/order.d.ts +2 -8
  73. package/lib/permitted-contents/order.js +19 -24
  74. package/lib/permitted-contents/recursive-branch.d.ts +3 -9
  75. package/lib/permitted-contents/recursive-branch.js +9 -13
  76. package/lib/permitted-contents/represent-transparent-nodes.d.ts +4 -8
  77. package/lib/permitted-contents/represent-transparent-nodes.js +15 -20
  78. package/lib/permitted-contents/start.d.ts +2 -7
  79. package/lib/permitted-contents/start.js +13 -21
  80. package/lib/permitted-contents/transparent.d.ts +1 -1
  81. package/lib/permitted-contents/transparent.js +6 -11
  82. package/lib/permitted-contents/types.d.ts +29 -29
  83. package/lib/permitted-contents/types.js +1 -2
  84. package/lib/permitted-contents/utils.d.ts +42 -79
  85. package/lib/permitted-contents/utils.js +72 -82
  86. package/lib/placeholder-label-option/index.d.ts +1 -1
  87. package/lib/placeholder-label-option/index.js +12 -13
  88. package/lib/require-accessible-name/index.d.ts +2 -2
  89. package/lib/require-accessible-name/index.js +12 -15
  90. package/lib/require-datetime/index.d.ts +3 -3
  91. package/lib/require-datetime/index.js +14 -13
  92. package/lib/require-datetime/types.d.ts +2 -2
  93. package/lib/require-datetime/types.js +1 -2
  94. package/lib/require-datetime/utils.d.ts +1 -1
  95. package/lib/require-datetime/utils.js +5 -12
  96. package/lib/required-attr/index.d.ts +3 -3
  97. package/lib/required-attr/index.js +11 -11
  98. package/lib/required-element/index.d.ts +2 -2
  99. package/lib/required-element/index.js +7 -7
  100. package/lib/required-h1/index.d.ts +3 -3
  101. package/lib/required-h1/index.js +6 -6
  102. package/lib/use-list/index.d.ts +6 -2
  103. package/lib/use-list/index.js +27 -11
  104. package/lib/wai-aria/checkings/abstract-role.d.ts +1 -1
  105. package/lib/wai-aria/checkings/abstract-role.js +5 -10
  106. package/lib/wai-aria/checkings/default-value.d.ts +4 -8
  107. package/lib/wai-aria/checkings/default-value.js +2 -6
  108. package/lib/wai-aria/checkings/deprecated-props.d.ts +5 -9
  109. package/lib/wai-aria/checkings/deprecated-props.js +3 -8
  110. package/lib/wai-aria/checkings/disallowed-prop.d.ts +5 -9
  111. package/lib/wai-aria/checkings/disallowed-prop.js +7 -12
  112. package/lib/wai-aria/checkings/implicit-props.d.ts +5 -9
  113. package/lib/wai-aria/checkings/implicit-props.js +12 -17
  114. package/lib/wai-aria/checkings/implicit-role.d.ts +1 -1
  115. package/lib/wai-aria/checkings/implicit-role.js +4 -9
  116. package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +1 -1
  117. package/lib/wai-aria/checkings/interaction-in-hidden.js +4 -8
  118. package/lib/wai-aria/checkings/no-global-prop.d.ts +4 -8
  119. package/lib/wai-aria/checkings/no-global-prop.js +2 -7
  120. package/lib/wai-aria/checkings/non-existent-role.d.ts +1 -1
  121. package/lib/wai-aria/checkings/non-existent-role.js +4 -9
  122. package/lib/wai-aria/checkings/permitted-roles.d.ts +1 -1
  123. package/lib/wai-aria/checkings/permitted-roles.js +4 -9
  124. package/lib/wai-aria/checkings/presentational-children.d.ts +1 -1
  125. package/lib/wai-aria/checkings/presentational-children.js +5 -10
  126. package/lib/wai-aria/checkings/required-owned-elements.d.ts +4 -8
  127. package/lib/wai-aria/checkings/required-owned-elements.js +7 -11
  128. package/lib/wai-aria/checkings/required-prop.d.ts +7 -13
  129. package/lib/wai-aria/checkings/required-prop.js +2 -7
  130. package/lib/wai-aria/checkings/value.d.ts +7 -16
  131. package/lib/wai-aria/checkings/value.js +7 -13
  132. package/lib/wai-aria/index.d.ts +2 -2
  133. package/lib/wai-aria/index.js +41 -40
  134. package/lib/wai-aria/types.d.ts +10 -10
  135. package/lib/wai-aria/types.js +1 -2
  136. package/package.json +17 -13
  137. package/test/attr-check.spec.js +0 -77
  138. package/test/attr-duplication/index.spec.js +0 -159
  139. package/test/attr-value-quotes/index.spec.js +0 -133
  140. package/test/case-sensitive-attr-name/index.spec.js +0 -65
  141. package/test/case-sensitive-tag-name/index.spec.js +0 -80
  142. package/test/character-reference/index.spec.js +0 -72
  143. package/test/class-naming/index.spec.js +0 -470
  144. package/test/create-message.spec.js +0 -497
  145. package/test/deprecated-attr/index.spec.js +0 -48
  146. package/test/deprecated-element/index.spec.js +0 -35
  147. package/test/disallowed-element/index.spec.js +0 -90
  148. package/test/doctype/index.spec.js +0 -50
  149. package/test/end-tag/index.spec.js +0 -162
  150. package/test/id-duplication/index.spec.js +0 -47
  151. package/test/ineffective-attr/index.spec.js +0 -31
  152. package/test/invalid-attr/index.spec.js +0 -1631
  153. package/test/label-has-control/index.spec.js +0 -29
  154. package/test/landmark-roles/index.spec.js +0 -187
  155. package/test/no-boolean-attr-value/index.spec.js +0 -41
  156. package/test/no-default-value/index.spec.js +0 -74
  157. package/test/no-empty-palpable-content/index.spec.js +0 -115
  158. package/test/no-hard-code-id/index.spec.js +0 -100
  159. package/test/no-refer-to-non-existent-id/index.spec.js +0 -254
  160. package/test/no-use-event-handler-attr/index.spec.js +0 -57
  161. package/test/permitted-contents/choice.spec.js +0 -174
  162. package/test/permitted-contents/count-pattern.spec.js +0 -308
  163. package/test/permitted-contents/index.spec.js +0 -1395
  164. package/test/permitted-contents/matches-selector.spec.js +0 -59
  165. package/test/permitted-contents/order.spec.js +0 -351
  166. package/test/permitted-contents/recursive-branch.spec.js +0 -41
  167. package/test/permitted-contents/represent-transparent-nodes.spec.js +0 -24
  168. package/test/permitted-contents/start.spec.js +0 -67
  169. package/test/placeholder-label-option/index.spec.js +0 -113
  170. package/test/require-accessible-name/index.spec.js +0 -444
  171. package/test/require-datetime/index.spec.js +0 -54
  172. package/test/require-datetime/utils.spec.js +0 -52
  173. package/test/required-attr/index.spec.js +0 -414
  174. package/test/required-element/index.spec.js +0 -188
  175. package/test/required-h1/index.spec.js +0 -69
  176. package/test/use-list/index.spec.js +0 -109
  177. package/test/wai-aria/checkings/value.spec.js +0 -33
  178. package/test/wai-aria/index.spec.js +0 -1203
@@ -1,29 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ml_core_1 = require("@markuplint/ml-core");
4
- const ml_spec_1 = require("@markuplint/ml-spec");
5
- const helpers_1 = require("../helpers");
6
- exports.default = (0, ml_core_1.createRule)({
1
+ import { createRule, getRoleSpec, getComputedRole } from '@markuplint/ml-core';
2
+ import { ARIA_RECOMMENDED_VERSION, isExposed } from '@markuplint/ml-spec';
3
+ import { accnameMayBeMutable } from '../helpers.js';
4
+ export default createRule({
5
+ meta: {
6
+ category: 'a11y',
7
+ },
7
8
  defaultOptions: {
8
- ariaVersion: ml_spec_1.ARIA_RECOMMENDED_VERSION,
9
+ ariaVersion: ARIA_RECOMMENDED_VERSION,
9
10
  },
10
11
  async verify({ document, report, t }) {
11
12
  await document.walkOn('Element', el => {
12
- var _a;
13
- if (((_a = el.pretenderContext) === null || _a === void 0 ? void 0 : _a.type) === 'pretender') {
14
- return;
15
- }
16
- if ((0, helpers_1.accnameMayBeMutable)(el, document)) {
13
+ if (accnameMayBeMutable(el, document)) {
17
14
  return;
18
15
  }
19
- if (!(0, ml_spec_1.isExposed)(el, document.specs, el.rule.options.ariaVersion)) {
16
+ if (!isExposed(el, document.specs, el.rule.options.ariaVersion)) {
20
17
  return;
21
18
  }
22
- const computed = (0, ml_core_1.getComputedRole)(document.specs, el, el.rule.options.ariaVersion);
19
+ const computed = getComputedRole(document.specs, el, el.rule.options.ariaVersion);
23
20
  if (!computed.role) {
24
21
  return;
25
22
  }
26
- const roleSpec = (0, ml_core_1.getRoleSpec)(document.specs, computed.role.name, el.namespaceURI, el.rule.options.ariaVersion);
23
+ const roleSpec = getRoleSpec(document.specs, computed.role.name, el.namespaceURI, el.rule.options.ariaVersion);
27
24
  if (!roleSpec || !roleSpec.accessibleNameRequired) {
28
25
  return;
29
26
  }
@@ -1,6 +1,6 @@
1
- import type { Lang } from './types';
1
+ import type { Lang } from './types.js';
2
2
  type Options = {
3
- langs?: Lang[];
3
+ langs?: Lang[];
4
4
  };
5
- declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<boolean, Options>>;
5
+ declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<boolean, Options>>;
6
6
  export default _default;
@@ -1,34 +1,35 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ml_core_1 = require("@markuplint/ml-core");
4
- const types_1 = require("@markuplint/types");
5
- const utils_1 = require("./utils");
6
- exports.default = (0, ml_core_1.createRule)({
1
+ import { createRule } from '@markuplint/ml-core';
2
+ import { check } from '@markuplint/types';
3
+ import { getCandidateDatetimeString } from './utils.js';
4
+ export default createRule({
5
+ meta: {
6
+ category: 'validation',
7
+ },
7
8
  defaultOptions: {
8
9
  langs: undefined,
9
10
  },
10
11
  verify({ document, report, t }) {
11
- document.querySelectorAll('time:not([datetime])').forEach(time => {
12
+ for (const time of document.querySelectorAll('time:not([datetime])')) {
12
13
  if (time.hasMutableChildren()) {
13
- return;
14
+ continue;
14
15
  }
15
16
  const content = time.textContent.trim();
16
- const result = (0, types_1.check)(content, 'DateTime');
17
+ const result = check(content, 'DateTime');
17
18
  if (result.matched) {
18
- return;
19
+ continue;
19
20
  }
20
- const candidate = (0, utils_1.getCandidateDatetimeString)(content, time.rule.options.langs);
21
+ const candidate = getCandidateDatetimeString(content, time.rule.options.langs);
21
22
  if (candidate) {
22
23
  report({
23
24
  scope: time,
24
25
  message: t('need {0*}', `datetime="${candidate}"`),
25
26
  });
26
- return;
27
+ continue;
27
28
  }
28
29
  report({
29
30
  scope: time,
30
31
  message: t('need {0}', t('the "{0*}" {1}', 'datetime', 'attribute')),
31
32
  });
32
- });
33
+ }
33
34
  },
34
35
  });
@@ -1,8 +1,8 @@
1
1
  export type DateTimeKey = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'ms';
2
2
  export type DateTimeData = Partial<Record<DateTimeKey, number>>;
3
3
  export type DateTime = {
4
- datetime: DateTimeData;
5
- zone?: number;
4
+ datetime: DateTimeData;
5
+ zone?: number;
6
6
  };
7
7
  /**
8
8
  * @see https://github.com/wanasit/chrono#locales
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,4 +1,4 @@
1
- import type { DateTime, Lang } from './types';
1
+ import type { DateTime, Lang } from './types.js';
2
2
  /**
3
3
  * Datetime-ish text to a datetime data
4
4
  *
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCandidateDatetimeString = exports.parseADatetime = void 0;
4
- const tslib_1 = require("tslib");
5
- const chrono = tslib_1.__importStar(require("chrono-node"));
1
+ import * as chrono from 'chrono-node';
6
2
  const defaultLangs = ['en', 'ja', 'fr', 'nl', 'ru', 'de', 'pt', 'zh'];
7
3
  /**
8
4
  * Datetime-ish text to a datetime data
@@ -12,8 +8,7 @@ const defaultLangs = ['en', 'ja', 'fr', 'nl', 'ru', 'de', 'pt', 'zh'];
12
8
  * @param base Reference date for a test
13
9
  * @returns
14
10
  */
15
- function parseADatetime(content, langs, base) {
16
- var _a;
11
+ export function parseADatetime(content, langs, base) {
17
12
  const date = parseTryMultipleLangs(content, langs, base);
18
13
  if (!date) {
19
14
  return null;
@@ -32,7 +27,7 @@ function parseADatetime(content, langs, base) {
32
27
  data.hour = date.get('hour');
33
28
  }
34
29
  if (date.isCertain('hour')) {
35
- data.minute = (_a = date.get('minute')) !== null && _a !== void 0 ? _a : 0;
30
+ data.minute = date.get('minute') ?? 0;
36
31
  }
37
32
  if (date.isCertain('second')) {
38
33
  data.second = date.get('second');
@@ -48,8 +43,7 @@ function parseADatetime(content, langs, base) {
48
43
  }
49
44
  return datetime;
50
45
  }
51
- exports.parseADatetime = parseADatetime;
52
- function getCandidateDatetimeString(content, langs = defaultLangs) {
46
+ export function getCandidateDatetimeString(content, langs = defaultLangs) {
53
47
  const date = parseADatetime(content, langs);
54
48
  if (!date) {
55
49
  return null;
@@ -66,7 +60,6 @@ function getCandidateDatetimeString(content, langs = defaultLangs) {
66
60
  }
67
61
  return datetimeStr;
68
62
  }
69
- exports.getCandidateDatetimeString = getCandidateDatetimeString;
70
63
  function toDatetimeString(date) {
71
64
  if (only(date, ['year', 'month'])) {
72
65
  return `${f(date.year, 4)}-${f(date.month, 2)}`;
@@ -101,7 +94,7 @@ function parseTryMultipleLangs(content, langs, base) {
101
94
  for (const lang of langs) {
102
95
  const results = chrono[lang].casual.parse(content, base);
103
96
  // Is not multiple datetime contents
104
- if (results.length < 1) {
97
+ if (results.length === 0) {
105
98
  continue;
106
99
  }
107
100
  const result = results[0];
@@ -1,7 +1,7 @@
1
1
  type RequiredAttributes = string | (string | Attr)[];
2
2
  type Attr = {
3
- name: string;
4
- value?: string | string[];
3
+ name: string;
4
+ value?: string | string[];
5
5
  };
6
- declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<RequiredAttributes, undefined>>;
6
+ declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<RequiredAttributes, undefined>>;
7
7
  export default _default;
@@ -1,17 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ml_core_1 = require("@markuplint/ml-core");
4
- const helpers_1 = require("../helpers");
5
- exports.default = (0, ml_core_1.createRule)({
1
+ import { createRule, getAttrSpecs } from '@markuplint/ml-core';
2
+ import { attrMatches, match } from '../helpers.js';
3
+ export default createRule({
4
+ meta: {
5
+ category: 'validation',
6
+ },
6
7
  defaultValue: [],
7
8
  async verify({ document, report, t }) {
8
9
  await document.walkOn('Element', el => {
9
- var _a;
10
10
  if (el.hasSpreadAttr) {
11
11
  return;
12
12
  }
13
13
  const customRequiredAttrs = typeof el.rule.value === 'string' ? [el.rule.value] : el.rule.value;
14
- const attrSpec = (0, ml_core_1.getAttrSpecs)(el, document.specs);
14
+ const attrSpec = getAttrSpecs(el, document.specs);
15
15
  const attributeSpecs = {};
16
16
  if (attrSpec && el.elementType === 'html') {
17
17
  for (const spec of attrSpec) {
@@ -52,7 +52,7 @@ exports.default = (0, ml_core_1.createRule)({
52
52
  invalid = !candidate.some(attrName => el.hasAttribute(attrName));
53
53
  }
54
54
  else if (spec.required === true) {
55
- invalid = (0, helpers_1.attrMatches)(el, spec.condition) && didntHave;
55
+ invalid = attrMatches(el, spec.condition) && didntHave;
56
56
  }
57
57
  else if (spec.required != null && spec.required !== false) {
58
58
  const selector = typeof spec.required === 'string' ? spec.required : spec.required.join(',');
@@ -67,13 +67,13 @@ exports.default = (0, ml_core_1.createRule)({
67
67
  }
68
68
  const value = el.getAttribute(spec.name);
69
69
  if (spec.values.length > 0 && value) {
70
- const matched = spec.values.some(pattern => (0, helpers_1.match)(value, pattern));
70
+ const matched = spec.values.some(pattern => match(value, pattern));
71
71
  if (!matched) {
72
72
  const expects = spec.values.length === 1 ? t(spec.values) : t('either {0}', t(spec.values));
73
73
  const message = t('{0} expects {1}', t('the "{0*}" {1}', spec.name, 'attribute'), expects);
74
74
  const attrToken = el.getAttributeToken(spec.name);
75
- const valueToken = (_a = attrToken[0]) === null || _a === void 0 ? void 0 : _a.valueNode;
76
- const token = valueToken !== null && valueToken !== void 0 ? valueToken : attrToken[0];
75
+ const valueToken = attrToken[0]?.valueNode;
76
+ const token = valueToken ?? attrToken[0];
77
77
  if (token) {
78
78
  report({
79
79
  scope: {
@@ -1,5 +1,5 @@
1
1
  type Options = {
2
- ignoreHasMutableContents: boolean;
2
+ ignoreHasMutableContents: boolean;
3
3
  };
4
- declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<string[], Options>>;
4
+ declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<string[], Options>>;
5
5
  export default _default;
@@ -1,13 +1,13 @@
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)({
1
+ import { createRule } from '@markuplint/ml-core';
2
+ export default createRule({
3
+ meta: {
4
+ category: 'validation',
5
+ },
5
6
  defaultValue: [],
6
7
  defaultOptions: {
7
8
  ignoreHasMutableContents: true,
8
9
  },
9
10
  async verify({ document, report, t }) {
10
- var _a, _b;
11
11
  const hasMutableContent = document.nodeList.some(n => n.is(n.ELEMENT_NODE) && n.hasMutableChildren());
12
12
  if (!hasMutableContent) {
13
13
  for (const query of document.rule.value) {
@@ -18,7 +18,7 @@ exports.default = (0, ml_core_1.createRule)({
18
18
  message,
19
19
  line: 1,
20
20
  col: 1,
21
- raw: (_b = (_a = document.nodeList[0]) === null || _a === void 0 ? void 0 : _a.raw.slice(0, 1)) !== null && _b !== void 0 ? _b : '',
21
+ raw: document.nodeList[0]?.raw.slice(0, 1) ?? '',
22
22
  });
23
23
  }
24
24
  }
@@ -31,7 +31,7 @@ exports.default = (0, ml_core_1.createRule)({
31
31
  return;
32
32
  }
33
33
  for (const query of el.rule.value) {
34
- const exists = Array.from(el.children).find(child => child.matches(query));
34
+ const exists = [...el.children].find(child => child.matches(query));
35
35
  if (!exists) {
36
36
  const message = t('Require {0}', t('the "{0*}" {1}', query, 'element'));
37
37
  report({
@@ -1,6 +1,6 @@
1
1
  export interface Options {
2
- 'expected-once': boolean;
3
- 'in-document-fragment': boolean;
2
+ 'expected-once': boolean;
3
+ 'in-document-fragment': boolean;
4
4
  }
5
- declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<boolean, Options>>;
5
+ declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<boolean, Options>>;
6
6
  export default _default;
@@ -1,13 +1,13 @@
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)({
1
+ import { createRule } from '@markuplint/ml-core';
2
+ export default createRule({
3
+ meta: {
4
+ category: 'a11y',
5
+ },
5
6
  defaultOptions: {
6
7
  'expected-once': true,
7
8
  'in-document-fragment': false,
8
9
  },
9
10
  async verify({ document, report, t }) {
10
- var _a, _b;
11
11
  const h1Stack = [];
12
12
  if (document.nodeList.length === 0) {
13
13
  return;
@@ -26,7 +26,7 @@ exports.default = (0, ml_core_1.createRule)({
26
26
  message,
27
27
  line: 1,
28
28
  col: 1,
29
- raw: (_b = (_a = document.nodeList[0]) === null || _a === void 0 ? void 0 : _a.raw.slice(0, 1)) !== null && _b !== void 0 ? _b : '',
29
+ raw: document.nodeList[0]?.raw.slice(0, 1) ?? '',
30
30
  });
31
31
  }
32
32
  else if (document.rule.options['expected-once'] && h1Stack.length > 1 && h1Stack[1]) {
@@ -1,6 +1,10 @@
1
1
  type Bullets = readonly string[];
2
2
  type Options = {
3
- spaceNeededBullets?: string[];
3
+ spaceNeededBullets?: string[];
4
+ noPrev?: boolean;
5
+ prevElement?: boolean;
6
+ prevComment?: boolean;
7
+ prevCodeBlock?: boolean;
4
8
  };
5
- declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<Bullets, Options>>;
9
+ declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<Bullets, Options>>;
6
10
  export default _default;
@@ -1,8 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ml_core_1 = require("@markuplint/ml-core");
4
- const shared_1 = require("@markuplint/shared");
5
- exports.default = (0, ml_core_1.createRule)({
1
+ import { createRule } from '@markuplint/ml-core';
2
+ import { decodeEntities } from '@markuplint/shared';
3
+ export default createRule({
4
+ meta: {
5
+ category: 'a11y',
6
+ },
6
7
  defaultValue: [
7
8
  /**
8
9
  * @see https://en.wikipedia.org/wiki/Bullet_(typography)#In_Unicode
@@ -53,12 +54,15 @@ exports.default = (0, ml_core_1.createRule)({
53
54
  '*', // asterisks
54
55
  '+', // plus signs
55
56
  ],
57
+ noPrev: true,
58
+ prevElement: true,
59
+ prevComment: true,
60
+ prevCodeBlock: false,
56
61
  },
57
62
  defaultSeverity: 'warning',
58
63
  async verify({ document, report, t }) {
59
64
  await document.walkOn('Text', textNode => {
60
- var _a;
61
- const text = (0, shared_1.decodeEntities)(textNode.raw.trim());
65
+ const text = decodeEntities(textNode.raw.trim());
62
66
  if (!text) {
63
67
  // empty
64
68
  return;
@@ -67,8 +71,21 @@ exports.default = (0, ml_core_1.createRule)({
67
71
  // character only
68
72
  return;
69
73
  }
74
+ if (textNode.rule.options.noPrev === false && !textNode.prevNode) {
75
+ return;
76
+ }
77
+ if (textNode.rule.options.prevElement === false && textNode.prevNode?.is(textNode.ELEMENT_NODE)) {
78
+ return;
79
+ }
80
+ if (textNode.rule.options.prevComment === false && textNode.prevNode?.is(textNode.COMMENT_NODE)) {
81
+ return;
82
+ }
83
+ if (textNode.rule.options.prevCodeBlock === false &&
84
+ textNode.prevNode?.is(textNode.MARKUPLINT_PREPROCESSOR_BLOCK)) {
85
+ return;
86
+ }
70
87
  const bullets = textNode.rule.value;
71
- const spaceNeededBullets = (_a = textNode.rule.options.spaceNeededBullets) !== null && _a !== void 0 ? _a : [];
88
+ const spaceNeededBullets = textNode.rule.options.spaceNeededBullets ?? [];
72
89
  if (isMayListItem(text, bullets, spaceNeededBullets)) {
73
90
  report({
74
91
  scope: textNode,
@@ -79,9 +96,8 @@ exports.default = (0, ml_core_1.createRule)({
79
96
  },
80
97
  });
81
98
  function isMayListItem(text, bullets, spaceNeededBullets) {
82
- var _a;
83
- const textArray = Array.from(text);
84
- const firstLetter = (_a = textArray[0]) !== null && _a !== void 0 ? _a : '';
99
+ const textArray = [...text];
100
+ const firstLetter = textArray[0] ?? '';
85
101
  const isBullet = bullets.includes(firstLetter);
86
102
  const needSpace = spaceNeededBullets.includes(firstLetter);
87
103
  const continuous = firstLetter === textArray[1];
@@ -1,3 +1,3 @@
1
- import type { Options } from '../types';
1
+ import type { Options } from '../types.js';
2
2
  import type { AttrChecker } from '@markuplint/ml-core';
3
3
  export declare const checkingAbstractRole: AttrChecker<boolean, Options>;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkingAbstractRole = void 0;
4
- const ml_spec_1 = require("@markuplint/ml-spec");
5
- const checkingAbstractRole = ({ attr }) => t => {
6
- var _a;
7
- const { roles } = (0, ml_spec_1.ariaSpecs)(attr.ownerMLDocument.specs, attr.rule.options.version);
8
- const tokens = (_a = attr.tokenList) === null || _a === void 0 ? void 0 : _a.allTokens();
1
+ import { ariaSpecs } from '@markuplint/ml-spec';
2
+ export const checkingAbstractRole = ({ attr }) => t => {
3
+ const { roles } = ariaSpecs(attr.ownerMLDocument.specs, attr.rule.options.version);
4
+ const tokens = attr.tokenList?.allTokens();
9
5
  if (!tokens) {
10
6
  return;
11
7
  }
12
8
  for (const token of tokens) {
13
9
  const role = roles.find(r => r.name === token.raw);
14
- if (role === null || role === void 0 ? void 0 : role.isAbstract) {
10
+ if (role?.isAbstract) {
15
11
  return {
16
12
  scope: token,
17
13
  message: t('{0} is {1}', t('the "{0*}" {1}', token.raw, 'role'), 'the abstract role'),
@@ -19,4 +15,3 @@ const checkingAbstractRole = ({ attr }) => t => {
19
15
  }
20
16
  }
21
17
  };
22
- exports.checkingAbstractRole = checkingAbstractRole;
@@ -1,10 +1,6 @@
1
- import type { Options } from '../types';
1
+ import type { Options } from '../types.js';
2
2
  import type { AttrChecker } from '@markuplint/ml-core';
3
3
  import type { ARIAProperty } from '@markuplint/ml-spec';
4
- export declare const checkingDefaultValue: AttrChecker<
5
- boolean,
6
- Options,
7
- {
8
- propSpecs: readonly ARIAProperty[];
9
- }
10
- >;
4
+ export declare const checkingDefaultValue: AttrChecker<boolean, Options, {
5
+ propSpecs: readonly ARIAProperty[];
6
+ }>;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkingDefaultValue = void 0;
4
- const checkingDefaultValue = ({ attr, propSpecs }) => t => {
1
+ export const checkingDefaultValue = ({ attr, propSpecs }) => t => {
5
2
  if (attr.isDynamicValue) {
6
3
  return;
7
4
  }
8
5
  const propSpec = propSpecs.find(p => p.name === attr.name);
9
6
  const value = attr.value.trim().toLowerCase();
10
- if ((propSpec === null || propSpec === void 0 ? void 0 : propSpec.defaultValue) != null && propSpec.defaultValue === value) {
7
+ if (propSpec?.defaultValue != null && propSpec.defaultValue === value) {
11
8
  return {
12
9
  scope: attr,
13
10
  message: t('It is {0}', 'default value'),
14
11
  };
15
12
  }
16
13
  };
17
- exports.checkingDefaultValue = checkingDefaultValue;
@@ -1,11 +1,7 @@
1
- import type { Options } from '../types';
1
+ import type { Options } from '../types.js';
2
2
  import type { AttrChecker } from '@markuplint/ml-core';
3
3
  import type { ARIAProperty, ARIARole } from '@markuplint/ml-spec';
4
- export declare const checkingDeprecatedProps: AttrChecker<
5
- boolean,
6
- Options,
7
- {
8
- role: ARIARole | null;
9
- propSpecs: readonly ARIAProperty[];
10
- }
11
- >;
4
+ export declare const checkingDeprecatedProps: AttrChecker<boolean, Options, {
5
+ role: ARIARole | null;
6
+ propSpecs: readonly ARIAProperty[];
7
+ }>;
@@ -1,18 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkingDeprecatedProps = void 0;
4
- const checkingDeprecatedProps = ({ attr, role, propSpecs }) => t => {
5
- var _a;
1
+ export const checkingDeprecatedProps = ({ attr, role, propSpecs }) => t => {
6
2
  if (!role) {
7
3
  return;
8
4
  }
9
5
  const props = role.ownedProperties.find(p => p.name === attr.name);
10
- if (props === null || props === void 0 ? void 0 : props.deprecated) {
6
+ if (props?.deprecated) {
11
7
  const propSpec = propSpecs.find(p => p.name === attr.name);
12
8
  return {
13
9
  scope: attr,
14
- message: t('{0:c} on {1}', t('{0} is {1:c}', t('the "{0*}" {1}', attr.name, `ARIA ${(_a = propSpec === null || propSpec === void 0 ? void 0 : propSpec.type) !== null && _a !== void 0 ? _a : 'property'}`), 'deprecated'), t('the "{0*}" {1}', role.name, 'role')),
10
+ message: t('{0:c} on {1}', t('{0} is {1:c}', t('the "{0*}" {1}', attr.name, `ARIA ${propSpec?.type ?? 'property'}`), 'deprecated'), t('the "{0*}" {1}', role.name, 'role')),
15
11
  };
16
12
  }
17
13
  };
18
- exports.checkingDeprecatedProps = checkingDeprecatedProps;
@@ -1,11 +1,7 @@
1
- import type { Options } from '../types';
1
+ import type { Options } from '../types.js';
2
2
  import type { AttrChecker } from '@markuplint/ml-core';
3
3
  import type { ARIAProperty, ARIARole } from '@markuplint/ml-spec';
4
- export declare const checkingDisallowedProp: AttrChecker<
5
- boolean,
6
- Options,
7
- {
8
- role: ARIARole | null;
9
- propSpecs: readonly ARIAProperty[];
10
- }
11
- >;
4
+ export declare const checkingDisallowedProp: AttrChecker<boolean, Options, {
5
+ role: ARIARole | null;
6
+ propSpecs: readonly ARIAProperty[];
7
+ }>;
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkingDisallowedProp = void 0;
4
- const ml_spec_1 = require("@markuplint/ml-spec");
5
- const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
6
- var _a, _b, _c, _d;
1
+ import { getARIA } from '@markuplint/ml-spec';
2
+ export const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
7
3
  if (!role) {
8
4
  return;
9
5
  }
@@ -12,8 +8,8 @@ const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
12
8
  }
13
9
  const statesAndProp = role.ownedProperties.find(p => p.name === attr.name);
14
10
  const propSpec = propSpecs.find(p => p.name === attr.name);
15
- const elAriaSpec = (0, ml_spec_1.getARIA)(attr.ownerMLDocument.specs, attr.ownerElement.localName, attr.ownerElement.namespaceURI, attr.rule.options.version, attr.ownerElement.matches.bind(attr.ownerElement));
16
- if ((elAriaSpec === null || elAriaSpec === void 0 ? void 0 : elAriaSpec.properties) !== false && ((_a = elAriaSpec === null || elAriaSpec === void 0 ? void 0 : elAriaSpec.properties) === null || _a === void 0 ? void 0 : _a.without)) {
11
+ const elAriaSpec = getARIA(attr.ownerMLDocument.specs, attr.ownerElement.localName, attr.ownerElement.namespaceURI, attr.rule.options.version, attr.ownerElement.matches.bind(attr.ownerElement));
12
+ if (elAriaSpec?.properties !== false && elAriaSpec?.properties?.without) {
17
13
  for (const ignore of elAriaSpec.properties.without) {
18
14
  if (ignore.name === attr.name) {
19
15
  return {
@@ -24,12 +20,12 @@ const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
24
20
  ? '{0} should not {1}'
25
21
  : '{0} is not recommended to {1}',
26
22
  // {0}
27
- t('the "{0*}" {1}', attr.name, `ARIA ${(_b = propSpec === null || propSpec === void 0 ? void 0 : propSpec.type) !== null && _b !== void 0 ? _b : 'property'}`),
23
+ t('the "{0*}" {1}', attr.name, `ARIA ${propSpec?.type ?? 'property'}`),
28
24
  // {1}
29
25
  'use'), t('the "{0*}" {1}', attr.ownerElement.localName, 'element')) +
30
26
  (ignore.alt
31
27
  ? t('. ') +
32
- t('{0} if you {1} {2}', t(ignore.alt.method === 'remove-attr' ? 'Remove {0}' : 'Add {0}', t('the "{0*}" {1}', ignore.alt.target, 'attribute')), 'use', t('the {0}', `ARIA ${(_c = propSpec === null || propSpec === void 0 ? void 0 : propSpec.type) !== null && _c !== void 0 ? _c : 'property'}`))
28
+ t('{0} if you {1} {2}', t(ignore.alt.method === 'remove-attr' ? 'Remove {0}' : 'Add {0}', t('the "{0*}" {1}', ignore.alt.target, 'attribute')), 'use', t('the {0}', `ARIA ${propSpec?.type ?? 'property'}`))
33
29
  : ''),
34
30
  };
35
31
  }
@@ -40,7 +36,6 @@ const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
40
36
  }
41
37
  return {
42
38
  scope: attr,
43
- message: t('{0:c} on {1}', t('{0} is {1:c}', t('the "{0*}" {1}', attr.name, `ARIA ${(_d = propSpec === null || propSpec === void 0 ? void 0 : propSpec.type) !== null && _d !== void 0 ? _d : 'property'}`), 'disallowed'), t('the "{0*}" {1}', role.name, 'role')),
39
+ message: t('{0:c} on {1}', t('{0} is {1:c}', t('the "{0*}" {1}', attr.name, `ARIA ${propSpec?.type ?? 'property'}`), 'disallowed'), t('the "{0*}" {1}', role.name, 'role')),
44
40
  };
45
41
  };
46
- exports.checkingDisallowedProp = checkingDisallowedProp;
@@ -1,11 +1,7 @@
1
- import type { Options } from '../types';
1
+ import type { Options } from '../types.js';
2
2
  import type { AttrChecker } from '@markuplint/ml-core';
3
3
  import type { ARIAProperty, Attribute } from '@markuplint/ml-spec';
4
- export declare const checkingImplicitProps: AttrChecker<
5
- boolean,
6
- Options,
7
- {
8
- propSpecs: readonly ARIAProperty[];
9
- attrSpecs: readonly Attribute[] | null;
10
- }
11
- >;
4
+ export declare const checkingImplicitProps: AttrChecker<boolean, Options, {
5
+ propSpecs: readonly ARIAProperty[];
6
+ attrSpecs: readonly Attribute[] | null;
7
+ }>;