@markuplint/rules 2.4.3 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +2 -6
  2. package/lib/attr-check.js +1 -1
  3. package/lib/attr-duplication/index.js +10 -7
  4. package/lib/attr-value-quotes/index.js +22 -26
  5. package/lib/case-sensitive-attr-name/index.d.ts +1 -5
  6. package/lib/case-sensitive-attr-name/index.js +52 -82
  7. package/lib/case-sensitive-tag-name/index.js +39 -31
  8. package/lib/character-reference/index.d.ts +2 -1
  9. package/lib/character-reference/index.js +6 -8
  10. package/lib/class-naming/index.js +12 -12
  11. package/lib/create-message.d.ts +1 -1
  12. package/lib/create-message.js +5 -5
  13. package/lib/deprecated-attr/index.js +17 -18
  14. package/lib/deprecated-element/index.js +5 -7
  15. package/lib/disallowed-element/index.js +8 -9
  16. package/lib/doctype/index.d.ts +1 -1
  17. package/lib/doctype/index.js +8 -8
  18. package/lib/end-tag/index.js +5 -2
  19. package/lib/helpers.d.ts +15 -28
  20. package/lib/helpers.js +42 -156
  21. package/lib/id-duplication/index.js +4 -6
  22. package/lib/index.d.ts +12 -21
  23. package/lib/index.js +0 -8
  24. package/lib/ineffective-attr/index.js +20 -28
  25. package/lib/invalid-attr/index.js +83 -83
  26. package/lib/landmark-roles/index.d.ts +2 -2
  27. package/lib/landmark-roles/index.js +10 -10
  28. package/lib/no-boolean-attr-value/index.js +34 -35
  29. package/lib/no-default-value/index.js +21 -25
  30. package/lib/no-hard-code-id/index.js +10 -14
  31. package/lib/no-refer-to-non-existent-id/index.d.ts +4 -1
  32. package/lib/no-refer-to-non-existent-id/index.js +77 -83
  33. package/lib/no-use-event-handler-attr/index.js +21 -23
  34. package/lib/permitted-contents/choice.d.ts +3 -0
  35. package/lib/permitted-contents/choice.js +37 -0
  36. package/lib/permitted-contents/complex-branch.d.ts +13 -0
  37. package/lib/permitted-contents/complex-branch.js +27 -0
  38. package/lib/permitted-contents/content-model.d.ts +2 -0
  39. package/lib/permitted-contents/content-model.js +49 -0
  40. package/lib/permitted-contents/count-pattern.d.ts +13 -0
  41. package/lib/permitted-contents/count-pattern.js +155 -0
  42. package/lib/permitted-contents/debug.d.ts +2 -0
  43. package/lib/permitted-contents/debug.js +5 -0
  44. package/lib/permitted-contents/index.d.ts +2 -5
  45. package/lib/permitted-contents/index.js +78 -249
  46. package/lib/permitted-contents/matches-selector.d.ts +3 -0
  47. package/lib/permitted-contents/matches-selector.js +185 -0
  48. package/lib/permitted-contents/order.d.ts +13 -0
  49. package/lib/permitted-contents/order.js +89 -0
  50. package/lib/permitted-contents/recursive-branch.d.ts +4 -0
  51. package/lib/permitted-contents/recursive-branch.js +43 -0
  52. package/lib/permitted-contents/represent-transparent-nodes.d.ts +6 -0
  53. package/lib/permitted-contents/represent-transparent-nodes.js +79 -0
  54. package/lib/permitted-contents/start.d.ts +12 -0
  55. package/lib/permitted-contents/start.js +71 -0
  56. package/lib/permitted-contents/transparent.d.ts +2 -0
  57. package/lib/permitted-contents/transparent.js +34 -0
  58. package/lib/permitted-contents/types.d.ts +45 -0
  59. package/lib/permitted-contents/types.js +2 -0
  60. package/lib/permitted-contents/utils.d.ts +32 -0
  61. package/lib/permitted-contents/utils.js +184 -0
  62. package/lib/require-accessible-name/index.d.ts +5 -1
  63. package/lib/require-accessible-name/index.js +11 -4
  64. package/lib/required-attr/index.js +16 -25
  65. package/lib/required-element/index.d.ts +1 -1
  66. package/lib/required-element/index.js +6 -6
  67. package/lib/required-h1/index.d.ts +2 -2
  68. package/lib/required-h1/index.js +3 -3
  69. package/lib/use-list/index.js +2 -2
  70. package/lib/wai-aria/checkings/abstract-role.d.ts +3 -0
  71. package/lib/wai-aria/checkings/abstract-role.js +22 -0
  72. package/lib/wai-aria/checkings/default-value.d.ts +6 -0
  73. package/lib/wai-aria/checkings/default-value.js +17 -0
  74. package/lib/wai-aria/checkings/deprecated-props.d.ts +7 -0
  75. package/lib/wai-aria/checkings/deprecated-props.js +18 -0
  76. package/lib/wai-aria/checkings/disallowed-prop.d.ts +7 -0
  77. package/lib/wai-aria/checkings/disallowed-prop.js +22 -0
  78. package/lib/wai-aria/checkings/implicit-props.d.ts +7 -0
  79. package/lib/wai-aria/checkings/implicit-props.js +50 -0
  80. package/lib/wai-aria/checkings/implicit-role.d.ts +3 -0
  81. package/lib/wai-aria/checkings/implicit-role.js +21 -0
  82. package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +11 -0
  83. package/lib/wai-aria/checkings/interaction-in-hidden.js +47 -0
  84. package/lib/wai-aria/checkings/no-global-prop.d.ts +6 -0
  85. package/lib/wai-aria/checkings/no-global-prop.js +14 -0
  86. package/lib/wai-aria/checkings/non-existant-role.d.ts +3 -0
  87. package/lib/wai-aria/checkings/non-existant-role.js +28 -0
  88. package/lib/wai-aria/checkings/permitted-roles.d.ts +3 -0
  89. package/lib/wai-aria/checkings/permitted-roles.js +28 -0
  90. package/lib/wai-aria/checkings/presentational-children.d.ts +29 -0
  91. package/lib/wai-aria/checkings/presentational-children.js +60 -0
  92. package/lib/wai-aria/checkings/required-owned-elements.d.ts +11 -0
  93. package/lib/wai-aria/checkings/required-owned-elements.js +63 -0
  94. package/lib/wai-aria/checkings/required-prop.d.ts +9 -0
  95. package/lib/wai-aria/checkings/required-prop.js +27 -0
  96. package/lib/wai-aria/checkings/value.d.ts +7 -0
  97. package/lib/wai-aria/checkings/value.js +21 -0
  98. package/lib/wai-aria/index.d.ts +1 -8
  99. package/lib/wai-aria/index.js +66 -207
  100. package/lib/wai-aria/types.d.ts +13 -0
  101. package/lib/wai-aria/types.js +2 -0
  102. package/package.json +8 -7
  103. package/schema.json +0 -12
  104. package/tsconfig.tsbuildinfo +1 -1
  105. package/lib/attr-equal-space-after/index.d.ts +0 -3
  106. package/lib/attr-equal-space-after/index.js +0 -90
  107. package/lib/attr-equal-space-before/index.d.ts +0 -3
  108. package/lib/attr-equal-space-before/index.js +0 -90
  109. package/lib/attr-spacing/index.d.ts +0 -6
  110. package/lib/attr-spacing/index.js +0 -100
  111. package/lib/indentation/index.d.ts +0 -7
  112. package/lib/indentation/index.js +0 -208
  113. package/lib/permitted-contents/array.combination.d.ts +0 -1
  114. package/lib/permitted-contents/array.combination.js +0 -33
  115. package/lib/permitted-contents/permitted-content.spec-to-regexp.d.ts +0 -11
  116. package/lib/permitted-contents/permitted-content.spec-to-regexp.js +0 -225
  117. package/lib/permitted-contents/unfold-content-models-to-tags.d.ts +0 -2
  118. package/lib/permitted-contents/unfold-content-models-to-tags.js +0 -8
