@markuplint/rules 1.10.4 → 2.0.0-dev.20211115.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 (57) hide show
  1. package/README.md +21 -20
  2. package/lib/attr-check.d.ts +16 -0
  3. package/lib/attr-check.js +498 -0
  4. package/lib/attr-duplication/index.d.ts +1 -1
  5. package/lib/attr-duplication/index.js +5 -8
  6. package/lib/attr-equal-space-after/index.d.ts +1 -1
  7. package/lib/attr-equal-space-after/index.js +8 -11
  8. package/lib/attr-equal-space-before/index.d.ts +1 -1
  9. package/lib/attr-equal-space-before/index.js +8 -11
  10. package/lib/attr-spacing/index.d.ts +3 -3
  11. package/lib/attr-spacing/index.js +19 -21
  12. package/lib/attr-value-quotes/index.d.ts +1 -1
  13. package/lib/attr-value-quotes/index.js +9 -12
  14. package/lib/case-sensitive-attr-name/index.d.ts +1 -1
  15. package/lib/case-sensitive-attr-name/index.js +11 -14
  16. package/lib/case-sensitive-tag-name/index.d.ts +1 -1
  17. package/lib/case-sensitive-tag-name/index.js +8 -11
  18. package/lib/character-reference/index.d.ts +1 -1
  19. package/lib/character-reference/index.js +15 -11
  20. package/lib/class-naming/index.d.ts +1 -1
  21. package/lib/class-naming/index.js +7 -10
  22. package/lib/deprecated-attr/index.d.ts +1 -1
  23. package/lib/deprecated-attr/index.js +6 -9
  24. package/lib/deprecated-element/index.d.ts +1 -1
  25. package/lib/deprecated-element/index.js +10 -15
  26. package/lib/doctype/index.d.ts +1 -1
  27. package/lib/doctype/index.js +16 -25
  28. package/lib/helpers.d.ts +12 -11
  29. package/lib/helpers.js +38 -25
  30. package/lib/id-duplication/index.d.ts +1 -1
  31. package/lib/id-duplication/index.js +5 -8
  32. package/lib/indentation/index.d.ts +3 -3
  33. package/lib/indentation/index.js +81 -116
  34. package/lib/index.d.ts +45 -24
  35. package/lib/index.js +42 -42
  36. package/lib/invalid-attr/index.d.ts +2 -2
  37. package/lib/invalid-attr/index.js +23 -25
  38. package/lib/landmark-roles/index.d.ts +3 -3
  39. package/lib/landmark-roles/index.js +12 -20
  40. package/lib/permitted-contents/index.d.ts +2 -2
  41. package/lib/permitted-contents/index.js +63 -45
  42. package/lib/permitted-contents/permitted-content.spec-to-regexp.d.ts +2 -2
  43. package/lib/permitted-contents/permitted-content.spec-to-regexp.js +49 -30
  44. package/lib/permitted-contents/unfold-content-models-to-tags.d.ts +1 -1
  45. package/lib/permitted-contents/unfold-content-models-to-tags.js +2 -3
  46. package/lib/{type-check.d.ts → primitive-check.d.ts} +24 -7
  47. package/lib/primitive-check.js +109 -0
  48. package/lib/required-attr/index.d.ts +1 -1
  49. package/lib/required-attr/index.js +12 -16
  50. package/lib/required-h1/index.d.ts +3 -3
  51. package/lib/required-h1/index.js +8 -13
  52. package/lib/wai-aria/index.d.ts +1 -1
  53. package/lib/wai-aria/index.js +57 -64
  54. package/package.json +6 -6
  55. package/tsconfig.test.json +1 -24
  56. package/tsconfig.tsbuildinfo +1 -1
  57. package/lib/type-check.js +0 -321
@@ -3,14 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  const alwaysMsg = 'Always insert {0} after {1} of {2}';
5
5
  const neverMsg = 'Never insert {0} after {1} of {2}';
