@markuplint/rules 2.4.2 → 3.0.0-alpha.0

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 (98) hide show
  1. package/README.md +1 -5
  2. package/lib/attr-duplication/index.js +10 -7
  3. package/lib/attr-equal-space-after/index.d.ts +1 -1
  4. package/lib/attr-equal-space-before/index.d.ts +1 -1
  5. package/lib/attr-spacing/index.d.ts +3 -3
  6. package/lib/attr-value-quotes/index.js +21 -25
  7. package/lib/case-sensitive-attr-name/index.d.ts +1 -5
  8. package/lib/case-sensitive-attr-name/index.js +51 -81
  9. package/lib/case-sensitive-tag-name/index.js +38 -30
  10. package/lib/character-reference/index.d.ts +2 -1
  11. package/lib/character-reference/index.js +6 -8
  12. package/lib/class-naming/index.js +11 -11
  13. package/lib/deprecated-attr/index.js +17 -18
  14. package/lib/deprecated-element/index.js +5 -7
  15. package/lib/disallowed-element/index.js +8 -9
  16. package/lib/doctype/index.js +7 -7
  17. package/lib/end-tag/index.js +4 -1
  18. package/lib/helper/aria/get-aria.d.ts +7 -0
  19. package/lib/helper/aria/get-aria.js +53 -0
  20. package/lib/helper/aria/get-computed-role.d.ts +10 -0
  21. package/lib/helper/aria/get-computed-role.js +24 -0
  22. package/lib/helper/aria/get-implicit-role.d.ts +7 -0
  23. package/lib/helper/aria/get-implicit-role.js +12 -0
  24. package/lib/helper/aria/get-permitted-roles.d.ts +14 -0
  25. package/lib/helper/aria/get-permitted-roles.js +26 -0
  26. package/lib/helper/aria/resolve-version.d.ts +2 -0
  27. package/lib/helper/aria/resolve-version.js +21 -0
  28. package/lib/helper/spec/aria-spec.d.ts +5 -0
  29. package/lib/helper/spec/aria-spec.js +12 -0
  30. package/lib/helper/spec/get-role-spec.d.ts +11 -0
  31. package/lib/helper/spec/get-role-spec.js +39 -0
  32. package/lib/helper/spec/html-spec.d.ts +2 -0
  33. package/lib/helper/spec/html-spec.js +14 -0
  34. package/lib/helpers.d.ts +10 -28
  35. package/lib/helpers.js +29 -149
  36. package/lib/id-duplication/index.js +4 -6
  37. package/lib/indentation/index.d.ts +3 -3
  38. package/lib/index.d.ts +14 -19
  39. package/lib/index.js +0 -8
  40. package/lib/ineffective-attr/index.js +19 -27
  41. package/lib/invalid-attr/index.js +83 -83
  42. package/lib/landmark-roles/index.d.ts +2 -2
  43. package/lib/landmark-roles/index.js +9 -9
  44. package/lib/no-boolean-attr-value/index.js +33 -34
  45. package/lib/no-default-value/index.js +20 -24
  46. package/lib/no-hard-code-id/index.js +9 -13
  47. package/lib/no-refer-to-non-existent-id/index.d.ts +4 -1
  48. package/lib/no-refer-to-non-existent-id/index.js +77 -83
  49. package/lib/no-use-event-handler-attr/index.js +20 -22
  50. package/lib/permitted-contents/index.d.ts +5 -2
  51. package/lib/permitted-contents/index.js +67 -68
  52. package/lib/permitted-contents/permitted-content.spec-to-regexp.d.ts +5 -5
  53. package/lib/permitted-contents/permitted-content.spec-to-regexp.js +19 -14
  54. package/lib/permitted-contents/unfold-content-models-to-tags.d.ts +2 -2
  55. package/lib/require-accessible-name/index.d.ts +5 -1
  56. package/lib/require-accessible-name/index.js +6 -3
  57. package/lib/required-attr/index.js +16 -25
  58. package/lib/required-element/index.d.ts +1 -1
  59. package/lib/required-element/index.js +6 -6
  60. package/lib/required-h1/index.d.ts +2 -2
  61. package/lib/required-h1/index.js +3 -3
  62. package/lib/wai-aria/checkings/abstract-role.d.ts +3 -0
  63. package/lib/wai-aria/checkings/abstract-role.js +22 -0
  64. package/lib/wai-aria/checkings/checking-required-owned-elements.d.ts +11 -0
  65. package/lib/wai-aria/checkings/checking-required-owned-elements.js +63 -0
  66. package/lib/wai-aria/checkings/default-value.d.ts +6 -0
  67. package/lib/wai-aria/checkings/default-value.js +17 -0
  68. package/lib/wai-aria/checkings/deprecated-props.d.ts +7 -0
  69. package/lib/wai-aria/checkings/deprecated-props.js +18 -0
  70. package/lib/wai-aria/checkings/disallowed-prop.d.ts +7 -0
  71. package/lib/wai-aria/checkings/disallowed-prop.js +22 -0
  72. package/lib/wai-aria/checkings/implicit-props.d.ts +7 -0
  73. package/lib/wai-aria/checkings/implicit-props.js +50 -0
  74. package/lib/wai-aria/checkings/implicit-role.d.ts +3 -0
  75. package/lib/wai-aria/checkings/implicit-role.js +21 -0
  76. package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +11 -0
  77. package/lib/wai-aria/checkings/interaction-in-hidden.js +47 -0
  78. package/lib/wai-aria/checkings/no-global-prop.d.ts +6 -0
  79. package/lib/wai-aria/checkings/no-global-prop.js +14 -0
  80. package/lib/wai-aria/checkings/non-existant-role.d.ts +3 -0
  81. package/lib/wai-aria/checkings/non-existant-role.js +28 -0
  82. package/lib/wai-aria/checkings/permitted-roles.d.ts +3 -0
  83. package/lib/wai-aria/checkings/permitted-roles.js +28 -0
  84. package/lib/wai-aria/checkings/presentational-children.d.ts +29 -0
  85. package/lib/wai-aria/checkings/presentational-children.js +60 -0
  86. package/lib/wai-aria/checkings/required-owned-elements.d.ts +11 -0
  87. package/lib/wai-aria/checkings/required-owned-elements.js +63 -0
  88. package/lib/wai-aria/checkings/required-prop.d.ts +9 -0
  89. package/lib/wai-aria/checkings/required-prop.js +27 -0
  90. package/lib/wai-aria/checkings/value.d.ts +7 -0
  91. package/lib/wai-aria/checkings/value.js +21 -0
  92. package/lib/wai-aria/index.d.ts +1 -8
  93. package/lib/wai-aria/index.js +66 -207
  94. package/lib/wai-aria/types.d.ts +13 -0
  95. package/lib/wai-aria/types.js +2 -0
  96. package/package.json +6 -6
  97. package/schema.json +0 -12
  98. package/tsconfig.tsbuildinfo +1 -1
