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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +1 -1
  2. package/lib/attr-check.d.ts +20 -8
  3. package/lib/attr-check.js +31 -22
  4. package/lib/attr-duplication/index.d.ts +3 -1
  5. package/lib/attr-duplication/index.js +2 -1
  6. package/lib/attr-value-quotes/index.d.ts +2 -2
  7. package/lib/case-sensitive-attr-name/index.d.ts +1 -1
  8. package/lib/case-sensitive-tag-name/index.d.ts +1 -1
  9. package/lib/character-reference/index.d.ts +1 -1
  10. package/lib/class-naming/index.d.ts +1 -1
  11. package/lib/class-naming/index.js +2 -4
  12. package/lib/create-message.d.ts +13 -2
  13. package/lib/create-message.js +4 -3
  14. package/lib/debug.js +1 -1
  15. package/lib/deprecated-attr/index.d.ts +3 -1
  16. package/lib/deprecated-element/index.d.ts +3 -1
  17. package/lib/deprecated-element/index.js +2 -2
  18. package/lib/disallowed-element/index.d.ts +1 -1
  19. package/lib/doctype/index.d.ts +2 -2
  20. package/lib/end-tag/index.d.ts +1 -1
  21. package/lib/helpers.d.ts +37 -22
  22. package/lib/helpers.js +27 -14
  23. package/lib/id-duplication/index.d.ts +3 -1
  24. package/lib/index.d.ts +243 -3
  25. package/lib/index.js +6 -1
  26. package/lib/ineffective-attr/index.d.ts +3 -1
  27. package/lib/ineffective-attr/index.js +2 -5
  28. package/lib/invalid-attr/index.d.ts +39 -12
  29. package/lib/invalid-attr/index.js +153 -27
  30. package/lib/label-has-control/index.d.ts +3 -1
  31. package/lib/landmark-roles/index.d.ts +3 -3
  32. package/lib/landmark-roles/index.js +9 -5
  33. package/lib/no-boolean-attr-value/index.d.ts +3 -1
  34. package/lib/no-default-value/index.d.ts +3 -1
  35. package/lib/no-empty-palpable-content/index.d.ts +3 -3
  36. package/lib/no-empty-palpable-content/index.js +11 -3
  37. package/lib/no-hard-code-id/index.d.ts +3 -1
  38. package/lib/no-refer-to-non-existent-id/index.d.ts +9 -4
  39. package/lib/no-refer-to-non-existent-id/index.js +65 -5
  40. package/lib/no-use-event-handler-attr/index.d.ts +2 -2
  41. package/lib/no-use-event-handler-attr/index.js +4 -4
  42. package/lib/permitted-contents/choice.d.ts +8 -1
  43. package/lib/permitted-contents/choice.js +37 -2
  44. package/lib/permitted-contents/complex-branch.d.ts +8 -1
  45. package/lib/permitted-contents/complex-branch.js +4 -2
  46. package/lib/permitted-contents/content-model.d.ts +1 -1
  47. package/lib/permitted-contents/content-model.js +7 -3
  48. package/lib/permitted-contents/count-pattern.d.ts +18 -2
  49. package/lib/permitted-contents/count-pattern.js +71 -64
  50. package/lib/permitted-contents/debug.browser.d.ts +30 -0
  51. package/lib/permitted-contents/debug.browser.js +14 -0
  52. package/lib/permitted-contents/debug.d.ts +2 -1
  53. package/lib/permitted-contents/debug.js +9 -1
  54. package/lib/permitted-contents/index.d.ts +1 -1
  55. package/lib/permitted-contents/index.js +12 -15
  56. package/lib/permitted-contents/matches-selector.d.ts +7 -2
  57. package/lib/permitted-contents/matches-selector.js +8 -6
  58. package/lib/permitted-contents/order.d.ts +8 -1
  59. package/lib/permitted-contents/order.js +25 -15
  60. package/lib/permitted-contents/recursive-branch.d.ts +8 -1
  61. package/lib/permitted-contents/recursive-branch.js +5 -3
  62. package/lib/permitted-contents/represent-transparent-nodes.d.ts +7 -3
  63. package/lib/permitted-contents/represent-transparent-nodes.js +4 -5
  64. package/lib/permitted-contents/start.d.ts +7 -1
  65. package/lib/permitted-contents/start.js +5 -3
  66. package/lib/permitted-contents/transparent.d.ts +2 -2
  67. package/lib/permitted-contents/transparent.js +11 -14
  68. package/lib/permitted-contents/types.d.ts +35 -28
  69. package/lib/permitted-contents/utils.d.ts +96 -28
  70. package/lib/permitted-contents/utils.js +135 -17
  71. package/lib/placeholder-label-option/index.d.ts +2 -0
  72. package/lib/placeholder-label-option/index.js +88 -0
  73. package/lib/require-accessible-name/index.d.ts +2 -2
  74. package/lib/require-accessible-name/index.js +5 -5
  75. package/lib/require-datetime/index.d.ts +6 -0
  76. package/lib/require-datetime/index.js +34 -0
  77. package/lib/require-datetime/types.d.ts +10 -0
  78. package/lib/require-datetime/types.js +2 -0
  79. package/lib/require-datetime/utils.d.ts +11 -0
  80. package/lib/require-datetime/utils.js +137 -0
  81. package/lib/required-attr/index.d.ts +3 -3
  82. package/lib/required-attr/index.js +19 -16
  83. package/lib/required-element/index.d.ts +2 -2
  84. package/lib/required-element/index.js +3 -2
  85. package/lib/required-h1/index.d.ts +3 -3
  86. package/lib/required-h1/index.js +4 -3
  87. package/lib/use-list/index.d.ts +3 -3
  88. package/lib/use-list/index.js +7 -5
  89. package/lib/wai-aria/checkings/_.d.ts +15 -0
  90. package/lib/wai-aria/checkings/_.js +27 -0
  91. package/lib/wai-aria/checkings/abstract-role.js +1 -1
  92. package/lib/wai-aria/checkings/default-value.d.ts +7 -3
  93. package/lib/wai-aria/checkings/deprecated-props.d.ts +8 -4
  94. package/lib/wai-aria/checkings/disallowed-prop.d.ts +8 -4
  95. package/lib/wai-aria/checkings/disallowed-prop.js +27 -3
  96. package/lib/wai-aria/checkings/implicit-props.d.ts +8 -4
  97. package/lib/wai-aria/checkings/implicit-props.js +3 -2
  98. package/lib/wai-aria/checkings/implicit-role.js +1 -1
  99. package/lib/wai-aria/checkings/interaction-in-hidden.js +3 -1
  100. package/lib/wai-aria/checkings/no-global-prop.d.ts +7 -3
  101. package/lib/wai-aria/checkings/non-existent-role.js +1 -1
  102. package/lib/wai-aria/checkings/permitted-roles.js +1 -1
  103. package/lib/wai-aria/checkings/presentational-children.js +4 -2
  104. package/lib/wai-aria/checkings/required-owned-elements.d.ts +7 -3
  105. package/lib/wai-aria/checkings/required-owned-elements.js +28 -12
  106. package/lib/wai-aria/checkings/required-prop copy.d.ts +15 -0
  107. package/lib/wai-aria/checkings/required-prop copy.js +27 -0
  108. package/lib/wai-aria/checkings/required-prop.d.ts +12 -6
  109. package/lib/wai-aria/checkings/unadopted-explicit-roles.d.ts +15 -0
  110. package/lib/wai-aria/checkings/unadopted-explicit-roles.js +17 -0
  111. package/lib/wai-aria/checkings/value.d.ts +15 -6
  112. package/lib/wai-aria/checkings/value.js +3 -1
  113. package/lib/wai-aria/index.d.ts +1 -1
  114. package/lib/wai-aria/index.js +13 -12
  115. package/lib/wai-aria/types.d.ts +10 -10
  116. package/lib/xxx/index.d.ts +2 -0
  117. package/lib/xxx/index.js +32 -0
  118. package/package.json +16 -11
  119. package/schema.json +6 -0
  120. package/test/attr-check.spec.js +77 -0
  121. package/test/attr-duplication/index.spec.js +159 -0
  122. package/test/attr-value-quotes/index.spec.js +133 -0
  123. package/test/case-sensitive-attr-name/index.spec.js +65 -0
  124. package/test/case-sensitive-tag-name/index.spec.js +80 -0
  125. package/test/character-reference/index.spec.js +57 -0
  126. package/test/class-naming/index.spec.js +470 -0
  127. package/test/create-message.spec.js +497 -0
  128. package/test/deprecated-attr/index.spec.js +48 -0
  129. package/test/deprecated-element/index.spec.js +48 -0
  130. package/test/disallowed-element/index.spec.js +90 -0
  131. package/test/doctype/index.spec.js +50 -0
  132. package/test/end-tag/index.spec.js +162 -0
  133. package/test/id-duplication/index.spec.js +47 -0
  134. package/test/ineffective-attr/index.spec.js +31 -0
  135. package/test/invalid-attr/index.spec.js +1632 -0
  136. package/test/label-has-control/index.spec.js +29 -0
  137. package/test/landmark-roles/index.spec.js +187 -0
  138. package/test/no-boolean-attr-value/index.spec.js +41 -0
  139. package/test/no-default-value/index.spec.js +74 -0
  140. package/test/no-empty-palpable-content/index.spec.js +115 -0
  141. package/test/no-hard-code-id/index.spec.js +100 -0
  142. package/test/no-refer-to-non-existent-id/index.spec.js +254 -0
  143. package/test/no-use-event-handler-attr/index.spec.js +57 -0
  144. package/test/permitted-contents/choice.spec.js +174 -0
  145. package/test/permitted-contents/count-pattern.spec.js +308 -0
  146. package/test/permitted-contents/index.spec.js +1371 -0
  147. package/test/permitted-contents/matches-selector.spec.js +59 -0
  148. package/test/permitted-contents/order.spec.js +351 -0
  149. package/test/permitted-contents/recursive-branch.spec.js +41 -0
  150. package/test/permitted-contents/represent-transparent-nodes.spec.js +24 -0
  151. package/test/permitted-contents/start.spec.js +67 -0
  152. package/test/placeholder-label-option/index.spec.js +113 -0
  153. package/test/require-accessible-name/index.spec.js +446 -0
  154. package/test/require-datetime/index.spec.js +54 -0
  155. package/test/require-datetime/utils.spec.js +52 -0
  156. package/test/required-attr/index.spec.js +414 -0
  157. package/test/required-element/index.spec.js +188 -0
  158. package/test/required-h1/index.spec.js +69 -0
  159. package/test/use-list/index.spec.js +109 -0
  160. package/test/wai-aria/checkings/value.spec.js +33 -0
  161. package/test/wai-aria/index.spec.js +1173 -0
  162. package/tsconfig.test.json +0 -3
  163. package/tsconfig.tsbuildinfo +0 -1
