@markuplint/rules 4.0.0-alpha.1 → 4.0.0-alpha.2

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.
@@ -3,4 +3,4 @@ import type { AttributeType } from '@markuplint/ml-spec';
3
3
  import type { UnmatchedResult } from '@markuplint/types';
4
4
  import type { ReadonlyDeep } from 'type-fest';
5
5
  export declare function createMessageValueExpected(t: Translator, baseTarget: string, type: ReadonlyDeep<AttributeType>, matches: UnmatchedResult): string;
6
- export declare function __createMessageValueExpected(t: Translator, baseTarget: string, expected: string | null, matches: Pick<UnmatchedResult, 'partName' | 'reason' | 'raw' | 'candidate' | 'ref' | 'extra'>): string;
6
+ export declare function __createMessageValueExpected(t: Translator, baseTarget: string, expected: string | null, matches: Pick<UnmatchedResult, 'partName' | 'reason' | 'raw' | 'candidate' | 'ref' | 'extra' | 'fallbackTo'>): string;
@@ -23,6 +23,7 @@ export function __createMessageValueExpected(t, baseTarget, expected, matches) {
23
23
  let expectPart;
24
24
  let unnecessaryPart;
25
25
  let candidatePart;
26
+ let fallbackToPart;
26
27
  let expectOrNeed = 'expects';
27
28
  if (matches.partName) {
28
29
  if (matches.partName === 'the content of the list') {
@@ -187,7 +188,10 @@ export function __createMessageValueExpected(t, baseTarget, expected, matches) {
187
188
  if (matches.candidate) {
188
189
  candidatePart = t('Did you mean "{0*}"?', matches.candidate);
189
190
  }
190
- let message = [reasonPart, unnecessaryPart, expectPart, candidatePart].filter(s => s).join(t('. '));
191
+ if (matches.fallbackTo) {
192
+ fallbackToPart = t('The user agent will automatically use "{0*}" instead', matches.fallbackTo);
193
+ }
194
+ let message = [reasonPart, unnecessaryPart, expectPart, candidatePart, fallbackToPart].filter(s => s).join(t('. '));
191
195
  if (matches.ref) {
192
196
  message += ` (${matches.ref})`;
193
197
  }
@@ -12,23 +12,33 @@ elements, specs, options, depth) {
12
12
  for (const some of pattern.choice) {
13
13
  choiceLog('Patterns[%s]: %s', i, modelLog(some, ''));
14
14
  const result = order(some, collection.unmatched, specs, options, depth + 1);
15
- if (result.type === 'UNEXPECTED_EXTRA_NODE' || result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
15
+ if (result.type === 'MATCHED' ||
16
+ result.type === 'MATCHED_ZERO' ||
17
+ (result.type === 'UNEXPECTED_EXTRA_NODE' && result.matched.length >= 1)) {
16
18
  choiceLog('Results[%s]: %s', i, choiceLogString(pattern.choice, i));
17
- collection.addMatched(result.matched);
18
19
  return {
19
20
  type: result.type,
20
- matched: collection.matched,
21
- unmatched: collection.unmatched,
21
+ matched: result.matched,
22
+ unmatched: result.unmatched,
22
23
  zeroMatch: result.zeroMatch,
23
24
  query: result.query,
24
25
  hint: result.hint,
25
26
  };
26
27
  }
27
28
  unmatchedResults.push(result);
29
+ collection.addMatched(result.matched);
28
30
  indexes.set(result, i);
29
31
  i++;
30
32
  }
31
33
  const barelyMatchedResult = unmatchedResults.sort((a, b) => {
34
+ if (a.type !== b.type) {
35
+ if (a.type === 'UNEXPECTED_EXTRA_NODE') {
36
+ return -1;
37
+ }
38
+ if (b.type === 'UNEXPECTED_EXTRA_NODE') {
39
+ return 1;
40
+ }
41
+ }
32
42
  const computed1 = b.matched.length - a.matched.length;
33
43
  if (computed1 !== 0) {
34
44
  return computed1;
@@ -1,6 +1,7 @@
1
1
  import { cmLog } from './debug.js';
2
2
  import { recursiveBranch } from './recursive-branch.js';
3
3
  import { Collection, mergeHints, modelLog, normalizeModel } from './utils.js';
4
+ const cLog = cmLog.extend('countCompereResult');
4
5
  /**
5
6
  * Check count
6
7
  *
@@ -139,7 +140,6 @@ elements, specs, options, depth) {
139
140
  return compereResult(matchedResult, barelyResult);
140
141
  }
141
142
  }
142
- const cLog = cmLog.extend('countCompereResult');
143
143
  function compereResult(
144
144
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
145
145
  a,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/rules",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "Built-in rules of markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -25,19 +25,19 @@
25
25
  "./lib/permitted-contents/debug.js": "./lib/permitted-contents/debug.browser.js"
26
26
  },
27
27
  "dependencies": {
28
- "@markuplint/html-spec": "4.0.0-alpha.1",
29
- "@markuplint/ml-core": "4.0.0-alpha.1",
30
- "@markuplint/ml-spec": "4.0.0-alpha.1",
31
- "@markuplint/selector": "4.0.0-alpha.1",
32
- "@markuplint/shared": "4.0.0-alpha.1",
33
- "@markuplint/types": "4.0.0-alpha.1",
34
- "@types/debug": "^4.1.8",
28
+ "@markuplint/html-spec": "4.0.0-alpha.2",
29
+ "@markuplint/ml-core": "4.0.0-alpha.2",
30
+ "@markuplint/ml-spec": "4.0.0-alpha.2",
31
+ "@markuplint/selector": "4.0.0-alpha.2",
32
+ "@markuplint/shared": "4.0.0-alpha.2",
33
+ "@markuplint/types": "4.0.0-alpha.2",
34
+ "@types/debug": "^4.1.9",
35
35
  "@ungap/structured-clone": "^1.2.0",
36
36
  "ansi-colors": "^4.1.3",
37
- "chrono-node": "^2.6.3",
37
+ "chrono-node": "^2.7.0",
38
38
  "debug": "^4.3.4",
39
- "tslib": "^2.6.1",
40
- "type-fest": "^4.1.0"
39
+ "tslib": "^2.6.2",
40
+ "type-fest": "^4.3.1"
41
41
  },
42
- "gitHead": "22502ee22a378ae766033d687dbc0443e5ed35dc"
42
+ "gitHead": "51ad52c760435641f9bff8685707d8178b0787eb"
43
43
  }