package/lib/index.d.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  declare const _default: {
2
2
  'attr-duplication': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, null>;
3
- 'attr-equal-space-after': import("packages/@markuplint/ml-core/lib").RuleSeed<"always" | "never" | "always-single-line" | "never-single-line", null>;
4
- 'attr-equal-space-before': import("packages/@markuplint/ml-core/lib").RuleSeed<"always" | "never" | "always-single-line" | "never-single-line", null>;
5
- 'attr-spacing': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, import("./attr-spacing").AttrSpasingOptions>;
6
3
  'attr-value-quotes': import("packages/@markuplint/ml-core/lib").RuleSeed<import("./attr-value-quotes").Type, null>;
7
- 'case-sensitive-attr-name': import("packages/@markuplint/ml-core/lib").RuleSeed<import("./case-sensitive-attr-name").Value | import("./case-sensitive-attr-name").Value_v1, null>;
4
+ 'case-sensitive-attr-name': import("packages/@markuplint/ml-core/lib").RuleSeed<import("./case-sensitive-attr-name").Value, null>;
8
5
  'case-sensitive-tag-name': import("packages/@markuplint/ml-core/lib").RuleSeed<import("./case-sensitive-tag-name").Value, null>;
9
6
  'character-reference': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, null>;
10
7
  'class-naming': import("packages/@markuplint/ml-core/lib").RuleSeed<import("./class-naming").Value, null>;
@@ -16,7 +13,6 @@ declare const _default: {
16
13
  }>;
17
14
  'end-tag': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, null>;
18
15
  'id-duplication': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, null>;
19
- indentation: import("packages/@markuplint/ml-core/lib").RuleSeed<import("./indentation").Value, import("./indentation").IndentationOptions>;
20
16
  'ineffective-attr': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, null>;
21
17
  'invalid-attr': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, {
22
18
  attrs?: Record<string, {
@@ -31,38 +27,37 @@ declare const _default: {
31
27
  ignoreAttrNamePrefix?: string | string[] | undefined;
32
28
  }>;
33
29
  'landmark-roles': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, {
34
- ignoreRoles?: (("banner" | "main" | "complementary" | "contentinfo") | "form" | "navigation" | "region")[] | undefined;
35
- labelEachArea?: boolean | undefined;
30
+ ignoreRoles: (("banner" | "main" | "complementary" | "contentinfo") | "form" | "navigation" | "region")[];
31
+ labelEachArea: boolean;
36
32
  }>;
37
33
  'no-boolean-attr-value': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, null>;
38
34
  'no-default-value': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, null>;
39
35
  'no-hard-code-id': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, null>;
40
- 'no-refer-to-non-existent-id': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, null>;
36
+ 'no-refer-to-non-existent-id': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-config/src").RuleConfigValue, {
37
+ ariaVersion: import("packages/@markuplint/ml-spec/lib").ARIAVersion;
38
+ }>;
41
39
  'no-use-event-handler-attr': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, {
42
40
  ignore?: string | string[] | undefined;
43
41
  }>;
44
- 'permitted-contents': import("packages/@markuplint/ml-core/lib").RuleSeed<import("packages/@markuplint/ml-spec/lib").PermittedStructuresSchema[], {
42
+ 'permitted-contents': import("packages/@markuplint/ml-core/lib").RuleSeed<(import("packages/@markuplint/ml-spec/lib").ContentModel & {
43
+ tag: string;
44
+ })[], {
45
45
  ignoreHasMutableChildren: boolean;
46
46
  }>;
47
- 'require-accessible-name': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, null>;
47
+ 'require-accessible-name': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, {
48
+ ariaVersion: import("packages/@markuplint/ml-spec/lib").ARIAVersion;
49
+ }>;
48
50
  'required-attr': import("packages/@markuplint/ml-core/lib").RuleSeed<string | (string | {
49
51
  name: string;
50
52
  value: string | string[];
51
53
  })[], null>;
52
54
  'required-element': import("packages/@markuplint/ml-core/lib").RuleSeed<string[], {
53
- ignoreHasMutableContents?: boolean | undefined;
55
+ ignoreHasMutableContents: boolean;
54
56
  }>;
55
57
  'required-h1': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, import("./required-h1").Options>;
56
58
  'use-list': import("packages/@markuplint/ml-core/lib").RuleSeed<string[], {
57
59
  spaceNeededBullets?: string[] | undefined;
58
60
  }>;
59
- 'wai-aria': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, {
60
- checkingValue?: boolean | undefined;
61
- checkingDeprecatedProps?: boolean | undefined;
62
- permittedAriaRoles?: boolean | undefined;
63
- disallowSetImplicitRole?: boolean | undefined;
64
- disallowSetImplicitProps?: boolean | undefined;
65
- disallowDefaultValue?: boolean | undefined;
66
- }>;
61
+ 'wai-aria': import("packages/@markuplint/ml-core/lib").RuleSeed<boolean, import("./wai-aria/types").Options>;
67
62
  };
68
63
  export default _default;
package/lib/index.js CHANGED
@@ -2,9 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const attr_duplication_1 = tslib_1.__importDefault(require("./attr-duplication"));
5
- const attr_equal_space_after_1 = tslib_1.__importDefault(require("./attr-equal-space-after"));
6
- const attr_equal_space_before_1 = tslib_1.__importDefault(require("./attr-equal-space-before"));
7
- const attr_spacing_1 = tslib_1.__importDefault(require("./attr-spacing"));
8
5
  const attr_value_quotes_1 = tslib_1.__importDefault(require("./attr-value-quotes"));
9
6
  const case_sensitive_attr_name_1 = tslib_1.__importDefault(require("./case-sensitive-attr-name"));
10
7
  const case_sensitive_tag_name_1 = tslib_1.__importDefault(require("./case-sensitive-tag-name"));
@@ -16,7 +13,6 @@ const disallowed_element_1 = tslib_1.__importDefault(require("./disallowed-eleme
16
13
  const doctype_1 = tslib_1.__importDefault(require("./doctype"));
17
14
  const end_tag_1 = tslib_1.__importDefault(require("./end-tag"));
18
15
  const id_duplication_1 = tslib_1.__importDefault(require("./id-duplication"));
19
- const indentation_1 = tslib_1.__importDefault(require("./indentation"));
20
16
  const ineffective_attr_1 = tslib_1.__importDefault(require("./ineffective-attr"));
21
17
  const invalid_attr_1 = tslib_1.__importDefault(require("./invalid-attr"));
22
18
  const landmark_roles_1 = tslib_1.__importDefault(require("./landmark-roles"));
@@ -34,9 +30,6 @@ const use_list_1 = tslib_1.__importDefault(require("./use-list"));
34
30
  const wai_aria_1 = tslib_1.__importDefault(require("./wai-aria"));
35
31
  exports.default = {
36
32
  'attr-duplication': attr_duplication_1.default,
37
- 'attr-equal-space-after': attr_equal_space_after_1.default,
38
- 'attr-equal-space-before': attr_equal_space_before_1.default,
39
- 'attr-spacing': attr_spacing_1.default,
40
33
  'attr-value-quotes': attr_value_quotes_1.default,
41
34
  'case-sensitive-attr-name': case_sensitive_attr_name_1.default,
42
35
  'case-sensitive-tag-name': case_sensitive_tag_name_1.default,
@@ -48,7 +41,6 @@ exports.default = {
48
41
  doctype: doctype_1.default,
49
42
  'end-tag': end_tag_1.default,
50
43
  'id-duplication': id_duplication_1.default,
51
- indentation: indentation_1.default,
52
44
  'ineffective-attr': ineffective_attr_1.default,
53
45
  'invalid-attr': invalid_attr_1.default,
54
46
  'landmark-roles': landmark_roles_1.default,
@@ -4,36 +4,28 @@ const ml_core_1 = require("@markuplint/ml-core");
4
4
  exports.default = (0, ml_core_1.createRule)({
5
5
  defaultServerity: 'warning',
6
6
  async verify({ document, report, t }) {
7
- await document.walkOn('Element', el => {
8
- const attrSpec = (0, ml_core_1.getAttrSpecs)(el.nameWithNS, document.specs);
7
+ await document.walkOn('Attr', attr => {
8
+ const attrSpec = (0, ml_core_1.getAttrSpecs)(attr.ownerElement, document.specs);
9
9
  if (!attrSpec) {
10
10
  return;
11
11
  }
12
- for (const attr of el.attributes) {
13
- if (attr.attrType === 'ps-attr') {
14
- continue;
15
- }
16
- const name = attr.getName().potential;
17
- const spec = attrSpec.find(s => s.name === name);
18
- if (!spec) {
19
- continue;
20
- }
21
- const ineffectiveConditions = spec.ineffective
22
- ? Array.isArray(spec.ineffective)
23
- ? spec.ineffective
24
- : [spec.ineffective]
25
- : [];
26
- if (ineffectiveConditions.some(selector => el.matches(selector))) {
27
- report({
28
- scope: el,
29
- raw: attr.raw,
30
- line: attr.startLine,
31
- col: attr.startCol,
32
- message: t('{0} is {1:c}', t('the "{0*}" {1}', name, 'attribute'), 'ineffective') +
33
- t('. ') +
34
- t("It doesn't need {0}", t('the {0}', 'attribute')),
35
- });
36
- }
12
+ const name = attr.name;
13
+ const spec = attrSpec.find(s => s.name === name);
14
+ if (!spec) {
15
+ return;
16
+ }
17
+ const ineffectiveConditions = spec.ineffective
18
+ ? Array.isArray(spec.ineffective)
19
+ ? spec.ineffective
20
+ : [spec.ineffective]
21
+ : [];
22
+ if (ineffectiveConditions.some(selector => attr.ownerElement.matches(selector))) {
23
+ report({
24
+ scope: attr,
25
+ message: t('{0} is {1:c}', t('the "{0*}" {1}', name, 'attribute'), 'ineffective') +
26
+ t('. ') +
27
+ t("It doesn't need {0}", t('the {0}', 'attribute')),
28
+ });
37
29
  }
38
30
  });
39
31
  },
@@ -8,100 +8,100 @@ const log = debug_1.log.extend('invalid-attr');
8
8
  exports.default = (0, ml_core_1.createRule)({
9
9
  defaultOptions: {},
10
10
  async verify({ document, report, t }) {
11
- await document.walkOn('Element', node => {
12
- var _a, _b, _c, _d, _e, _f, _g, _h;
13
- const attrSpecs = (0, ml_core_1.getAttrSpecs)(node.nameWithNS, document.specs);
14
- for (const attr of node.attributes) {
15
- if (attr.attrType === 'html-attr' && attr.isDirective) {
16
- continue;
11
+ await document.walkOn('Attr', attr => {
12
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
13
+ if (attr.isDirective) {
14
+ return;
15
+ }
16
+ const attrSpecs = (0, ml_core_1.getAttrSpecs)(attr.ownerElement, document.specs);
17
+ const attrName = attr.nameNode;
18
+ const name = attr.name;
19
+ if (!attr.ownerElement.isCustomElement && attr.candidate) {
20
+ const message = t('{0} is {1:c}', t('the "{0*}" {1}', name, 'attribute'), 'disallowed') +
21
+ t('. ') +
22
+ t('Did you mean "{0}"?', attr.candidate);
23
+ report({
24
+ scope: attr,
25
+ line: attrName === null || attrName === void 0 ? void 0 : attrName.startLine,
26
+ col: attrName === null || attrName === void 0 ? void 0 : attrName.startCol,
27
+ raw: attrName === null || attrName === void 0 ? void 0 : attrName.raw,
28
+ message: message,
29
+ });
30
+ return;
31
+ }
32
+ const valueNode = attr.valueNode;
33
+ const value = attr.value;
34
+ if (attr.rule.option.ignoreAttrNamePrefix) {
35
+ const ignoreAttrNamePrefixes = Array.isArray(attr.rule.option.ignoreAttrNamePrefix)
36
+ ? attr.rule.option.ignoreAttrNamePrefix
37
+ : [attr.rule.option.ignoreAttrNamePrefix];
38
+ if (ignoreAttrNamePrefixes.some(prefix => name.indexOf(prefix) === 0)) {
39
+ return;
17
40
  }
18
- const attrName = attr.getName();
19
- const name = attrName.potential;
20
- if (!node.isCustomElement && attr.attrType === 'html-attr' && attr.candidate) {
21
- const message = t('{0} is {1:c}', t('the "{0*}" {1}', attrName.raw, 'attribute'), 'disallowed') +
22
- t('. ') +
23
- t('Did you mean "{0}"?', attr.candidate);
24
- report({
25
- scope: node,
26
- message: message,
27
- line: attrName.line,
28
- col: attrName.col,
29
- raw: attrName.raw,
41
+ }
42
+ let invalid = false;
43
+ const customRule = attr.rule.option.attrs ? attr.rule.option.attrs[name] : null;
44
+ if (customRule) {
45
+ if ('enum' in customRule) {
46
+ invalid = (0, attr_check_1.attrCheck)(t, name.toLowerCase(), value, true, {
47
+ name,
48
+ type: {
49
+ enum: customRule.enum,
50
+ },
51
+ description: '',
30
52
  });
31
- continue;
32
- }
33
- const attrValue = attr.getValue();
34
- const value = attrValue.potential;
35
- if (node.rule.option.ignoreAttrNamePrefix) {
36
- const ignoreAttrNamePrefixes = Array.isArray(node.rule.option.ignoreAttrNamePrefix)
37
- ? node.rule.option.ignoreAttrNamePrefix
38
- : [node.rule.option.ignoreAttrNamePrefix];
39
- if (ignoreAttrNamePrefixes.some(prefix => name.indexOf(prefix) === 0)) {
40
- continue;
41
- }
42
53
  }
43
- let invalid = false;
44
- const customRule = node.rule.option.attrs ? node.rule.option.attrs[name] : null;
45
- if (customRule) {
46
- if (attr.attrType === 'html-attr' && attr.isDynamicValue) {
47
- continue;
48
- }
49
- if ('enum' in customRule) {
50
- invalid = (0, attr_check_1.attrCheck)(t, name.toLowerCase(), value, true, {
51
- name,
52
- type: {
53
- enum: customRule.enum,
54
- },
55
- description: '',
56
- });
57
- }
58
- else if ('pattern' in customRule) {
59
- if (!(0, helpers_1.match)(value, customRule.pattern)) {
60
- invalid = {
61
- invalidType: 'invalid-value',
62
- message: t('{0} is unmatched with the below patterns: {1}', t('the "{0*}" {1}', name, 'attribute'), customRule.pattern),
63
- };
64
- }
65
- }
66
- else if ('type' in customRule) {
67
- invalid = (0, attr_check_1.attrCheck)(t, name, value, true, { name, type: customRule.type, description: '' });
68
- }
69
- else if ('disallowed' in customRule && customRule.disallowed) {
54
+ else if ('pattern' in customRule) {
55
+ if (!(0, helpers_1.match)(value, customRule.pattern)) {
70
56
  invalid = {
71
- invalidType: 'non-existent',
72
- message: t('{0} is disallowed', t('the "{0*}" {1}', name, 'attribute')),
57
+ invalidType: 'invalid-value',
58
+ message: t('{0} is unmatched with the below patterns: {1}', t('the "{0*}" {1}', name, 'attribute'), customRule.pattern),
73
59
  };
74
60
  }
75
61
  }
76
- else if (!node.isCustomElement && attrSpecs) {
77
- log('Checking %s[%s="%s"]', node.nodeName, name, value);
78
- invalid = (0, helpers_1.isValidAttr)(t, name, value, (attr.attrType === 'html-attr' && attr.isDynamicValue) || false, node, attrSpecs, log);
62
+ else if ('type' in customRule) {
63
+ invalid = (0, attr_check_1.attrCheck)(t, name, value, true, { name, type: customRule.type, description: '' });
79
64
  }
80
- if (invalid) {
81
- switch (invalid.invalidType) {
82
- case 'invalid-value': {
83
- report({
84
- scope: node,
85
- message: invalid.message,
86
- line: attrValue.line + ((_b = (_a = invalid.loc) === null || _a === void 0 ? void 0 : _a.line) !== null && _b !== void 0 ? _b : 0),
87
- col: ((_c = invalid.loc) === null || _c === void 0 ? void 0 : _c.line) ? ((_d = invalid.loc) === null || _d === void 0 ? void 0 : _d.col) + 1 : attrValue.col + ((_f = (_e = invalid.loc) === null || _e === void 0 ? void 0 : _e.col) !== null && _f !== void 0 ? _f : 0),
88
- raw: (_h = (_g = invalid.loc) === null || _g === void 0 ? void 0 : _g.raw) !== null && _h !== void 0 ? _h : value,
89
- });
65
+ else if ('disallowed' in customRule && customRule.disallowed) {
66
+ invalid = {
67
+ invalidType: 'non-existent',
68
+ message: t('{0} is disallowed', t('the "{0*}" {1}', name, 'attribute')),
69
+ };
70
+ }
71
+ }
72
+ else if (!attr.ownerElement.isCustomElement && attrSpecs) {
73
+ log('Checking %s[%s="%s"]', attr.nodeName, name, value);
74
+ invalid = (0, helpers_1.isValidAttr)(t, name, value, attr.isDynamicValue || false, attr.ownerElement, attrSpecs, log);
75
+ }
76
+ if (invalid) {
77
+ switch (invalid.invalidType) {
78
+ case 'invalid-value': {
79
+ if (attr.isDynamicValue) {
90
80
  break;
91
81
  }
92
- case 'non-existent': {
93
- const spec = (0, helpers_1.htmlSpec)(document.specs, node.nameWithNS);
94
- if (spec === null || spec === void 0 ? void 0 : spec.possibleToAddProperties) {
95
- continue;
96
- }
97
- report({
98
- scope: node,
99
- message: invalid.message,
100
- line: attrName.line,
101
- col: attrName.col,
102
- raw: attrName.raw,
103
- });
82
+ report({
83
+ scope: attr,
84
+ message: invalid.message,
85
+ line: ((_a = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startLine) !== null && _a !== void 0 ? _a : 0) + ((_c = (_b = invalid.loc) === null || _b === void 0 ? void 0 : _b.line) !== null && _c !== void 0 ? _c : 0),
86
+ col: ((_d = invalid.loc) === null || _d === void 0 ? void 0 : _d.line)
87
+ ? ((_e = invalid.loc) === null || _e === void 0 ? void 0 : _e.col) + 1
88
+ : ((_f = valueNode === null || valueNode === void 0 ? void 0 : valueNode.startCol) !== null && _f !== void 0 ? _f : 0) + ((_h = (_g = invalid.loc) === null || _g === void 0 ? void 0 : _g.col) !== null && _h !== void 0 ? _h : 0),
89
+ raw: (_k = (_j = invalid.loc) === null || _j === void 0 ? void 0 : _j.raw) !== null && _k !== void 0 ? _k : value,
90
+ });
91
+ break;
92
+ }
93
+ case 'non-existent': {
94
+ const spec = (0, ml_core_1.getSpec)(attr.ownerElement, document.specs);
95
+ if (spec === null || spec === void 0 ? void 0 : spec.possibleToAddProperties) {
96
+ return;
104
97
  }
98
+ report({
99
+ scope: attr,
100
+ message: invalid.message,
101
+ line: attrName === null || attrName === void 0 ? void 0 : attrName.startLine,
102
+ col: attrName === null || attrName === void 0 ? void 0 : attrName.startCol,
103
+ raw: attrName === null || attrName === void 0 ? void 0 : attrName.raw,
104
+ });
105
105
  }
106
106
  }
107
107
  }
@@ -1,6 +1,6 @@
1
1
  declare type Options = {
2
- ignoreRoles?: Roles[];
3
- labelEachArea?: boolean;
2
+ ignoreRoles: Roles[];
3
+ labelEachArea: boolean;
4
4
  };
5
5
  declare type TopLevelRoles = 'banner' | 'main' | 'complementary' | 'contentinfo';
6
6
  declare type Roles = TopLevelRoles | 'form' | 'navigation' | 'region';
@@ -23,13 +23,13 @@ exports.default = (0, ml_core_1.createRule)({
23
23
  return;
24
24
  }
25
25
  const roles = {
26
- complementary: document.matchNodes(selectors.complementary.join(',')),
27
- contentinfo: document.matchNodes(selectors.contentinfo.join(',')),
28
- form: document.matchNodes(selectors.form.join(',')),
29
- banner: document.matchNodes(selectors.banner.join(',')),
30
- main: document.matchNodes(selectors.main.join(',')),
31
- navigation: document.matchNodes(selectors.navigation.join(',')),
32
- region: document.matchNodes(selectors.region.join(',')),
26
+ complementary: Array.from(document.querySelectorAll(selectors.complementary.join(','))),
27
+ contentinfo: Array.from(document.querySelectorAll(selectors.contentinfo.join(','))),
28
+ form: Array.from(document.querySelectorAll(selectors.form.join(','))),
29
+ banner: Array.from(document.querySelectorAll(selectors.banner.join(','))),
30
+ main: Array.from(document.querySelectorAll(selectors.main.join(','))),
31
+ navigation: Array.from(document.querySelectorAll(selectors.navigation.join(','))),
32
+ region: Array.from(document.querySelectorAll(selectors.region.join(','))),
33
33
  };
34
34
  /**
35
35
  * `<header>`
@@ -43,7 +43,7 @@ exports.default = (0, ml_core_1.createRule)({
43
43
  * > - nav
44
44
  * > - section
45
45
  */
46
- const headers = document.matchNodes('header').filter(header => {
46
+ const headers = Array.from(document.querySelectorAll('header')).filter(header => {
47
47
  return !header.closest('article, aside, main, nav, section');
48
48
  });
49
49
  roles.banner.push(...headers);
@@ -59,7 +59,7 @@ exports.default = (0, ml_core_1.createRule)({
59
59
  * > - nav
60
60
  * > - section
61
61
  */
62
- const footers = document.matchNodes('footer').filter(footer => {
62
+ const footers = Array.from(document.querySelectorAll('footer')).filter(footer => {
63
63
  return !footer.closest('article, aside, main, nav, section');
64
64
  });
65
65
  roles.contentinfo.push(...footers);
@@ -4,43 +4,42 @@ const ml_core_1 = require("@markuplint/ml-core");
4
4
  exports.default = (0, ml_core_1.createRule)({
5
5
  defaultServerity: 'warning',
6
6
  async verify({ document, report, t }) {
7
- await document.walkOn('Element', el => {
8
- const attrSpec = (0, ml_core_1.getAttrSpecs)(el.nameWithNS, document.specs);
7
+ await document.walkOn('Attr', attr => {
8
+ var _a, _b;
9
+ const attrSpec = (0, ml_core_1.getAttrSpecs)(attr.ownerElement, document.specs);
9
10
  if (!attrSpec) {
10
11
  return;
11
12
  }
12
- for (const attr of el.attributes) {
13
- if (attr.attrType === 'ps-attr' || attr.isDynamicValue) {
14
- continue;
15
- }
16
- const name = attr.getName().potential;
17
- const spec = attrSpec.find(s => s.name === name);
18
- if (!spec) {
19
- continue;
20
- }
21
- if (spec.type !== 'Boolean') {
22
- continue;
23
- }
24
- const extraTokens = [
25
- attr.spacesBeforeEqual,
26
- attr.equal,
27
- attr.spacesAfterEqual,
28
- attr.startQuote,
29
- attr.valueNode,
30
- attr.endQuote,
31
- ];
32
- const extraRaw = extraTokens.reduce((raw, t) => raw + t.raw, '');
33
- if (extraRaw) {
34
- report({
35
- scope: el,
36
- raw: extraRaw,
37
- line: attr.spacesBeforeEqual.startLine,
38
- col: attr.spacesBeforeEqual.startCol,
39
- message: t('{0} is {1}', t('the "{0*}" {1}', name, 'attribute'), t('a {0}', 'boolean attribute')) +
40
- t('. ') +
41
- t("It doesn't need {0}", t('the {0}', 'value')),
42
- });
43
- }
13
+ if (attr.isDynamicValue) {
14
+ return;
15
+ }
16
+ const name = attr.name;
17
+ const spec = attrSpec.find(s => s.name === name);
18
+ if (!spec) {
19
+ return;
20
+ }
21
+ if (spec.type !== 'Boolean') {
22
+ return;
23
+ }
24
+ const extraTokens = [
25
+ attr.spacesBeforeEqual,
26
+ attr.equal,
27
+ attr.spacesAfterEqual,
28
+ attr.startQuote,
29
+ attr.valueNode,
30
+ attr.endQuote,
31
+ ];
32
+ const extraRaw = extraTokens.reduce((raw, t) => { var _a; return raw + ((_a = t === null || t === void 0 ? void 0 : t.raw) !== null && _a !== void 0 ? _a : ''); }, '');
33
+ if (extraRaw) {
34
+ report({
35
+ scope: attr,
36
+ line: (_a = attr.spacesBeforeEqual) === null || _a === void 0 ? void 0 : _a.startLine,
37
+ col: (_b = attr.spacesBeforeEqual) === null || _b === void 0 ? void 0 : _b.startCol,
38
+ raw: extraRaw,
39
+ message: t('{0} is {1}', t('the "{0*}" {1}', name, 'attribute'), t('a {0}', 'boolean attribute')) +
40
+ t('. ') +
41
+ t("It doesn't need {0}", t('the {0}', 'value')),
42
+ });
44
43
  }
45
44
  });
46
45
  },
@@ -5,33 +5,29 @@ const helpers_1 = require("../helpers");
5
5
  exports.default = (0, ml_core_1.createRule)({
6
6
  defaultServerity: 'warning',
7
7
  async verify({ document, report, t }) {
8
- await document.walkOn('Element', el => {
9
- const attrSpec = (0, ml_core_1.getAttrSpecs)(el.nameWithNS, document.specs);
8
+ await document.walkOn('Attr', attr => {
9
+ var _a, _b, _c;
10
+ const attrSpec = (0, ml_core_1.getAttrSpecs)(attr.ownerElement, document.specs);
10
11
  if (!attrSpec) {
11
12
  return;
12
13
  }
13
- for (const attr of el.attributes) {
14
- if (attr.attrType !== 'html-attr') {
15
- continue;
16
- }
17
- const spec = attrSpec.find(s => s.name === attr.getName().potential);
18
- if (!spec) {
19
- continue;
20
- }
21
- if (!spec.defaultValue) {
22
- continue;
23
- }
24
- const normalizedValue = (0, helpers_1.toNormalizedValue)(attr.getValue().potential, spec);
25
- const defaultValue = (0, helpers_1.toNormalizedValue)(spec.defaultValue, spec);
26
- if (defaultValue === normalizedValue) {
27
- report({
28
- scope: el,
29
- line: attr.valueNode.startLine,
30
- col: attr.valueNode.startCol,
31
- raw: attr.valueNode.raw,
32
- message: t('It is {0}', t('the {0}', 'default value')),
33
- });
34
- }
14
+ const spec = attrSpec.find(s => s.name === attr.name);
15
+ if (!spec) {
16
+ return;
17
+ }
18
+ if (!spec.defaultValue) {
19
+ return;
20
+ }
21
+ const normalizedValue = (0, helpers_1.toNormalizedValue)(attr.value, spec);
22
+ const defaultValue = (0, helpers_1.toNormalizedValue)(spec.defaultValue, spec);
23
+ if (defaultValue === normalizedValue) {
24
+ report({
25
+ scope: attr,
26
+ line: (_a = attr.valueNode) === null || _a === void 0 ? void 0 : _a.startLine,
27
+ col: (_b = attr.valueNode) === null || _b === void 0 ? void 0 : _b.startCol,
28
+ raw: (_c = attr.valueNode) === null || _c === void 0 ? void 0 : _c.raw,
29
+ message: t('It is {0}', t('the {0}', 'default value')),
30
+ });
35
31
  }
36
32
  });
37
33
  },
@@ -7,19 +7,15 @@ exports.default = (0, ml_core_1.createRule)({
7
7
  if (!document.isFragment) {
8
8
  return;
9
9
  }
10
- await document.walkOn('Element', el => {
11
- for (const attr of el.attributes) {
12
- if (attr.potentialName.toLowerCase() === 'id' &&
13
- ((attr.attrType === 'html-attr' && !attr.isDynamicValue) ||
14
- (attr.attrType === 'ps-attr' && attr.valueType !== 'code'))) {
15
- report({
16
- scope: el,
17
- line: attr.startLine,
18
- col: attr.startCol,
19
- raw: attr.raw,
20
- message: t('It is {0:c}', 'hard-coded'),
21
- });
22
- }
10
+ await document.walkOn('Attr', attr => {
11
+ if (attr.name.toLowerCase() === 'id' && !attr.isDynamicValue && attr.valueType !== 'code') {
12
+ report({
13
+ scope: attr,
14
+ line: attr.startLine,
15
+ col: attr.startCol,
16
+ raw: attr.raw,
17
+ message: t('It is {0:c}', 'hard-coded'),
18
+ });
23
19
  }
24
20
  });
25
21
  },
@@ -1,2 +1,5 @@
1
- declare const _default: import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, null>;
1
+ import type { ARIAVersion } from '@markuplint/ml-spec';
2
+ declare const _default: import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, {
3
+ ariaVersion: ARIAVersion;
4
+ }>;
2
5
  export default _default;