@@ -1,3 +1,3 @@
1
1
  import type { Options, TagRule } from './types';
2
- declare const _default: import("@markuplint/ml-core").RuleSeed<TagRule[], Options>;
2
+ declare const _default: Readonly<import('@markuplint/ml-core').RuleSeed<TagRule[], Options>>;
3
3
  export default _default;
@@ -11,22 +11,17 @@ exports.default = (0, ml_core_1.createRule)({
11
11
  async verify({ document, report, t }) {
12
12
  await document.walkOn('Element', el => {
13
13
  var _a, _b, _c;
14
- if (!el.rule.value) {
14
+ if (el.rule.options.ignoreHasMutableChildren && el.hasMutableChildren()) {
15
15
  return;
16
16
  }
17
- if (el.rule.option.ignoreHasMutableChildren && el.hasMutableChildren()) {
18
- return;
19
- }
20
- const results = (0, content_model_1.contentModel)(el, el.rule.value, el.rule.option);
17
+ const results = (0, content_model_1.contentModel)(el, el.rule.value, el.rule.options);
21
18
  for (const { type, scope, query, hint } of results) {
22
19
  let message = '';
23
- if (hint) {
24
- if (hint.max != null) {
25
- message =
26
- t('there is more content than it needs') +
27
- t('. ') +
28
- t('the max number of elements required is {0}', `${hint.max}`);
29
- }
20
+ if (hint.max != null) {
21
+ message =
22
+ t('there is more content than it needs') +
23
+ t('. ') +
24
+ t('the max number of elements required is {0}', `${hint.max}`);
30
25
  }
31
26
  switch (type) {
32
27
  case 'MATCHED':
@@ -75,10 +70,10 @@ exports.default = (0, ml_core_1.createRule)({
75
70
  });
76
71
  break;
77
72
  }
78
- case 'VOID_ELEMENT': {
73
+ case 'NOTHING': {
79
74
  report({
80
75
  scope: el,
81
- message: t('{0} is {1}', t('the {0}', 'element'), t('a {0}', 'void element')),
76
+ message: t('{0} disallows {1}', t('the {0}', 'element'), 'contents'),
82
77
  });
83
78
  break;
84
79
  }
@@ -91,7 +86,9 @@ exports.default = (0, ml_core_1.createRule)({
91
86
  });
92
87
  },
93
88
  });
94
- function name(scope, t) {
89
+ function name(
90
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
91
+ scope, t) {
95
92
  if (scope.is(scope.ELEMENT_NODE)) {
96
93
  return t('the "{0}" {1}', scope.localName, 'element');
97
94
  }
@@ -1,3 +1,8 @@
1
- import type { ChildNode, Options, Result, Specs } from './types';
1
+ import type { ChildNode, Result, Specs } from './types';
2
2
  export type SelectorResult = Result<'UNMATCHED_SELECTOR_BUT_MAY_EMPTY' | 'MISSING_NODE' | 'UNMATCHED_SELECTORS'>;
3
- export declare function matchesSelector(query: string, node: ChildNode | undefined, specs: Specs, options: Options, depth: number): SelectorResult;
3
+ export declare function matchesSelector(
4
+ query: string,
5
+ node: ChildNode | undefined,
6
+ specs: Specs,
7
+ depth: number,
8
+ ): SelectorResult;
@@ -4,7 +4,9 @@ exports.matchesSelector = void 0;
4
4
  const ml_spec_1 = require("@markuplint/ml-spec");
5
5
  const debug_1 = require("./debug");
6
6
  const utils_1 = require("./utils");
7
- function matchesSelector(query, node, specs, options, depth) {
7
+ function matchesSelector(query,
8
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
9
+ node, specs, depth) {
8
10
  const nodeLog = debug_1.cmLog.extend(`node#${depth}`);
9
11
  const { selector, hasText, hasCustom } = optCondition(query, specs);
10
12
  if (node == null) {
@@ -12,7 +14,7 @@ function matchesSelector(query, node, specs, options, depth) {
12
14
  nodeLog('<#text>.matches(%s) => ""', query);
13
15
  return {
14
16
  type: 'MATCHED_ZERO',
15
- matched: node ? [node] : [],
17
+ matched: [],
16
18
  unmatched: [],
17
19
  zeroMatch: true,
18
20
  query,
@@ -103,9 +105,9 @@ function matchesSelector(query, node, specs, options, depth) {
103
105
  unmatched: [node],
104
106
  zeroMatch: true,
105
107
  query,
106
- hint: {
108
+ hint: (0, utils_1.cleanObject)({
107
109
  not: result.not,
108
- },
110
+ }),
109
111
  };
110
112
  }
111
113
  return {
@@ -114,9 +116,9 @@ function matchesSelector(query, node, specs, options, depth) {
114
116
  unmatched: [node],
115
117
  zeroMatch: false,
116
118
  query,
117
- hint: {
119
+ hint: (0, utils_1.cleanObject)({
118
120
  not: result.not,
119
- },
121
+ }),
120
122
  };
121
123
  }
122
124
  return {
@@ -1,5 +1,6 @@
1
1
  import type { ChildNode, Options, Result, Specs } from './types';
2
2
  import type { PermittedContentPattern } from '@markuplint/ml-spec';
3
+ import type { ReadonlyDeep } from 'type-fest';
3
4
  /**
4
5
  * Check ordered array
5
6
  *
@@ -10,4 +11,10 @@ import type { PermittedContentPattern } from '@markuplint/ml-spec';
10
11
  * @param depth
11
12
  * @returns
12
13
  */
13
- export declare function order(contents: ReadonlyArray<PermittedContentPattern>, nodes: ReadonlyArray<ChildNode>, specs: Specs, options: Options, depth: number): Result;
14
+ export declare function order(
15
+ contents: ReadonlyDeep<PermittedContentPattern[]>,
16
+ nodes: readonly ChildNode[],
17
+ specs: Specs,
18
+ options: Options,
19
+ depth: number,
20
+ ): Result;
@@ -15,42 +15,51 @@ const utils_1 = require("./utils");
15
15
  * @param depth
16
16
  * @returns
17
17
  */
18
- function order(contents, nodes, specs, options, depth) {
19
- var _a, _b, _c, _d;
18
+ function order(contents,
19
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
20
+ nodes, specs, options, depth) {
21
+ var _a, _b, _c, _d, _e;
20
22
  const orderLog = debug_1.cmLog.extend(`order#${depth}`);
21
23
  const btLog = debug_1.cmLog.extend(`backtrack#${depth}`);
22
24
  const patterns = (0, helpers_1.deepCopy)(contents);
23
25
  const collection = new utils_1.Collection(nodes);
26
+ orderLog('Model:\n RegEx: %s\n Schema: %o', (0, utils_1.modelLog)(patterns, ''), patterns);
24
27
  orderLog('Starts: %s', collection);
25
28
  let result = undefined;
26
29
  let backtrackMode = false;
27
30
  let afterBacktrack = false;
28
31
  const unmatchedResults = [];
29
- while (patterns.length) {
32
+ while (patterns.length > 0 && patterns[0]) {
30
33
  result = (0, complex_branch_1.complexBranch)(patterns[0], collection.unmatched, specs, options, depth);
31
34
  collection.addMatched(result.matched);
32
- orderLog('stack: %s', collection);
33
35
  if (result.type !== 'UNEXPECTED_EXTRA_NODE' && result.type !== 'MATCHED' && result.type !== 'MATCHED_ZERO') {
34
36
  unmatchedResults.push(result);
35
37
  if (backtrackMode) {
36
38
  collection.back();
37
- btLog('🔙');
39
+ btLog('🔙◀BACK');
38
40
  backtrackMode = false;
39
41
  afterBacktrack = true;
40
42
  continue;
41
43
  }
42
- orderLog('conformed (%s): %s', result.type, collection.toString(true));
43
44
  const barelyMatchedResult = unmatchedResults.sort((a, b) => b.matched.length - a.matched.length)[0];
44
45
  if (!barelyMatchedResult) {
45
46
  throw new Error('Unreachable code');
46
47
  }
48
+ orderLog('Result (%s): %s%s', result.type, collection.toString(true), ((_a = barelyMatchedResult.hint.missing) === null || _a === void 0 ? void 0 : _a.barelyMatchedElements) != null
49
+ ? `; But ${barelyMatchedResult.hint.missing.barelyMatchedElements} elements hit out of pattern`
50
+ : '');
47
51
  return {
48
52
  type: barelyMatchedResult.type,
49
53
  matched: collection.matched,
50
54
  unmatched: collection.unmatched,
51
55
  zeroMatch: barelyMatchedResult.zeroMatch,
52
56
  query: barelyMatchedResult.query,
53
- hint: barelyMatchedResult.hint,
57
+ hint: (0, utils_1.mergeHints)(barelyMatchedResult.hint, {
58
+ missing: {
59
+ barelyMatchedElements: collection.matched.length,
60
+ need: barelyMatchedResult.query,
61
+ },
62
+ }),
54
63
  };
55
64
  }
56
65
  if (afterBacktrack) {
@@ -65,25 +74,26 @@ function order(contents, nodes, specs, options, depth) {
65
74
  }
66
75
  patterns.shift();
67
76
  }
68
- if (collection.unmatched.length) {
69
- orderLog('Conformed (UNEXPECTED_EXTRA_NODE): %s', collection.toString(true));
77
+ if (collection.unmatched.length > 0) {
78
+ orderLog('Result (UNEXPECTED_EXTRA_NODE): %s', collection.toString(true));
70
79
  return {
71
80
  type: 'UNEXPECTED_EXTRA_NODE',
72
81
  matched: collection.matched,
73
82
  unmatched: collection.unmatched,
74
83
  zeroMatch: false,
75
- query: (_a = result === null || result === void 0 ? void 0 : result.query) !== null && _a !== void 0 ? _a : 'N/A',
76
- hint: (_b = result === null || result === void 0 ? void 0 : result.hint) !== null && _b !== void 0 ? _b : {},
84
+ query: (_b = result === null || result === void 0 ? void 0 : result.query) !== null && _b !== void 0 ? _b : 'N/A',
85
+ hint: (_c = result === null || result === void 0 ? void 0 : result.hint) !== null && _c !== void 0 ? _c : {},
77
86
  };
78
87
  }
79
- orderLog('Conformed: %s', collection);
88
+ const resultType = collection.matched.length > 0 ? 'MATCHED' : 'MATCHED_ZERO';
89
+ orderLog('Result (%s): %s', resultType, collection.toString(true));
80
90
  return {
81
- type: collection.matched.length ? 'MATCHED' : 'MATCHED_ZERO',
91
+ type: resultType,
82
92
  matched: collection.matched,
83
93
  unmatched: collection.unmatched,
84
94
  zeroMatch: false,
85
- query: (_c = result === null || result === void 0 ? void 0 : result.query) !== null && _c !== void 0 ? _c : 'N/A',
86
- hint: (_d = result === null || result === void 0 ? void 0 : result.hint) !== null && _d !== void 0 ? _d : {},
95
+ query: (_d = result === null || result === void 0 ? void 0 : result.query) !== null && _d !== void 0 ? _d : 'N/A',
96
+ hint: (_e = result === null || result === void 0 ? void 0 : result.hint) !== null && _e !== void 0 ? _e : {},
87
97
  };
88
98
  }
89
99
  exports.order = order;
@@ -1,4 +1,11 @@
1
1
  import type { SelectorResult } from './matches-selector';
2
2
  import type { ChildNode, Options, Specs } from './types';
3
3
  import type { PermittedContentPattern, Model } from '@markuplint/ml-spec';
4
- export declare function recursiveBranch(model: Model | PermittedContentPattern[], nodes: readonly ChildNode[], specs: Specs, options: Options, depth: number): SelectorResult;
4
+ import type { ReadonlyDeep } from 'type-fest';
5
+ export declare function recursiveBranch(
6
+ model: ReadonlyDeep<Model | PermittedContentPattern[]>,
7
+ nodes: readonly ChildNode[],
8
+ specs: Specs,
9
+ options: Options,
10
+ depth: number,
11
+ ): SelectorResult;
@@ -4,17 +4,19 @@ exports.recursiveBranch = void 0;
4
4
  const matches_selector_1 = require("./matches-selector");
5
5
  const order_1 = require("./order");
6
6
  const utils_1 = require("./utils");
7
- function recursiveBranch(model, nodes, specs, options, depth) {
7
+ function recursiveBranch(model,
8
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
9
+ nodes, specs, options, depth) {
8
10
  if (!(0, utils_1.isModel)(model)) {
9
11
  return (0, order_1.order)(model, nodes, specs, options, depth + 1);
10
12
  }
11
13
  if (typeof model === 'string') {
12
- return (0, matches_selector_1.matchesSelector)(model, nodes[0], specs, options, depth);
14
+ return (0, matches_selector_1.matchesSelector)(model, nodes[0], specs, depth);
13
15
  }
14
16
  const collection = new utils_1.Collection(nodes);
15
17
  let lastUnmatched = null;
16
18
  for (const query of model) {
17
- const result = (0, matches_selector_1.matchesSelector)(query, collection.unmatched[0], specs, options, depth);
19
+ const result = (0, matches_selector_1.matchesSelector)(query, collection.unmatched[0], specs, depth);
18
20
  collection.addMatched(result.matched);
19
21
  if (result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
20
22
  return {
@@ -1,6 +1,10 @@
1
1
  import type { ChildNode, Options, Result, Specs } from './types';
2
2
  export declare const transparentMode: Map<ChildNode, true>;
3
- export declare function representTransparentNodes(nodes: ChildNode[], specs: Specs, options: Options): {
4
- nodes: ChildNode[];
5
- errors: Result[];
3
+ export declare function representTransparentNodes(
4
+ nodes: ChildNode[],
5
+ specs: Specs,
6
+ options: Options,
7
+ ): {
8
+ nodes: ChildNode[];
9
+ errors: Result[];
6
10
  };
@@ -5,7 +5,9 @@ const ml_spec_1 = require("@markuplint/ml-spec");
5
5
  const order_1 = require("./order");
6
6
  const utils_1 = require("./utils");
7
7
  exports.transparentMode = new Map();
8
- function representTransparentNodes(nodes, specs, options) {
8
+ function representTransparentNodes(
9
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
10
+ nodes, specs, options) {
9
11
  var _a;
10
12
  const result = [];
11
13
  const errors = [];
@@ -13,9 +15,6 @@ function representTransparentNodes(nodes, specs, options) {
13
15
  if (parent) {
14
16
  const { errors: parentErrors } = representTransparentNodes([parent], specs, options);
15
17
  errors.push(...parentErrors);
16
- // if (!Array.isArray(parentRes)) {
17
- // return parentRes;
18
- // }
19
18
  }
20
19
  for (const node of nodes) {
21
20
  if (!node.is(node.ELEMENT_NODE)) {
@@ -34,7 +33,7 @@ function representTransparentNodes(nodes, specs, options) {
34
33
  }
35
34
  const collection = new utils_1.Collection((0, utils_1.getChildNodesWithoutWhitespaces)(node));
36
35
  let unmatched;
37
- if (noTransparentModels.length) {
36
+ if (noTransparentModels.length > 0) {
38
37
  const result = (0, order_1.order)(noTransparentModels, collection.unmatched, specs, options, Infinity);
39
38
  unmatched = result.unmatched;
40
39
  }
@@ -1,5 +1,6 @@
1
1
  import type { ContentModelResult, Element, Options, Specs } from './types';
2
2
  import type { ContentModel } from '@markuplint/ml-spec';
3
+ import type { ReadonlyDeep } from 'type-fest';
3
4
  /**
4
5
  * Check start
5
6
  *
@@ -9,4 +10,9 @@ import type { ContentModel } from '@markuplint/ml-spec';
9
10
  * @param options
10
11
  * @returns
11
12
  */
12
- export declare function start(contents: ContentModel['contents'], el: Element, specs: Specs, options: Options): ContentModelResult[];
13
+ export declare function start(
14
+ contents: ReadonlyDeep<ContentModel['contents']>,
15
+ el: Element,
16
+ specs: Specs,
17
+ options: Options,
18
+ ): ContentModelResult[];
@@ -13,13 +13,15 @@ const utils_1 = require("./utils");
13
13
  * @param options
14
14
  * @returns
15
15
  */
16
- function start(contents, el, specs, options) {
16
+ function start(contents,
17
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
18
+ el, specs, options) {
17
19
  var _a;
18
20
  if (contents === false) {
19
- if (el.childNodes.length) {
21
+ if (el.childNodes.length > 0) {
20
22
  return [
21
23
  {
22
- type: 'VOID_ELEMENT',
24
+ type: 'NOTHING',
23
25
  scope: el,
24
26
  query: ':not(*)',
25
27
  hint: {},
@@ -1,2 +1,2 @@
1
- import type { ChildNode, Options, Result, Specs } from './types';
2
- export declare function transparent(nodes: ChildNode[], specs: Specs, options: Options, depth: number): Result;
1
+ import type { ChildNode, Result } from './types';
2
+ export declare function transparent(nodes: readonly ChildNode[]): Result;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transparent = void 0;
4
- const count_pattern_1 = require("./count-pattern");
5
4
  const debug_1 = require("./debug");
6
- const utils_1 = require("./utils");
7
5
  const transparentLog = debug_1.cmLog.extend('transparent');
8
- function transparent(nodes, specs, options, depth) {
9
- var _a;
10
- if (nodes.length === 0 || ((_a = nodes[0].parentElement) === null || _a === void 0 ? void 0 : _a.parentElement)) {
6
+ function transparent(
7
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
8
+ nodes) {
9
+ var _a, _b;
10
+ if (nodes.length === 0 || ((_b = (_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.parentElement)) {
11
11
  transparentLog('Skipped');
12
12
  return {
13
13
  type: nodes.length === 0 ? 'MATCHED_ZERO' : 'MATCHED',
@@ -19,16 +19,13 @@ function transparent(nodes, specs, options, depth) {
19
19
  };
20
20
  }
21
21
  transparentLog('Transparent model element is component root');
22
- const collection = new utils_1.Collection(nodes);
23
- const result = (0, count_pattern_1.countPattern)({ zeroOrMore: ':model(flow)' }, collection.unmatched, specs, options, depth);
24
- collection.addMatched(result.matched);
25
22
  return {
26
- type: result.type,
27
- matched: collection.matched,
28
- unmatched: collection.unmatched,
29
- zeroMatch: result.zeroMatch,
30
- query: result.query,
31
- hint: result.hint,
23
+ type: 'MATCHED',
24
+ matched: nodes.slice(),
25
+ unmatched: [],
26
+ zeroMatch: false,
27
+ query: 'transparent',
28
+ hint: {},
32
29
  };
33
30
  }
34
31
  exports.transparent = transparent;
@@ -1,45 +1,52 @@
1
1
  import type { Element as _Element, ChildNode as _ChildNode } from '@markuplint/ml-core';
2
2
  import type { ContentModel, MLMLSpec } from '@markuplint/ml-spec';
3
+ import type { ReadonlyDeep } from 'type-fest';
3
4
  export type Element = _Element<TagRule[], Options>;
4
5
  export type ChildNode = _ChildNode<TagRule[], Options>;
5
6
  export type Specs = {
6
- cites: MLMLSpec['cites'];
7
- def: MLMLSpec['def'];
8
- specs: {
9
- name: string;
10
- contentModel: {
11
- contents: MLMLSpec['specs'][0]['contentModel']['contents'];
12
- };
13
- }[];
7
+ readonly cites: MLMLSpec['cites'];
8
+ readonly def: MLMLSpec['def'];
9
+ readonly specs: readonly {
10
+ readonly name: string;
11
+ readonly contentModel: {
12
+ readonly contents: MLMLSpec['specs'][0]['contentModel']['contents'];
13
+ };
14
+ }[];
14
15
  };
15
16
  export type ContentModelResult = {
16
- type: MatchedReason | UnmatchedReason;
17
- scope: ChildNode;
18
- query: Result['query'];
19
- hint: Result['hint'];
17
+ type: MatchedReason | UnmatchedReason;
18
+ scope: ChildNode;
19
+ query: Result['query'];
20
+ hint: Result['hint'];
20
21
  };
21
22
  export type Result<T extends string = MatchedReason> = {
22
- type: MatchedReason | UnmatchedReason | T;
23
- matched: ChildNode[];
24
- unmatched: ChildNode[];
25
- zeroMatch: boolean;
26
- query: string;
27
- hint: {
28
- max?: number;
29
- not?: ChildNode;
30
- transparent?: Element;
31
- };
23
+ type: MatchedReason | UnmatchedReason | T;
24
+ matched: ChildNode[];
25
+ unmatched: ChildNode[];
26
+ zeroMatch: boolean;
27
+ query: string;
28
+ hint: Hints;
29
+ };
30
+ export type Hints = {
31
+ max?: number;
32
+ not?: ChildNode;
33
+ transparent?: Element;
34
+ missing?: {
35
+ barelyMatchedElements?: number;
36
+ need?: string;
37
+ };
32
38
  };
33
39
  export type MatchedReason = 'MATCHED' | 'MATCHED_ZERO';
34
- export type UnmatchedReason = 'VOID_ELEMENT' | 'UNEXPECTED_EXTRA_NODE' | 'TRANSPARENT_MODEL_DISALLOWS' | MissingNodeReason;
40
+ export type UnmatchedReason = 'NOTHING' | 'UNEXPECTED_EXTRA_NODE' | 'TRANSPARENT_MODEL_DISALLOWS' | MissingNodeReason;
35
41
  export type MissingNodeReason = 'MISSING_NODE_REQUIRED' | 'MISSING_NODE_ONE_OR_MORE';
42
+ export type RepeatSign = '' | '?' | '+' | '*' | `{${number},${number}}`;
36
43
  export type TransparentModel = {
37
- el: Element;
38
- additionalCondition: string;
44
+ el: Element;
45
+ additionalCondition: string;
39
46
  };
40
47
  export type TagRule = {
41
- tag: string;
42
- } & ContentModel;
48
+ readonly tag: string;
49
+ } & ReadonlyDeep<ContentModel>;
43
50
  export type Options = {
44
- ignoreHasMutableChildren: boolean;
51
+ readonly ignoreHasMutableChildren: boolean;
45
52
  };
@@ -1,32 +1,100 @@
1
- import type { ChildNode, Element, Specs } from './types';
2
- import type { PermittedContentPattern, PermittedContentChoice, PermittedContentOneOrMore, PermittedContentOptional, PermittedContentRequire, PermittedContentTransparent, PermittedContentZeroOrMore, Model } from '@markuplint/ml-spec';
1
+ import type { ChildNode, Element, Hints, MissingNodeReason, RepeatSign, Specs } from './types';
2
+ import type {
3
+ PermittedContentPattern,
4
+ PermittedContentChoice,
5
+ PermittedContentOneOrMore,
6
+ PermittedContentOptional,
7
+ PermittedContentRequire,
8
+ PermittedContentTransparent,
9
+ PermittedContentZeroOrMore,
10
+ Model,
11
+ } from '@markuplint/ml-spec';
12
+ import type { ReadonlyDeep } from 'type-fest';
3
13
  export declare function getChildNodesWithoutWhitespaces(el: Element): ChildNode[];
4
- export declare function isModel(model: Model | PermittedContentPattern[]): model is Model;
5
- export declare function matches(selector: string, node: ChildNode, specs: Specs): {
6
- matched: boolean;
7
- not?: undefined;
8
- } | {
9
- matched: boolean;
10
- not: ChildNode | undefined;
14
+ export declare function isModel(model: ReadonlyDeep<Model | PermittedContentPattern[]>): model is ReadonlyDeep<Model>;
15
+ export declare function matches(
16
+ selector: string,
17
+ node: ChildNode,
18
+ specs: Specs,
19
+ ):
20
+ | {
21
+ matched: boolean;
22
+ not?: undefined;
23
+ }
24
+ | {
25
+ matched: boolean;
26
+ not: ChildNode | undefined;
27
+ };
28
+ export declare function isRequire(
29
+ content: ReadonlyDeep<PermittedContentPattern>,
30
+ ): content is ReadonlyDeep<PermittedContentRequire>;
31
+ export declare function isOptional(
32
+ content: ReadonlyDeep<PermittedContentPattern>,
33
+ ): content is ReadonlyDeep<PermittedContentOptional>;
34
+ export declare function isOneOrMore(
35
+ content: ReadonlyDeep<PermittedContentPattern>,
36
+ ): content is ReadonlyDeep<PermittedContentOneOrMore>;
37
+ export declare function isZeroOrMore(
38
+ content: ReadonlyDeep<PermittedContentPattern>,
39
+ ): content is ReadonlyDeep<PermittedContentZeroOrMore>;
40
+ export declare function isChoice(
41
+ content: ReadonlyDeep<PermittedContentPattern>,
42
+ ): content is ReadonlyDeep<PermittedContentChoice>;
43
+ export declare function isTransparent(
44
+ content: ReadonlyDeep<PermittedContentPattern>,
45
+ ): content is ReadonlyDeep<PermittedContentTransparent>;
46
+ export declare function normalizeModel(
47
+ pattern:
48
+ | ReadonlyDeep<PermittedContentRequire>
49
+ | ReadonlyDeep<PermittedContentOptional>
50
+ | ReadonlyDeep<PermittedContentOneOrMore>
51
+ | ReadonlyDeep<PermittedContentZeroOrMore>,
52
+ ): {
53
+ model: ReadonlyDeep<PermittedContentPattern[] | Model>;
54
+ min: number;
55
+ max: number;
56
+ repeat: RepeatSign;
57
+ missingType: MissingNodeReason | undefined;
11
58
  };
12
- export declare function isRequire(content: PermittedContentPattern): content is PermittedContentRequire;
13
- export declare function isOptional(content: PermittedContentPattern): content is PermittedContentOptional;
14
- export declare function isOneOrMore(content: PermittedContentPattern): content is PermittedContentOneOrMore;
15
- export declare function isZeroOrMore(content: PermittedContentPattern): content is PermittedContentZeroOrMore;
16
- export declare function isChoice(content: PermittedContentPattern): content is PermittedContentChoice;
17
- export declare function isTransparent(content: PermittedContentPattern): content is PermittedContentTransparent;
59
+ export declare function mergeHints(
60
+ a: Readonly<Hints>,
61
+ b: Readonly<Hints>,
62
+ ): Partial<{
63
+ missing:
64
+ | Partial<{
65
+ barelyMatchedElements?: number | undefined;
66
+ need?: string | undefined;
67
+ }>
68
+ | undefined;
69
+ max?: number | undefined;
70
+ not?:
71
+ | import('packages/@markuplint/ml-core/lib').DocumentType<
72
+ import('./types').TagRule[],
73
+ import('./types').Options
74
+ >
75
+ | import('packages/@markuplint/ml-core/lib/ml-dom/node/character-data').MLCharacterData<
76
+ import('./types').TagRule[],
77
+ import('./types').Options,
78
+ import('packages/@markuplint/ml-ast/lib').MLASTAbstractNode
79
+ >
80
+ | import('packages/@markuplint/ml-core/lib').Element<import('./types').TagRule[], import('./types').Options>
81
+ | import('packages/@markuplint/ml-core/lib').Block<import('./types').TagRule[], import('./types').Options>
82
+ | undefined;
83
+ transparent?: Element | undefined;
84
+ }>;
85
+ export declare function cleanObject<T extends Object>(object: T): Partial<T>;
18
86
  export declare class Collection {
19
- #private;
20
- constructor(origin: readonly ChildNode[]);
21
- get matched(): ChildNode[];
22
- get matchedCount(): number;
23
- get nodes(): ChildNode[];
24
- get unmatched(): ChildNode[];
25
- addMatched(nodes: ChildNode[]): boolean;
26
- back(): void;
27
- lock(): void;
28
- max(max: number): void;
29
- toString(highlightExtraNodes?: boolean): string;
30
- }
31
- export declare class UnsupportedError extends Error {
87
+ #private;
88
+ constructor(origin: readonly ChildNode[]);
89
+ get matched(): ChildNode[];
90
+ get matchedCount(): number;
91
+ get nodes(): ChildNode[];
92
+ get unmatched(): ChildNode[];
93
+ addMatched(nodes: ChildNode[]): boolean;
94
+ back(): void;
95
+ lock(): void;
96
+ max(max: number): void;
97
+ toString(highlightExtraNodes?: boolean): string;
32
98
  }
99
+ export declare class UnsupportedError extends Error {}
100
+ export declare function modelLog(model: ReadonlyDeep<Model | PermittedContentPattern[]>, repeat: RepeatSign): string;