@@ -3,35 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  const helpers_1 = require("../helpers");
5
5
  exports.default = (0, ml_core_1.createRule)({
6
- defaultServerity: 'warning',
6
+ defaultSeverity: 'warning',
7
7
  defaultOptions: {},
8
8
  async verify({ document, report, t }) {
9
- await document.walkOn('Element', el => {
10
- if (el.isCustomElement) {
9
+ await document.walkOn('Attr', attr => {
10
+ if (attr.ownerElement.elementType !== 'html') {
11
11
  return;
12
12
  }
13
- const ignoreList = Array.isArray(el.rule.option.ignore)
14
- ? el.rule.option.ignore
15
- : el.rule.option.ignore
16
- ? [el.rule.option.ignore]
13
+ const ignoreList = Array.isArray(attr.rule.option.ignore)
14
+ ? attr.rule.option.ignore
15
+ : attr.rule.option.ignore
16
+ ? [attr.rule.option.ignore]
17
17
  : [];
18
- el.attributes.forEach(attr => {
19
- const name = attr.getName().potential;
20
- for (const ignore of ignoreList) {
21
- if ((0, helpers_1.match)(name, ignore)) {
22
- return;
23
- }
18
+ const name = attr.name;
19
+ for (const ignore of ignoreList) {
20
+ if ((0, helpers_1.match)(name, ignore)) {
21
+ return;
24
22
  }
25
- if (/^on/i.test(name)) {
26
- report({
27
- scope: el,
28
- raw: attr.raw,
29
- line: attr.startLine,
30
- col: attr.startCol,
31
- message: t('{0} is disallowed', t('the "{0*}" {1}', name, 'attribute')),
32
- });
33
- }
34
- });
23
+ }
24
+ if (/^on/i.test(name)) {
25
+ report({
26
+ scope: attr,
27
+ raw: attr.raw,
28
+ line: attr.startLine,
29
+ col: attr.startCol,
30
+ message: t('{0} is disallowed', t('the "{0*}" {1}', name, 'attribute')),
31
+ });
32
+ }
35
33
  });
36
34
  },
37
35
  });
@@ -0,0 +1,3 @@
1
+ import type { ChildNode, Options, Result, Specs } from './types';
2
+ import type { PermittedContentChoice } from '@markuplint/ml-spec';
3
+ export declare function choice(pattern: PermittedContentChoice, elements: ChildNode[], specs: Specs, options: Options, depth: number): Result;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.choice = void 0;
4
+ const order_1 = require("./order");
5
+ const utils_1 = require("./utils");
6
+ function choice(pattern, elements, specs, options, depth) {
7
+ const collection = new utils_1.Collection(elements);
8
+ const unmatchedResults = [];
9
+ for (const some of pattern.choice) {
10
+ const result = (0, order_1.order)(some, collection.unmatched, specs, options, depth + 1);
11
+ if (result.type === 'UNEXPECTED_EXTRA_NODE' || result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
12
+ collection.addMatched(result.matched);
13
+ return {
14
+ type: result.type,
15
+ matched: collection.matched,
16
+ unmatched: collection.unmatched,
17
+ zeroMatch: result.zeroMatch,
18
+ query: result.query,
19
+ hint: result.hint,
20
+ };
21
+ }
22
+ unmatchedResults.push(result);
23
+ }
24
+ const barelyMatchedResult = unmatchedResults.sort((a, b) => b.matched.length - a.matched.length)[0];
25
+ if (!barelyMatchedResult) {
26
+ throw new Error('Unreachable code');
27
+ }
28
+ return {
29
+ type: barelyMatchedResult.type,
30
+ matched: collection.matched,
31
+ unmatched: collection.unmatched,
32
+ zeroMatch: barelyMatchedResult.zeroMatch,
33
+ query: barelyMatchedResult.query,
34
+ hint: barelyMatchedResult.hint,
35
+ };
36
+ }
37
+ exports.choice = choice;
@@ -0,0 +1,13 @@
1
+ import type { ChildNode, Options, Result, Specs } from './types';
2
+ import type { PermittedContentPattern } from '@markuplint/ml-spec';
3
+ /**
4
+ * Check content condition
5
+ *
6
+ * @param pattern
7
+ * @param elements
8
+ * @param specs
9
+ * @param options
10
+ * @param depth
11
+ * @returns
12
+ */
13
+ export declare function complexBranch(pattern: PermittedContentPattern, elements: ChildNode[], specs: Specs, options: Options, depth: number): Result;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.complexBranch = void 0;
4
+ const choice_1 = require("./choice");
5
+ const count_pattern_1 = require("./count-pattern");
6
+ const transparent_1 = require("./transparent");
7
+ const utils_1 = require("./utils");
8
+ /**
9
+ * Check content condition
10
+ *
11
+ * @param pattern
12
+ * @param elements
13
+ * @param specs
14
+ * @param options
15
+ * @param depth
16
+ * @returns
17
+ */
18
+ function complexBranch(pattern, elements, specs, options, depth) {
19
+ if ((0, utils_1.isChoice)(pattern)) {
20
+ return (0, choice_1.choice)(pattern, elements, specs, options, depth);
21
+ }
22
+ if ((0, utils_1.isTransparent)(pattern)) {
23
+ return (0, transparent_1.transparent)(elements, specs, options, depth);
24
+ }
25
+ return (0, count_pattern_1.countPattern)(pattern, elements, specs, options, depth);
26
+ }
27
+ exports.complexBranch = complexBranch;
@@ -0,0 +1,2 @@
1
+ import type { ContentModelResult, Element, Options, TagRule } from './types';
2
+ export declare function contentModel(el: Element, rules: TagRule[], options: Options): ContentModelResult[];
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contentModel = void 0;
4
+ const ml_spec_1 = require("@markuplint/ml-spec");
5
+ const start_1 = require("./start");
6
+ function contentModel(el, rules, options) {
7
+ const model = createModel(el, rules);
8
+ if (model == null) {
9
+ return [
10
+ {
11
+ type: 'MATCHED',
12
+ scope: el,
13
+ query: '*',
14
+ hint: {},
15
+ },
16
+ ];
17
+ }
18
+ const result = (0, start_1.start)(model, el, el.ownerMLDocument.specs, options);
19
+ return result;
20
+ }
21
+ exports.contentModel = contentModel;
22
+ function createModel(el, rules) {
23
+ const specs = cachedSpecs(el.ownerMLDocument.specs, rules);
24
+ const model = (0, ml_spec_1.getContentModel)(el, specs.specs);
25
+ return model;
26
+ }
27
+ const caches = new Map();
28
+ function cachedSpecs(specs, rules) {
29
+ if (!rules.length) {
30
+ return specs;
31
+ }
32
+ const key = JSON.stringify(rules);
33
+ const cached = caches.get(key);
34
+ if (cached) {
35
+ return cached;
36
+ }
37
+ const merged = {
38
+ ...specs,
39
+ specs: [
40
+ ...specs.specs,
41
+ ...rules.map(tag => ({
42
+ name: tag.tag,
43
+ contentModel: tag,
44
+ })),
45
+ ],
46
+ };
47
+ caches.set(key, merged);
48
+ return merged;
49
+ }
@@ -0,0 +1,13 @@
1
+ import type { ChildNode, Options, Result, Specs } from './types';
2
+ import type { PermittedContentOneOrMore, PermittedContentOptional, PermittedContentRequire, PermittedContentZeroOrMore } from '@markuplint/ml-spec';
3
+ /**
4
+ * Check count
5
+ *
6
+ * @param pattern
7
+ * @param elements
8
+ * @param specs
9
+ * @param options
10
+ * @param depth
11
+ * @returns
12
+ */
13
+ export declare function countPattern(pattern: PermittedContentOneOrMore | PermittedContentOptional | PermittedContentRequire | PermittedContentZeroOrMore, elements: readonly ChildNode[], specs: Specs, options: Options, depth: number): Result;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.countPattern = void 0;
4
+ const debug_1 = require("./debug");
5
+ const recursive_branch_1 = require("./recursive-branch");
6
+ const utils_1 = require("./utils");
7
+ /**
8
+ * Check count
9
+ *
10
+ * @param pattern
11
+ * @param elements
12
+ * @param specs
13
+ * @param options
14
+ * @param depth
15
+ * @returns
16
+ */
17
+ function countPattern(pattern, elements, specs, options, depth) {
18
+ var _a, _b, _c, _d, _e;
19
+ const ptLog = debug_1.cmLog.extend(`countPattern#${depth}`);
20
+ const collection = new utils_1.Collection(elements);
21
+ let min;
22
+ let max;
23
+ let model;
24
+ let type;
25
+ let _type;
26
+ if ((0, utils_1.isRequire)(pattern)) {
27
+ min = (_a = pattern.min) !== null && _a !== void 0 ? _a : 1;
28
+ max = Math.max((_b = pattern.max) !== null && _b !== void 0 ? _b : 1, min);
29
+ model = pattern.require;
30
+ type = 'MISSING_NODE_REQUIRED';
31
+ _type = 'require';
32
+ }
33
+ else if ((0, utils_1.isOptional)(pattern)) {
34
+ min = 0;
35
+ max = Math.max((_c = pattern.max) !== null && _c !== void 0 ? _c : 1, 1);
36
+ model = pattern.optional;
37
+ _type = 'optional';
38
+ }
39
+ else if ((0, utils_1.isOneOrMore)(pattern)) {
40
+ min = 1;
41
+ max = Math.max((_d = pattern.max) !== null && _d !== void 0 ? _d : Infinity, 1);
42
+ model = pattern.oneOrMore;
43
+ type = 'MISSING_NODE_ONE_OR_MORE';
44
+ _type = 'one or more';
45
+ }
46
+ else if ((0, utils_1.isZeroOrMore)(pattern)) {
47
+ min = 0;
48
+ max = Math.max((_e = pattern.max) !== null && _e !== void 0 ? _e : Infinity, 1);
49
+ model = pattern.zeroOrMore;
50
+ _type = 'zero or more';
51
+ }
52
+ else {
53
+ throw new Error('Unreachable code');
54
+ }
55
+ ptLog('%s: %o', _type, model);
56
+ let prevResult = null;
57
+ // eslint-disable-next-line no-constant-condition
58
+ while (true) {
59
+ ptLog('%s', collection);
60
+ const result = (0, recursive_branch_1.recursiveBranch)(model, collection.unmatched, specs, options, depth);
61
+ const added = collection.addMatched(result.matched);
62
+ if (result.type === 'UNMATCHED_SELECTOR_BUT_MAY_EMPTY') {
63
+ ptLog('MATCHED_ZERO: %s', result.query);
64
+ return {
65
+ type: 'MATCHED_ZERO',
66
+ matched: collection.matched,
67
+ unmatched: collection.unmatched,
68
+ zeroMatch: true,
69
+ query: result.query,
70
+ hint: result.hint,
71
+ };
72
+ }
73
+ if (max < collection.matchedCount) {
74
+ collection.max(max);
75
+ ptLog('UNEXPECTED_EXTRA_NODE (max: %s): %s', max, result.query);
76
+ return {
77
+ type: 'UNEXPECTED_EXTRA_NODE',
78
+ matched: collection.matched,
79
+ unmatched: collection.unmatched,
80
+ zeroMatch: result.zeroMatch,
81
+ query: result.query,
82
+ hint: {
83
+ ...result.hint,
84
+ max,
85
+ },
86
+ };
87
+ }
88
+ if (prevResult) {
89
+ if (result.type === 'MISSING_NODE_ONE_OR_MORE' ||
90
+ result.type === 'MISSING_NODE_REQUIRED' ||
91
+ result.type === 'TRANSPARENT_MODEL_DISALLOWS') {
92
+ ptLog('%s(continued): %s', result.type, collection);
93
+ return {
94
+ type: result.type,
95
+ matched: collection.matched,
96
+ unmatched: collection.unmatched,
97
+ zeroMatch: result.zeroMatch,
98
+ query: result.query,
99
+ hint: result.hint,
100
+ };
101
+ }
102
+ ptLog('%s(continued): %s', prevResult.type, collection);
103
+ return prevResult;
104
+ }
105
+ if (added && collection.unmatched.length > 0) {
106
+ continue;
107
+ }
108
+ if (collection.matchedCount + (result.zeroMatch ? 1 : 0) < min) {
109
+ const resultType = result.type === 'MISSING_NODE_REQUIRED' ||
110
+ result.type === 'MISSING_NODE_ONE_OR_MORE' ||
111
+ result.type === 'TRANSPARENT_MODEL_DISALLOWS'
112
+ ? result.type
113
+ : type !== null && type !== void 0 ? type : 'MISSING_NODE_REQUIRED';
114
+ ptLog('%s(in %s): %s', resultType, type, result.query);
115
+ return {
116
+ type: resultType,
117
+ matched: collection.matched,
118
+ unmatched: collection.unmatched,
119
+ zeroMatch: result.zeroMatch,
120
+ query: result.query,
121
+ hint: result.hint,
122
+ };
123
+ }
124
+ const resultType = collection.matched.length === 0 ? 'MATCHED_ZERO' : 'MATCHED';
125
+ const zeroMatch = result.zeroMatch || min === 0 || resultType === 'MATCHED_ZERO';
126
+ const matchedResult = {
127
+ type: resultType,
128
+ matched: collection.matched,
129
+ unmatched: collection.unmatched,
130
+ zeroMatch,
131
+ query: result.query,
132
+ hint: result.hint,
133
+ };
134
+ if (!prevResult && collection.unmatched.length) {
135
+ ptLog('continue checking');
136
+ prevResult = matchedResult;
137
+ continue;
138
+ }
139
+ ptLog('%s: %s', resultType, collection);
140
+ if (result.type === 'MISSING_NODE_REQUIRED' ||
141
+ result.type === 'MISSING_NODE_ONE_OR_MORE' ||
142
+ result.type === 'TRANSPARENT_MODEL_DISALLOWS') {
143
+ return {
144
+ type: result.type,
145
+ matched: collection.matched,
146
+ unmatched: collection.unmatched,
147
+ zeroMatch: result.zeroMatch,
148
+ query: result.query,
149
+ hint: result.hint,
150
+ };
151
+ }
152
+ return matchedResult;
153
+ }
154
+ }
155
+ exports.countPattern = countPattern;
@@ -0,0 +1,2 @@
1
+ /// <reference types="debug" />
2
+ export declare const cmLog: import("debug").Debugger;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cmLog = void 0;
4
+ const debug_1 = require("../debug");
5
+ exports.cmLog = debug_1.log.extend('content-model');
@@ -1,6 +1,3 @@
1
- import type { PermittedStructuresSchema } from '@markuplint/ml-spec';
2
- declare type Options = {
3
- ignoreHasMutableChildren: boolean;
4
- };
5
- declare const _default: import("@markuplint/ml-core").RuleSeed<PermittedStructuresSchema[], Options>;
1
+ import type { Options, TagRule } from './types';
2
+ declare const _default: import("@markuplint/ml-core").RuleSeed<TagRule[], Options>;
6
3
  export default _default;