@markuplint/rules 3.12.1 → 3.13.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.
@@ -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;
@@ -28,6 +28,7 @@ function __createMessageValueExpected(t, baseTarget, expected, matches) {
28
28
  let expectPart;
29
29
  let unnecessaryPart;
30
30
  let candidatePart;
31
+ let fallbackToPart;
31
32
  let expectOrNeed = 'expects';
32
33
  if (matches.partName) {
33
34
  if (matches.partName === 'the content of the list') {
@@ -192,7 +193,10 @@ function __createMessageValueExpected(t, baseTarget, expected, matches) {
192
193
  if (matches.candidate) {
193
194
  candidatePart = t('Did you mean "{0*}"?', matches.candidate);
194
195
  }
195
- let message = [reasonPart, unnecessaryPart, expectPart, candidatePart].filter(s => s).join(t('. '));
196
+ if (matches.fallbackTo) {
197
+ fallbackToPart = t('The user agent will automatically use "{0*}" instead', matches.fallbackTo);
198
+ }
199
+ let message = [reasonPart, unnecessaryPart, expectPart, candidatePart, fallbackToPart].filter(s => s).join(t('. '));
196
200
  if (matches.ref) {
197
201
  message += ` (${matches.ref})`;
198
202
  }
package/lib/index.d.ts CHANGED
@@ -15,38 +15,38 @@ declare const rules: {
15
15
  readonly 'id-duplication': Readonly<import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, undefined>>;
16
16
  readonly 'ineffective-attr': Readonly<import("@markuplint/ml-core").RuleSeed<import("@markuplint/ml-core").RuleConfigValue, undefined>>;
17
17
  readonly 'invalid-attr': Readonly<import("@markuplint/ml-core").RuleSeed<boolean, {
18
- allowAttrs?: (string | {
18
+ allowAttrs?: Record<string, {
19
+ enum: [string, ...string[]];
20
+ } | {
21
+ pattern: string;
22
+ } | {
23
+ type: import("packages/@markuplint/ml-spec/lib").AttributeType;
24
+ }> | (string | {
19
25
  name: string;
20
- value: ({
26
+ value: import("packages/@markuplint/ml-spec/lib").AttributeType | ({
21
27
  enum: [string, ...string[]];
22
28
  } | {
23
29
  pattern: string;
24
30
  } | {
25
31
  type: import("packages/@markuplint/ml-spec/lib").AttributeType;
26
- }) | import("packages/@markuplint/ml-spec/lib").AttributeType;
27
- })[] | Record<string, {
32
+ });
33
+ })[] | undefined;
34
+ disallowAttrs?: Record<string, {
28
35
  enum: [string, ...string[]];
29
36
  } | {
30
37
  pattern: string;
31
38
  } | {
32
39
  type: import("packages/@markuplint/ml-spec/lib").AttributeType;
33
- }> | undefined;
34
- disallowAttrs?: (string | {
40
+ }> | (string | {
35
41
  name: string;
36
- value: ({
42
+ value: import("packages/@markuplint/ml-spec/lib").AttributeType | ({
37
43
  enum: [string, ...string[]];
38
44
  } | {
39
45
  pattern: string;
40
46
  } | {
41
47
  type: import("packages/@markuplint/ml-spec/lib").AttributeType;
42
- }) | import("packages/@markuplint/ml-spec/lib").AttributeType;
43
- })[] | Record<string, {
44
- enum: [string, ...string[]];
45
- } | {
46
- pattern: string;
47
- } | {
48
- type: import("packages/@markuplint/ml-spec/lib").AttributeType;
49
- }> | undefined;
48
+ });
49
+ })[] | undefined;
50
50
  ignoreAttrNamePrefix?: string | string[] | undefined;
51
51
  allowToAddPropertiesForPretender?: boolean | undefined;
52
52
  attrs?: Record<string, ({
@@ -15,24 +15,34 @@ elements, specs, options, depth) {
15
15
  for (const some of pattern.choice) {
16
16
  choiceLog('Patterns[%s]: %s', i, (0, utils_1.modelLog)(some, ''));
17
17
  const result = (0, order_1.order)(some, collection.unmatched, specs, options, depth + 1);
18
- if (result.type === 'UNEXPECTED_EXTRA_NODE' || result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
18
+ if (result.type === 'MATCHED' ||
19
+ result.type === 'MATCHED_ZERO' ||
20
+ (result.type === 'UNEXPECTED_EXTRA_NODE' && result.matched.length >= 1)) {
19
21
  choiceLog('Results[%s]: %s', i, choiceLogString(pattern.choice, i));
20
- collection.addMatched(result.matched);
21
22
  return {
22
23
  type: result.type,
23
- matched: collection.matched,
24
- unmatched: collection.unmatched,
24
+ matched: result.matched,
25
+ unmatched: result.unmatched,
25
26
  zeroMatch: result.zeroMatch,
26
27
  query: result.query,
27
28
  hint: result.hint,
28
29
  };
29
30
  }
30
31
  unmatchedResults.push(result);
32
+ collection.addMatched(result.matched);
31
33
  indexes.set(result, i);
32
34
  i++;
33
35
  }
34
36
  const barelyMatchedResult = unmatchedResults.sort((a, b) => {
35
37
  var _c, _d, _e, _f;
38
+ if (a.type !== b.type) {
39
+ if (a.type === 'UNEXPECTED_EXTRA_NODE') {
40
+ return -1;
41
+ }
42
+ if (b.type === 'UNEXPECTED_EXTRA_NODE') {
43
+ return 1;
44
+ }
45
+ }
36
46
  const computed1 = b.matched.length - a.matched.length;
37
47
  if (computed1 !== 0) {
38
48
  return computed1;
@@ -4,6 +4,7 @@ exports.countPattern = void 0;
4
4
  const debug_1 = require("./debug");
5
5
  const recursive_branch_1 = require("./recursive-branch");
6
6
  const utils_1 = require("./utils");
7
+ const cLog = debug_1.cmLog.extend('countCompereResult');
7
8
  /**
8
9
  * Check count
9
10
  *
@@ -143,7 +144,6 @@ elements, specs, options, depth) {
143
144
  }
144
145
  }
145
146
  exports.countPattern = countPattern;
146
- const cLog = debug_1.cmLog.extend('countCompereResult');
147
147
  function compereResult(
148
148
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
149
149
  a,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/rules",
3
- "version": "3.12.1",
3
+ "version": "3.13.0",
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>",
@@ -20,12 +20,12 @@
20
20
  "./lib/permitted-contents/debug.js": "./lib/permitted-contents/debug.browser.js"
21
21
  },
22
22
  "dependencies": {
23
- "@markuplint/html-spec": "3.11.1",
24
- "@markuplint/ml-core": "3.12.1",
25
- "@markuplint/ml-spec": "3.11.1",
26
- "@markuplint/selector": "3.11.1",
23
+ "@markuplint/html-spec": "3.12.0",
24
+ "@markuplint/ml-core": "3.13.0",
25
+ "@markuplint/ml-spec": "3.12.0",
26
+ "@markuplint/selector": "3.12.0",
27
27
  "@markuplint/shared": "3.8.0",
28
- "@markuplint/types": "3.9.1",
28
+ "@markuplint/types": "3.10.0",
29
29
  "@types/debug": "^4.1.8",
30
30
  "@ungap/structured-clone": "^1.2.0",
31
31
  "ansi-colors": "^4.1.3",
@@ -34,5 +34,5 @@
34
34
  "tslib": "^2.6.2",
35
35
  "type-fest": "^4.3.1"
36
36
  },
37
- "gitHead": "09100b8baa14dd930602daa458197322197c79c2"
37
+ "gitHead": "ef31aef8f2fff319d0f692feead332ec5fc5c7cf"
38
38
  }
@@ -93,18 +93,8 @@ test('the input element type case-insensitive', async () => {
93
93
  expect(violations2.length).toBe(0);
94
94
  });
95
95
 
96
- test('ancestor condition', async () => {
97
- expect((await mlRuleTest(rule, '<picture><source media="print"></picture>')).violations).toStrictEqual([]);
98
-
99
- expect((await mlRuleTest(rule, '<audio><source media="print"></audio>')).violations).toStrictEqual([
100
- {
101
- severity: 'error',
102
- line: 1,
103
- col: 16,
104
- message: 'The "media" attribute is disallowed',
105
- raw: 'media',
106
- },
107
- ]);
96
+ test.skip('ancestor condition', async () => {
97
+ // TODO: Find instead of test
108
98
  });
109
99
 
110
100
  test('Add allow attr', async () => {
@@ -169,10 +169,10 @@ describe('verify', () => {
169
169
  expect(violations2).toStrictEqual([
170
170
  {
171
171
  severity: 'error',
172
- col: 1,
173
- line: 1,
174
- message: 'Require one or more elements. (Need "dt")',
175
- raw: '<dl>',
172
+ col: 5,
173
+ line: 2,
174
+ message: 'The "dt" element is not allowed in the "dl" element in this context',
175
+ raw: '<dt>',
176
176
  },
177
177
  {
178
178
  severity: 'error',