6
- exports.default = ml_core_1.createRule({
7
- name: 'attr-equal-space-after',
8
- defaultLevel: 'warning',
6
+ exports.default = (0, ml_core_1.createRule)({
7
+ defaultServerity: 'warning',
9
8
  defaultValue: 'never',
10
9
  defaultOptions: null,
11
- async verify(document, translate) {
12
- const reports = [];
13
- await document.walkOn('Element', async (node) => {
10
+ async verify(context) {
11
+ await context.document.walkOn('Element', async (node) => {
14
12
  for (const attr of node.attributes) {
15
13
  if (attr.attrType === 'ps-attr' || !(attr.equal && attr.spacesAfterEqual && attr.spacesBeforeEqual)) {
16
14
  continue;
@@ -43,9 +41,9 @@ exports.default = ml_core_1.createRule({
43
41
  }
44
42
  }
45
43
  if (isBad) {
46
- reports.push({
47
- severity: node.rule.severity,
48
- message: translate(rawMessage, 'space', 'equal sign', 'attribute'),
44
+ context.report({
45
+ scope: node,
46
+ message: context.translate(rawMessage, 'space', 'equal sign', 'attribute'),
49
47
  line: attr.spacesBeforeEqual.startLine,
50
48
  col: attr.spacesBeforeEqual.startCol,
51
49
  raw: attr.spacesBeforeEqual.raw + attr.equal.raw + attr.spacesAfterEqual.raw,
@@ -53,9 +51,8 @@ exports.default = ml_core_1.createRule({
53
51
  }
54
52
  }
55
53
  });
56
- return reports;
57
54
  },
58
- async fix(document) {
55
+ async fix({ document }) {
59
56
  await document.walkOn('Element', async (node) => {
60
57
  for (const attr of node.attributes) {
61
58
  if (attr.attrType === 'ps-attr' || !(attr.equal && attr.spacesAfterEqual && attr.spacesBeforeEqual)) {
@@ -1,3 +1,3 @@
1
1
  declare type Value = 'always' | 'never' | 'always-single-line' | 'never-single-line';
2
- declare const _default: import("@markuplint/ml-core").MLRule<Value, null>;
2
+ declare const _default: import("@markuplint/ml-core").RuleSeed<Value, null>;
3
3
  export default _default;
@@ -3,14 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  const alwaysMsg = 'Always insert {0} before {1} of {2}';
5
5
  const neverMsg = 'Never insert {0} before {1} of {2}';
6
- exports.default = ml_core_1.createRule({
7
- name: 'attr-equal-space-before',
8
- defaultLevel: 'warning',
6
+ exports.default = (0, ml_core_1.createRule)({
7
+ defaultServerity: 'warning',
9
8
  defaultValue: 'never',
10
9
  defaultOptions: null,
11
- async verify(document, translate) {
12
- const reports = [];
13
- await document.walkOn('Element', async (node) => {
10
+ async verify(context) {
11
+ await context.document.walkOn('Element', async (node) => {
14
12
  for (const attr of node.attributes) {
15
13
  if (attr.attrType === 'ps-attr' || !(attr.equal && attr.spacesAfterEqual && attr.spacesBeforeEqual)) {
16
14
  continue;
@@ -43,9 +41,9 @@ exports.default = ml_core_1.createRule({
43
41
  }
44
42
  }
45
43
  if (isBad) {
46
- reports.push({
47
- severity: node.rule.severity,
48
- message: translate(rawMessage, 'space', 'equal sign', 'attribute'),
44
+ context.report({
45
+ scope: node,
46
+ message: context.translate(rawMessage, 'space', 'equal sign', 'attribute'),
49
47
  line: attr.spacesBeforeEqual.startLine,
50
48
  col: attr.spacesBeforeEqual.startCol,
51
49
  raw: attr.spacesBeforeEqual.raw + attr.equal.raw + attr.spacesAfterEqual.raw,
@@ -53,9 +51,8 @@ exports.default = ml_core_1.createRule({
53
51
  }
54
52
  }
55
53
  });
56
- return reports;
57
54
  },
58
- async fix(document) {
55
+ async fix({ document }) {
59
56
  await document.walkOn('Element', async (node) => {
60
57
  for (const attr of node.attributes) {
61
58
  if (attr.attrType === 'ps-attr' || !(attr.equal && attr.spacesAfterEqual && attr.spacesBeforeEqual)) {
@@ -1,6 +1,6 @@
1
1
  export interface AttrSpasingOptions {
2
- lineBreak: 'either' | 'always' | 'never';
3
- width: number | false;
2
+ lineBreak?: 'either' | 'always' | 'never';
3
+ width?: number | false;
4
4
  }
5
- declare const _default: import("@markuplint/ml-core").MLRule<boolean, AttrSpasingOptions>;
5
+ declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, AttrSpasingOptions>;
6
6
  export default _default;
@@ -1,17 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
- exports.default = ml_core_1.createRule({
5
- name: 'attr-spacing',
6
- defaultLevel: 'warning',
4
+ exports.default = (0, ml_core_1.createRule)({
5
+ defaultServerity: 'warning',
7
6
  defaultValue: true,
8
7
  defaultOptions: {
9
8
  lineBreak: 'either',
10
9
  width: 1,
11
10
  },
12
- async verify(document, translate) {
13
- const reports = [];
14
- await document.walkOn('Element', async (node) => {
11
+ async verify(context) {
12
+ await context.document.walkOn('Element', async (node) => {
15
13
  const attrs = node.attributes;
16
14
  for (const attr of attrs) {
17
15
  if (attr.attrType === 'ps-attr') {
@@ -21,9 +19,9 @@ exports.default = ml_core_1.createRule({
21
19
  const hasLineBreak = /\r?\n/.test(attr.spacesBeforeName.raw);
22
20
  // console.log({ attr: `${attr.spacesBeforeName.raw}${attr.raw}`, hasSpace, hasLineBreak });
23
21
  if (!hasSpace) {
24
- reports.push({
25
- severity: node.rule.severity,
26
- message: translate('Required {0}', 'space'),
22
+ context.report({
23
+ scope: node,
24
+ message: context.translate('Required {0}', 'space'),
27
25
  line: attr.spacesBeforeName.startLine,
28
26
  col: attr.spacesBeforeName.startCol,
29
27
  raw: attr.spacesBeforeName.raw,
@@ -32,9 +30,9 @@ exports.default = ml_core_1.createRule({
32
30
  else {
33
31
  if (hasLineBreak) {
34
32
  if (node.rule.option.lineBreak === 'never') {
35
- reports.push({
36
- severity: node.rule.severity,
37
- message: translate('Never {0}', 'break line'),
33
+ context.report({
34
+ scope: node,
35
+ message: context.translate('Never {0}', 'break line'),
38
36
  line: attr.spacesBeforeName.startLine,
39
37
  col: attr.spacesBeforeName.startCol,
40
38
  raw: attr.spacesBeforeName.raw,
@@ -43,18 +41,18 @@ exports.default = ml_core_1.createRule({
43
41
  }
44
42
  else {
45
43
  if (node.rule.option.lineBreak === 'always') {
46
- reports.push({
47
- severity: node.rule.severity,
48
- message: translate('Insert {0}', 'line break'),
44
+ context.report({
45
+ scope: node,
46
+ message: context.translate('Insert {0}', 'line break'),
49
47
  line: attr.spacesBeforeName.startLine,
50
48
  col: attr.spacesBeforeName.startCol,
51
49
  raw: attr.spacesBeforeName.raw,
52
50
  });
53
51
  }
54
52
  if (node.rule.option.width && node.rule.option.width !== attr.spacesBeforeName.raw.length) {
55
- reports.push({
56
- severity: node.rule.severity,
57
- message: translate('{0} should be {1}', 'Space', node.rule.option.width),
53
+ context.report({
54
+ scope: node,
55
+ message: context.translate('{0} should be {1}', 'Space', node.rule.option.width),
58
56
  line: attr.spacesBeforeName.startLine,
59
57
  col: attr.spacesBeforeName.startCol,
60
58
  raw: attr.spacesBeforeName.raw,
@@ -64,9 +62,8 @@ exports.default = ml_core_1.createRule({
64
62
  }
65
63
  }
66
64
  });
67
- return reports;
68
65
  },
69
- async fix(document) {
66
+ async fix({ document }) {
70
67
  await document.walkOn('Element', async (node) => {
71
68
  const attrs = node.attributes;
72
69
  for (const attr of attrs) {
@@ -88,7 +85,8 @@ exports.default = ml_core_1.createRule({
88
85
  }
89
86
  else {
90
87
  if (node.rule.option.lineBreak === 'always') {
91
- const expectIndent = node.indentation ? node.indentation.raw : '';
88
+ const indent = (0, ml_core_1.getIndent)(node);
89
+ const expectIndent = indent ? indent.raw : '';
92
90
  attr.spacesBeforeName.fix(`\n${expectIndent}`);
93
91
  }
94
92
  else if (node.rule.option.width &&
@@ -3,5 +3,5 @@ export declare type Quote = '"' | "'";
3
3
  export declare type QuoteMap = {
4
4
  [P in Type]: Quote;
5
5
  };
6
- declare const _default: import("@markuplint/ml-core").MLRule<Type, null>;
6
+ declare const _default: import("@markuplint/ml-core").RuleSeed<Type, null>;
7
7
  export default _default;
@@ -5,23 +5,21 @@ const quoteList = {
5
5
  double: '"',
6
6
  single: "'",
7
7
  };
8
- exports.default = ml_core_1.createRule({
9
- name: 'attr-value-quotes',
10
- defaultLevel: 'warning',
8
+ exports.default = (0, ml_core_1.createRule)({
9
+ defaultServerity: 'warning',
11
10
  defaultValue: 'double',
12
11
  defaultOptions: null,
13
- async verify(document, translate) {
14
- const reports = [];
15
- await document.walkOn('Element', async (node) => {
16
- const message = translate('{0} is must {1} on {2}', 'Attribute value', 'quote', `${node.rule.value} quotation mark`);
12
+ async verify(context) {
13
+ await context.document.walkOn('Element', async (node) => {
14
+ const message = context.translate('{0} is must {1} on {2}', 'Attribute value', 'quote', `${node.rule.value} quotation mark`);
17
15
  for (const attr of node.attributes) {
18
16
  if (attr.attrType === 'ps-attr' || attr.isDynamicValue || attr.isDirective || attr.equal.raw === '') {
19
17
  continue;
20
18
  }
21
19
  const quote = attr.startQuote.raw;
22
20
  if (quote !== quoteList[node.rule.value]) {
23
- reports.push({
24
- severity: node.rule.severity,
21
+ context.report({
22
+ scope: node,
25
23
  message,
26
24
  line: attr.name.startLine,
27
25
  col: attr.name.startCol,
@@ -30,10 +28,9 @@ exports.default = ml_core_1.createRule({
30
28
  }
31
29
  }
32
30
  });
33
- return reports;
34
31
  },
35
- async fix(document) {
36
- await document.walkOn('Element', async (node) => {
32
+ async fix(context) {
33
+ await context.document.walkOn('Element', async (node) => {
37
34
  for (const attr of node.attributes) {
38
35
  const quote = quoteList[node.rule.value];
39
36
  if (attr.attrType === 'html-attr' && quote && attr.startQuote && attr.startQuote.raw !== quote) {
@@ -1,3 +1,3 @@
1
1
  export declare type Value = 'no-upper' | 'no-lower';
2
- declare const _default: import("@markuplint/ml-core").MLRule<Value, null>;
2
+ declare const _default: import("@markuplint/ml-core").RuleSeed<Value, null>;
3
3
  export default _default;
@@ -2,22 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  const helpers_1 = require("../helpers");
5
- exports.default = ml_core_1.createRule({
6
- name: 'case-sensitive-attr-name',
7
- defaultLevel: 'warning',
5
+ exports.default = (0, ml_core_1.createRule)({
6
+ defaultServerity: 'warning',
8
7
  defaultValue: 'no-upper',
9
8
  defaultOptions: null,
10
- async verify(document, translate) {
11
- const reports = [];
9
+ async verify({ document, report, t }) {
12
10
  await document.walkOn('Element', async (node) => {
13
- if (node.namespaceURI !== 'http://www.w3.org/1999/xhtml' || node.isCustomElement) {
11
+ if (node.isForeignElement || node.isCustomElement) {
14
12
  return;
15
13
  }
16
14
  const ms = node.rule.severity === 'error' ? 'must' : 'should';
17
15
  const deny = node.rule.value === 'no-upper' ? /[A-Z]/ : /[a-z]/;
18
16
  const cases = node.rule.value === 'no-upper' ? 'lower' : 'upper';
19
- const message = translate(`{0} of {1} ${ms} be {2}`, 'Attribute name', 'HTML elements', `${cases}case`);
20
- const attrSpecs = helpers_1.getAttrSpecs(node.nodeName.toLowerCase(), document.specs);
17
+ const message = t(`{0} ${ms} be {1}`, t('{0} of {1}', 'attribute names', 'HTML elements'), `${cases}case`);
18
+ const attrSpecs = (0, helpers_1.getAttrSpecs)(node.nameWithNS, document.specs);
21
19
  for (const attr of node.attributes) {
22
20
  if (attr.attrType === 'ps-attr') {
23
21
  continue;
@@ -37,8 +35,8 @@ exports.default = ml_core_1.createRule({
37
35
  }
38
36
  }
39
37
  if (deny.test(name.raw)) {
40
- reports.push({
41
- severity: node.rule.severity,
38
+ report({
39
+ scope: node,
42
40
  message,
43
41
  line: name.line,
44
42
  col: name.col,
@@ -47,14 +45,13 @@ exports.default = ml_core_1.createRule({
47
45
  }
48
46
  }
49
47
  });
50
- return reports;
51
48
  },
52
- async fix(document) {
49
+ async fix({ document }) {
53
50
  await document.walkOn('Element', async (node) => {
54
- if (node.namespaceURI !== 'http://www.w3.org/1999/xhtml' || node.isCustomElement) {
51
+ if (node.isForeignElement || node.isCustomElement) {
55
52
  return;
56
53
  }
57
- const attrSpecs = helpers_1.getAttrSpecs(node.nodeName.toLowerCase(), document.specs);
54
+ const attrSpecs = (0, helpers_1.getAttrSpecs)(node.nameWithNS, document.specs);
58
55
  if (node.attributes) {
59
56
  for (const attr of node.attributes) {
60
57
  if (attr.attrType === 'ps-attr') {
@@ -1,3 +1,3 @@
1
1
  export declare type Value = 'lower' | 'upper';
2
- declare const _default: import("@markuplint/ml-core").MLRule<Value, null>;
2
+ declare const _default: import("@markuplint/ml-core").RuleSeed<Value, null>;
3
3
  export default _default;
@@ -1,25 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
- exports.default = ml_core_1.createRule({
5
- name: 'case-sensitive-tag-name',
6
- defaultLevel: 'warning',
4
+ exports.default = (0, ml_core_1.createRule)({
5
+ defaultServerity: 'warning',
7
6
  defaultValue: 'lower',
8
7
  defaultOptions: null,
9
- async verify(document, translate) {
10
- const reports = [];
8
+ async verify({ document, report, t }) {
11
9
  await document.walk(async (node) => {
12
10
  if ('fixNodeName' in node) {
13
- if (node.isForeignElement || node.isCustomElement) {
11
+ if (node.isForeignElement || node.isCustomElement || node.type === 'OmittedElement') {
14
12
  return;
15
13
  }
16
14
  const ms = node.rule.severity === 'error' ? 'must' : 'should';
17
15
  const deny = node.rule.value === 'lower' ? /[A-Z]/ : /[a-z]/;
18
- const message = translate(`{0} of {1} ${ms} be {2}`, 'Tag name', 'HTML elements', `${node.rule.value}case`);
16
+ const message = t(`{0} ${ms} be {1}`, t('{0} of {1}', 'tag names', 'HTML elements'), `${node.rule.value}case`);
19
17
  if (deny.test(node.nodeName)) {
20
18
  const loc = node.getNameLocation();
21
- reports.push({
22
- severity: node.rule.severity,
19
+ report({
20
+ scope: node,
23
21
  message,
24
22
  line: loc.line,
25
23
  col: loc.col,
@@ -28,9 +26,8 @@ exports.default = ml_core_1.createRule({
28
26
  }
29
27
  }
30
28
  });
31
- return reports;
32
29
  },
33
- async fix(document) {
30
+ async fix({ document }) {
34
31
  await document.walk(async (node) => {
35
32
  if ('fixNodeName' in node) {
36
33
  if (node.isForeignElement || node.isCustomElement) {
@@ -1,3 +1,3 @@
1
1
  export declare type Value = boolean;
2
- declare const _default: import("@markuplint/ml-core").MLRule<boolean, null>;
2
+ declare const _default: import("@markuplint/ml-core").RuleSeed<boolean, null>;
3
3
  export default _default;
@@ -3,12 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  const defaultChars = ['"', '&', '<', '>'];
5
5
  const ignoreParentElement = ['script', 'style'];
6
- exports.default = ml_core_1.createRule({
7
- name: 'character-reference',
6
+ exports.default = (0, ml_core_1.createRule)({
8
7
  defaultValue: true,
9
8
  defaultOptions: null,
10
- async verify(document, translate) {
11
- const reports = [];
9
+ async verify({ document, report, t }) {
12
10
  const targetNodes = [];
13
11
  await document.walkOn('Text', async (node) => {
14
12
  if (node.parentNode && ignoreParentElement.includes(node.parentNode.nodeName.toLowerCase())) {
@@ -16,9 +14,9 @@ exports.default = ml_core_1.createRule({
16
14
  }
17
15
  const severity = node.rule.severity;
18
16
  const ms = severity === 'error' ? 'must' : 'should';
19
- const message = translate(`{0} ${ms} {1}`, 'Illegal characters', 'escape in character reference');
17
+ const message = t(`{0} ${ms} {1}`, 'Illegal characters', 'escape in character reference');
20
18
  targetNodes.push({
21
- severity,
19
+ scope: node,
22
20
  line: node.startLine,
23
21
  col: node.startCol,
24
22
  raw: node.raw,
@@ -28,7 +26,7 @@ exports.default = ml_core_1.createRule({
28
26
  await document.walkOn('Element', async (node) => {
29
27
  const severity = node.rule.severity;
30
28
  const ms = severity === 'error' ? 'must' : 'should';
31
- const message = translate(`{0} ${ms} {1}`, 'Illegal characters', 'escape in character reference');
29
+ const message = t(`{0} ${ms} {1}`, 'Illegal characters', 'escape in character reference');
32
30
  for (const attr of node.attributes) {
33
31
  if (attr.attrType === 'ps-attr' ||
34
32
  (attr.attrType === 'html-attr' && attr.isDynamicValue) ||
@@ -37,7 +35,7 @@ exports.default = ml_core_1.createRule({
37
35
  }
38
36
  const value = attr.getValue();
39
37
  targetNodes.push({
40
- severity,
38
+ scope: node,
41
39
  line: value.line,
42
40
  col: value.col,
43
41
  raw: value.raw,
@@ -46,11 +44,17 @@ exports.default = ml_core_1.createRule({
46
44
  }
47
45
  });
48
46
  for (const targetNode of targetNodes) {
47
+ if (!('scope' in targetNode && 'line' in targetNode)) {
48
+ continue;
49
+ }
49
50
  const escapedText = targetNode.raw.replace(/&(?:[a-z]+|#[0-9]+|x[0-9]);/gi, $0 => '*'.repeat($0.length));
50
- ml_core_1.getLocationFromChars(defaultChars, escapedText, targetNode.line, targetNode.col).forEach(location => {
51
- reports.push(Object.assign({ severity: targetNode.severity, message: targetNode.message }, location));
51
+ (0, ml_core_1.getLocationFromChars)(defaultChars, escapedText, targetNode.line, targetNode.col).forEach(location => {
52
+ report({
53
+ scope: targetNode.scope,
54
+ message: targetNode.message,
55
+ ...location,
56
+ });
52
57
  });
53
58
  }
54
- return reports;
55
59
  },
56
60
  });
@@ -1,3 +1,3 @@
1
1
  export declare type Value = string | string[] | null;
2
- declare const _default: import("@markuplint/ml-core").MLRule<Value, null>;
2
+ declare const _default: import("@markuplint/ml-core").RuleSeed<Value, null>;
3
3
  export default _default;
@@ -2,13 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  const helpers_1 = require("../helpers");
5
- exports.default = ml_core_1.createRule({
6
- name: 'class-naming',
7
- defaultLevel: 'warning',
5
+ exports.default = (0, ml_core_1.createRule)({
6
+ defaultServerity: 'warning',
8
7
  defaultValue: null,
9
8
  defaultOptions: null,
10
- async verify(document, translate) {
11
- const reports = [];
9
+ async verify({ document, report, t }) {
12
10
  await document.walkOn('Element', async (node) => {
13
11
  if (node.rule.value) {
14
12
  const classPatterns = Array.isArray(node.rule.value) ? node.rule.value : [node.rule.value];
@@ -23,10 +21,10 @@ exports.default = ml_core_1.createRule({
23
21
  .map(c => c.trim())
24
22
  .filter(c => c);
25
23
  for (const className of classList) {
26
- if (!classPatterns.some(pattern => helpers_1.match(className, pattern))) {
27
- reports.push({
28
- severity: node.rule.severity,
29
- message: translate('{0} {1} is unmatched patterns ({2})', `"${className}"`, 'class name', `"${classPatterns.join('", "')}"`),
24
+ if (!classPatterns.some(pattern => (0, helpers_1.match)(className, pattern))) {
25
+ report({
26
+ scope: node,
27
+ message: t('{0} is unmatched with the below patterns: {1}', t('the "{0}" {1}', className, 'class name'), `"${classPatterns.join('", "')}"`),
30
28
  line: classAttr.line,
31
29
  col: classAttr.col,
32
30
  raw: classAttr.raw,
@@ -36,6 +34,5 @@ exports.default = ml_core_1.createRule({
36
34
  }
37
35
  }
38
36
  });
39
- return reports;
40
37
  },
41
38
  });
@@ -1,2 +1,2 @@
1
- declare const _default: import("@markuplint/ml-core").MLRule<null, null>;
1
+ declare const _default: import("@markuplint/ml-core").RuleSeed<null, null>;
2
2
  export default _default;
@@ -2,14 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
4
  const helpers_1 = require("../helpers");
5
- exports.default = ml_core_1.createRule({
6
- name: 'deprecated-attr',
5
+ exports.default = (0, ml_core_1.createRule)({
7
6
  defaultValue: null,
8
7
  defaultOptions: null,
9
- async verify(document, translate) {
10
- const reports = [];
8
+ async verify({ document, report, t }) {
11
9
  await document.walkOn('Element', async (element) => {
12
- const attrSpecs = helpers_1.getAttrSpecs(element.nodeName, document.specs);
10
+ const attrSpecs = (0, helpers_1.getAttrSpecs)(element.nameWithNS, document.specs);
13
11
  if (!attrSpecs) {
14
12
  return;
15
13
  }
@@ -20,9 +18,9 @@ exports.default = ml_core_1.createRule({
20
18
  return;
21
19
  }
22
20
  if (attrSpec.deprecated || attrSpec.obsolete) {
23
- const message = translate('The {0} {1} is {2}', name.potential, 'attribute', attrSpec.obsolete ? 'obsolete' : 'deprecated');
24
- reports.push({
25
- severity: element.rule.severity,
21
+ const message = t('{0} is {1:c}', t('the "{0}" {1}', name.potential, 'attribute'), attrSpec.obsolete ? 'obsolete' : 'deprecated');
22
+ report({
23
+ scope: element,
26
24
  message,
27
25
  line: name.line,
28
26
  col: name.col,
@@ -31,6 +29,5 @@ exports.default = ml_core_1.createRule({
31
29
  }
32
30
  }
33
31
  });
34
- return reports;
35
32
  },
36
33
  });
@@ -1,2 +1,2 @@
1
- declare const _default: import("@markuplint/ml-core").MLRule<null, null>;
1
+ declare const _default: import("@markuplint/ml-core").RuleSeed<null, null>;
2
2
  export default _default;
@@ -1,31 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ const html_spec_1 = (0, tslib_1.__importDefault)(require("@markuplint/html-spec"));
4
5
  const ml_core_1 = require("@markuplint/ml-core");
5
6
  const ml_spec_1 = require("@markuplint/ml-spec");
6
- const html_spec_1 = tslib_1.__importDefault(require("@markuplint/html-spec"));
7
- exports.default = ml_core_1.createRule({
8
- name: 'deprecated-element',
7
+ exports.default = (0, ml_core_1.createRule)({
9
8
  defaultValue: null,
10
9
  defaultOptions: null,
11
- async verify(document, translate) {
12
- const reports = [];
13
- const message = translate('{0} is {1}', 'Element', 'deprecated');
14
- await document.walkOn('Element', async (element) => {
15
- if (element.isForeignElement || element.isCustomElement) {
10
+ async verify({ document, report, t }) {
11
+ await document.walkOn('Element', async (el) => {
12
+ const ns = el.ns;
13
+ if (!(ns === 'html' || ns === 'svg') || el.isCustomElement) {
16
14
  return;
17
15
  }
18
- const spec = ml_spec_1.getSpecByTagName(element.nodeName, html_spec_1.default);
16
+ const spec = (0, ml_spec_1.getSpecByTagName)(el.nameWithNS, html_spec_1.default);
19
17
  if (spec && (spec.obsolete || spec.deprecated || spec.nonStandard)) {
20
- reports.push({
21
- severity: element.rule.severity,
18
+ const message = t('{0} is {1:c}', t('the "{0}" {1}', el.nodeName, 'element'), spec.deprecated ? 'deprecated' : spec.obsolete ? 'obsolete' : 'non-standard');
19
+ report({
20
+ scope: el,
22
21
  message,
23
- line: element.startLine,
24
- col: element.startCol,
25
- raw: element.raw,
26
22
  });
27
23
  }
28
24
  });
29
- return reports;
30
25
  },
31
26
  });
@@ -1,5 +1,5 @@
1
1
  declare type Option = {
2
2
  denyObsolateType: boolean;
3
3
  };
4
- declare const _default: import("@markuplint/ml-core").MLRule<"always", Option>;
4
+ declare const _default: import("@markuplint/ml-core").RuleSeed<"always", Option>;
5
5
  export default _default;
@@ -1,39 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ml_core_1 = require("@markuplint/ml-core");
4
- exports.default = ml_core_1.createRule({
5
- name: 'doctype',
4
+ exports.default = (0, ml_core_1.createRule)({
6
5
  defaultValue: 'always',
7
6
  defaultOptions: {
8
7
  denyObsolateType: true,
9
8
  },
10
- async verify(document, translate, rule) {
11
- if (document.isFragment) {
12
- return [];
9
+ async verify(context) {
10
+ if (context.document.isFragment) {
11
+ return;
13
12
  }
14
- const doctype = document.doctype;
13
+ const doctype = context.document.doctype;
15
14
  if (!doctype) {
16
- return [
17
- {
18
- severity: rule.severity,
19
- message: translate('Required {0}', 'doctype'),
20
- line: 1,
21
- col: 1,
22
- raw: '',
23
- },
24
- ];
15
+ context.report({
16
+ message: context.translate('Require {0}', 'doctype'),
17
+ line: 1,
18
+ col: 1,
19
+ raw: '',
20
+ });
21
+ return;
25
22
  }
26
23
  if ((doctype.name.toLowerCase() === 'html' && doctype.publicId) || doctype.systemId) {
27
- return [
28
- {
29
- severity: rule.severity,
30
- message: translate('Never {0} {1}', 'declarate', 'obsolete doctype'),
31
- line: doctype.startLine,
32
- col: doctype.startCol,
33
- raw: doctype.raw,
34
- },
35
- ];
24
+ context.report({
25
+ scope: doctype,
26
+ message: context.translate('Never {0} {1}', 'declarate', 'obsolete doctype'),
27
+ });
36
28
  }
37
- return [];
38
29
  },
39
30
  });