@markuplint/rules 3.11.0 → 4.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 (142) hide show
  1. package/lib/attr-check.js +14 -19
  2. package/lib/attr-duplication/index.js +3 -6
  3. package/lib/attr-value-quotes/index.js +5 -9
  4. package/lib/case-sensitive-attr-name/index.js +9 -13
  5. package/lib/case-sensitive-tag-name/index.js +2 -4
  6. package/lib/character-reference/index.js +6 -8
  7. package/lib/class-naming/index.js +9 -11
  8. package/lib/create-message.js +9 -16
  9. package/lib/debug.js +2 -6
  10. package/lib/deprecated-attr/index.js +6 -9
  11. package/lib/deprecated-element/index.js +3 -5
  12. package/lib/disallowed-element/index.js +2 -4
  13. package/lib/doctype/index.js +2 -4
  14. package/lib/end-tag/index.js +5 -8
  15. package/lib/helpers.d.ts +1 -1
  16. package/lib/helpers.js +17 -28
  17. package/lib/id-duplication/index.js +2 -4
  18. package/lib/index.d.ts +15 -15
  19. package/lib/index.js +63 -66
  20. package/lib/ineffective-attr/index.js +5 -7
  21. package/lib/invalid-attr/index.js +30 -33
  22. package/lib/label-has-control/index.js +2 -4
  23. package/lib/landmark-roles/index.js +3 -6
  24. package/lib/no-boolean-attr-value/index.js +6 -9
  25. package/lib/no-default-value/index.js +9 -12
  26. package/lib/no-empty-palpable-content/index.js +5 -7
  27. package/lib/no-hard-code-id/index.js +2 -4
  28. package/lib/no-refer-to-non-existent-id/index.js +26 -30
  29. package/lib/no-use-event-handler-attr/index.js +4 -6
  30. package/lib/permitted-contents/choice.d.ts +1 -1
  31. package/lib/permitted-contents/choice.js +13 -18
  32. package/lib/permitted-contents/complex-branch.d.ts +1 -1
  33. package/lib/permitted-contents/complex-branch.js +10 -14
  34. package/lib/permitted-contents/content-model.d.ts +1 -1
  35. package/lib/permitted-contents/content-model.js +5 -9
  36. package/lib/permitted-contents/count-pattern.d.ts +1 -1
  37. package/lib/permitted-contents/count-pattern.js +19 -24
  38. package/lib/permitted-contents/debug.browser.js +9 -12
  39. package/lib/permitted-contents/debug.d.ts +8 -1
  40. package/lib/permitted-contents/debug.js +12 -13
  41. package/lib/permitted-contents/index.d.ts +1 -1
  42. package/lib/permitted-contents/index.js +10 -13
  43. package/lib/permitted-contents/matches-selector.d.ts +1 -1
  44. package/lib/permitted-contents/matches-selector.js +12 -17
  45. package/lib/permitted-contents/order.d.ts +1 -1
  46. package/lib/permitted-contents/order.js +17 -22
  47. package/lib/permitted-contents/recursive-branch.d.ts +2 -2
  48. package/lib/permitted-contents/recursive-branch.js +9 -13
  49. package/lib/permitted-contents/represent-transparent-nodes.d.ts +1 -1
  50. package/lib/permitted-contents/represent-transparent-nodes.js +15 -20
  51. package/lib/permitted-contents/start.d.ts +1 -1
  52. package/lib/permitted-contents/start.js +13 -21
  53. package/lib/permitted-contents/transparent.d.ts +1 -1
  54. package/lib/permitted-contents/transparent.js +4 -9
  55. package/lib/permitted-contents/types.js +1 -2
  56. package/lib/permitted-contents/utils.d.ts +1 -1
  57. package/lib/permitted-contents/utils.js +55 -74
  58. package/lib/placeholder-label-option/index.js +5 -9
  59. package/lib/require-accessible-name/index.js +10 -13
  60. package/lib/require-datetime/index.d.ts +1 -1
  61. package/lib/require-datetime/index.js +6 -8
  62. package/lib/require-datetime/types.js +1 -2
  63. package/lib/require-datetime/utils.d.ts +1 -1
  64. package/lib/require-datetime/utils.js +4 -11
  65. package/lib/required-attr/index.js +8 -11
  66. package/lib/required-element/index.js +3 -6
  67. package/lib/required-h1/index.js +3 -6
  68. package/lib/use-list/index.js +6 -10
  69. package/lib/wai-aria/checkings/abstract-role.d.ts +1 -1
  70. package/lib/wai-aria/checkings/abstract-role.js +5 -10
  71. package/lib/wai-aria/checkings/default-value.d.ts +1 -1
  72. package/lib/wai-aria/checkings/default-value.js +2 -6
  73. package/lib/wai-aria/checkings/deprecated-props.d.ts +1 -1
  74. package/lib/wai-aria/checkings/deprecated-props.js +3 -8
  75. package/lib/wai-aria/checkings/disallowed-prop.d.ts +1 -1
  76. package/lib/wai-aria/checkings/disallowed-prop.js +7 -12
  77. package/lib/wai-aria/checkings/implicit-props.d.ts +1 -1
  78. package/lib/wai-aria/checkings/implicit-props.js +6 -11
  79. package/lib/wai-aria/checkings/implicit-role.d.ts +1 -1
  80. package/lib/wai-aria/checkings/implicit-role.js +4 -9
  81. package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +1 -1
  82. package/lib/wai-aria/checkings/interaction-in-hidden.js +4 -8
  83. package/lib/wai-aria/checkings/no-global-prop.d.ts +1 -1
  84. package/lib/wai-aria/checkings/no-global-prop.js +2 -7
  85. package/lib/wai-aria/checkings/non-existent-role.d.ts +1 -1
  86. package/lib/wai-aria/checkings/non-existent-role.js +4 -9
  87. package/lib/wai-aria/checkings/permitted-roles.d.ts +1 -1
  88. package/lib/wai-aria/checkings/permitted-roles.js +4 -9
  89. package/lib/wai-aria/checkings/presentational-children.d.ts +1 -1
  90. package/lib/wai-aria/checkings/presentational-children.js +4 -9
  91. package/lib/wai-aria/checkings/required-owned-elements.d.ts +1 -1
  92. package/lib/wai-aria/checkings/required-owned-elements.js +4 -8
  93. package/lib/wai-aria/checkings/required-prop.d.ts +1 -1
  94. package/lib/wai-aria/checkings/required-prop.js +2 -7
  95. package/lib/wai-aria/checkings/value.d.ts +1 -1
  96. package/lib/wai-aria/checkings/value.js +4 -10
  97. package/lib/wai-aria/index.d.ts +1 -1
  98. package/lib/wai-aria/index.js +38 -40
  99. package/lib/wai-aria/types.js +1 -2
  100. package/package.json +17 -12
  101. package/test/attr-check.spec.js +0 -77
  102. package/test/attr-duplication/index.spec.js +0 -159
  103. package/test/attr-value-quotes/index.spec.js +0 -133
  104. package/test/case-sensitive-attr-name/index.spec.js +0 -65
  105. package/test/case-sensitive-tag-name/index.spec.js +0 -80
  106. package/test/character-reference/index.spec.js +0 -72
  107. package/test/class-naming/index.spec.js +0 -470
  108. package/test/create-message.spec.js +0 -497
  109. package/test/deprecated-attr/index.spec.js +0 -48
  110. package/test/deprecated-element/index.spec.js +0 -35
  111. package/test/disallowed-element/index.spec.js +0 -90
  112. package/test/doctype/index.spec.js +0 -50
  113. package/test/end-tag/index.spec.js +0 -162
  114. package/test/id-duplication/index.spec.js +0 -47
  115. package/test/ineffective-attr/index.spec.js +0 -31
  116. package/test/invalid-attr/index.spec.js +0 -1632
  117. package/test/label-has-control/index.spec.js +0 -29
  118. package/test/landmark-roles/index.spec.js +0 -187
  119. package/test/no-boolean-attr-value/index.spec.js +0 -41
  120. package/test/no-default-value/index.spec.js +0 -74
  121. package/test/no-empty-palpable-content/index.spec.js +0 -115
  122. package/test/no-hard-code-id/index.spec.js +0 -100
  123. package/test/no-refer-to-non-existent-id/index.spec.js +0 -254
  124. package/test/no-use-event-handler-attr/index.spec.js +0 -57
  125. package/test/permitted-contents/choice.spec.js +0 -174
  126. package/test/permitted-contents/count-pattern.spec.js +0 -308
  127. package/test/permitted-contents/index.spec.js +0 -1395
  128. package/test/permitted-contents/matches-selector.spec.js +0 -59
  129. package/test/permitted-contents/order.spec.js +0 -351
  130. package/test/permitted-contents/recursive-branch.spec.js +0 -41
  131. package/test/permitted-contents/represent-transparent-nodes.spec.js +0 -24
  132. package/test/permitted-contents/start.spec.js +0 -67
  133. package/test/placeholder-label-option/index.spec.js +0 -113
  134. package/test/require-accessible-name/index.spec.js +0 -467
  135. package/test/require-datetime/index.spec.js +0 -54
  136. package/test/require-datetime/utils.spec.js +0 -52
  137. package/test/required-attr/index.spec.js +0 -414
  138. package/test/required-element/index.spec.js +0 -188
  139. package/test/required-h1/index.spec.js +0 -69
  140. package/test/use-list/index.spec.js +0 -109
  141. package/test/wai-aria/checkings/value.spec.js +0 -33
  142. package/test/wai-aria/index.spec.js +0 -1173
@@ -1,23 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ml_core_1 = require("@markuplint/ml-core");
4
- const ml_spec_1 = require("@markuplint/ml-spec");
5
- const helpers_1 = require("../helpers");
6
- const abstract_role_1 = require("./checkings/abstract-role");
7
- const default_value_1 = require("./checkings/default-value");
8
- const deprecated_props_1 = require("./checkings/deprecated-props");
9
- const disallowed_prop_1 = require("./checkings/disallowed-prop");
10
- const implicit_props_1 = require("./checkings/implicit-props");
11
- const implicit_role_1 = require("./checkings/implicit-role");
12
- const interaction_in_hidden_1 = require("./checkings/interaction-in-hidden");
13
- const no_global_prop_1 = require("./checkings/no-global-prop");
14
- const non_existent_role_1 = require("./checkings/non-existent-role");
15
- const permitted_roles_1 = require("./checkings/permitted-roles");
16
- const presentational_children_1 = require("./checkings/presentational-children");
17
- const required_owned_elements_1 = require("./checkings/required-owned-elements");
18
- const required_prop_1 = require("./checkings/required-prop");
19
- const value_1 = require("./checkings/value");
20
- exports.default = (0, ml_core_1.createRule)({
1
+ import { createRule, getAttrSpecs, getComputedRole, ariaSpecs, getSpec } from '@markuplint/ml-core';
2
+ import { ARIA_RECOMMENDED_VERSION } from '@markuplint/ml-spec';
3
+ import { Collection } from '../helpers.js';
4
+ import { checkingAbstractRole } from './checkings/abstract-role.js';
5
+ import { checkingDefaultValue } from './checkings/default-value.js';
6
+ import { checkingDeprecatedProps } from './checkings/deprecated-props.js';
7
+ import { checkingDisallowedProp } from './checkings/disallowed-prop.js';
8
+ import { checkingImplicitProps } from './checkings/implicit-props.js';
9
+ import { checkingImplicitRole } from './checkings/implicit-role.js';
10
+ import { checkingInteractionInHidden } from './checkings/interaction-in-hidden.js';
11
+ import { checkingNoGlobalProp } from './checkings/no-global-prop.js';
12
+ import { checkingNonExistentRole } from './checkings/non-existent-role.js';
13
+ import { checkingPermittedRoles } from './checkings/permitted-roles.js';
14
+ import { checkingPresentationalChildren } from './checkings/presentational-children.js';
15
+ import { checkingRequiredOwnedElements } from './checkings/required-owned-elements.js';
16
+ import { checkingRequiredProp } from './checkings/required-prop.js';
17
+ import { checkingValue } from './checkings/value.js';
18
+ export default createRule({
21
19
  defaultOptions: {
22
20
  checkingValue: true,
23
21
  checkingDeprecatedProps: true,
@@ -28,14 +26,14 @@ exports.default = (0, ml_core_1.createRule)({
28
26
  disallowSetImplicitRole: true,
29
27
  disallowSetImplicitProps: true,
30
28
  disallowDefaultValue: false,
31
- version: ml_spec_1.ARIA_RECOMMENDED_VERSION,
29
+ version: ARIA_RECOMMENDED_VERSION,
32
30
  },
33
31
  async verify({ document, report, t }) {
34
32
  await document.walkOn('Element', el => {
35
33
  const roleAttr = el.getAttributeNode('role');
36
34
  const propAttrs = el.attributes.filter(attr => /^aria-/i.test(attr.name));
37
- const ariaAttrs = new helpers_1.Collection(roleAttr, ...propAttrs);
38
- const elSpec = (0, ml_core_1.getSpec)(el, document.specs.specs);
35
+ const ariaAttrs = new Collection(roleAttr, ...propAttrs);
36
+ const elSpec = getSpec(el, document.specs.specs);
39
37
  if (!elSpec) {
40
38
  return;
41
39
  }
@@ -48,50 +46,50 @@ exports.default = (0, ml_core_1.createRule)({
48
46
  }
49
47
  return;
50
48
  }
51
- const computed = (0, ml_core_1.getComputedRole)(document.specs, el, el.rule.options.version);
52
- const { props: propSpecs } = (0, ml_core_1.ariaSpecs)(document.specs, el.rule.options.version);
49
+ const computed = getComputedRole(document.specs, el, el.rule.options.version);
50
+ const { props: propSpecs } = ariaSpecs(document.specs, el.rule.options.version);
53
51
  if (roleAttr) {
54
- if (report((0, non_existent_role_1.checkingNonExistentRole)({ attr: roleAttr }))) {
52
+ if (report(checkingNonExistentRole({ attr: roleAttr }))) {
55
53
  return;
56
54
  }
57
- if (report((0, abstract_role_1.checkingAbstractRole)({ attr: roleAttr }))) {
55
+ if (report(checkingAbstractRole({ attr: roleAttr }))) {
58
56
  return;
59
57
  }
60
- report((0, required_prop_1.checkingRequiredProp)({ el, role: computed.role, propSpecs }));
58
+ report(checkingRequiredProp({ el, role: computed.role, propSpecs }));
61
59
  if (el.rule.options.disallowSetImplicitRole) {
62
- report((0, implicit_role_1.checkingImplicitRole)({ attr: roleAttr }));
60
+ report(checkingImplicitRole({ attr: roleAttr }));
63
61
  }
64
62
  if (el.rule.options.permittedAriaRoles) {
65
- report((0, permitted_roles_1.checkingPermittedRoles)({ attr: roleAttr }));
63
+ report(checkingPermittedRoles({ attr: roleAttr }));
66
64
  }
67
65
  }
68
66
  for (const attr of propAttrs) {
69
- report((0, disallowed_prop_1.checkingDisallowedProp)({ attr, role: computed.role, propSpecs }));
67
+ report(checkingDisallowedProp({ attr, role: computed.role, propSpecs }));
70
68
  if (el.rule.options.checkingDeprecatedProps) {
71
- report((0, deprecated_props_1.checkingDeprecatedProps)({ attr, role: computed.role, propSpecs }));
69
+ report(checkingDeprecatedProps({ attr, role: computed.role, propSpecs }));
72
70
  }
73
71
  if (el.rule.options.disallowSetImplicitProps) {
74
- const attrSpecs = (0, ml_core_1.getAttrSpecs)(el, document.specs);
75
- report((0, implicit_props_1.checkingImplicitProps)({ attr, propSpecs, attrSpecs }));
72
+ const attrSpecs = getAttrSpecs(el, document.specs);
73
+ report(checkingImplicitProps({ attr, propSpecs, attrSpecs }));
76
74
  }
77
75
  if (el.rule.options.checkingValue) {
78
- report((0, value_1.checkingValue)({ attr, role: computed.role, propSpecs, booleanish: document.booleanish }));
76
+ report(checkingValue({ attr, role: computed.role, propSpecs, booleanish: document.booleanish }));
79
77
  }
80
78
  if (el.rule.options.disallowDefaultValue) {
81
- report((0, default_value_1.checkingDefaultValue)({ attr, propSpecs }));
79
+ report(checkingDefaultValue({ attr, propSpecs }));
82
80
  }
83
81
  if (!computed.role) {
84
- report((0, no_global_prop_1.checkingNoGlobalProp)({ attr, propSpecs }));
82
+ report(checkingNoGlobalProp({ attr, propSpecs }));
85
83
  }
86
84
  }
87
85
  if (el.rule.options.checkingRequiredOwnedElements) {
88
- report((0, required_owned_elements_1.checkingRequiredOwnedElements)({ el, role: computed.role }));
86
+ report(checkingRequiredOwnedElements({ el, role: computed.role }));
89
87
  }
90
88
  if (el.rule.options.checkingPresentationalChildren) {
91
- report((0, presentational_children_1.checkingPresentationalChildren)({ el }));
89
+ report(checkingPresentationalChildren({ el }));
92
90
  }
93
91
  if (el.rule.options.checkingInteractionInHidden) {
94
- report((0, interaction_in_hidden_1.checkingInteractionInHidden)({ el }));
92
+ report(checkingInteractionInHidden({ el }));
95
93
  }
96
94
  });
97
95
  },
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@markuplint/rules",
3
- "version": "3.11.0",
3
+ "version": "4.0.0-alpha.1",
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>",
7
7
  "license": "MIT",
8
8
  "private": false,
9
- "main": "lib/index.js",
10
- "types": "lib/index.d.ts",
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./lib/index.js"
13
+ }
14
+ },
15
+ "types": "./lib/index.d.ts",
11
16
  "publishConfig": {
12
17
  "access": "public"
13
18
  },
@@ -20,19 +25,19 @@
20
25
  "./lib/permitted-contents/debug.js": "./lib/permitted-contents/debug.browser.js"
21
26
  },
22
27
  "dependencies": {
23
- "@markuplint/html-spec": "3.10.0",
24
- "@markuplint/ml-core": "3.11.0",
25
- "@markuplint/ml-spec": "3.10.0",
26
- "@markuplint/selector": "3.10.0",
27
- "@markuplint/shared": "3.7.0",
28
- "@markuplint/types": "3.8.0",
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",
29
34
  "@types/debug": "^4.1.8",
30
35
  "@ungap/structured-clone": "^1.2.0",
31
36
  "ansi-colors": "^4.1.3",
32
37
  "chrono-node": "^2.6.3",
33
38
  "debug": "^4.3.4",
34
- "tslib": "^2.5.3",
35
- "type-fest": "^3.11.1"
39
+ "tslib": "^2.6.1",
40
+ "type-fest": "^4.1.0"
36
41
  },
37
- "gitHead": "9547b8dca20736a93e4d01af2d61bee314ba5718"
42
+ "gitHead": "22502ee22a378ae766033d687dbc0443e5ed35dc"
38
43
  }
@@ -1,77 +0,0 @@
1
- const { translator } = require('@markuplint/i18n');
2
- const { i18n } = require('markuplint');
3
-
4
- const { valueCheck } = require('../lib/attr-check');
5
-
6
- let t;
7
-
8
- beforeAll(async () => {
9
- const locale = await i18n('en');
10
- t = translator(locale);
11
- });
12
-
13
- test('OneCodePointChar List', () => {
14
- expect(
15
- valueCheck(t, 'accesskey', '@ 12', {
16
- token: 'OneCodePointChar',
17
- separator: 'space',
18
- unique: true,
19
- }),
20
- ).toStrictEqual([
21
- 'the "accesskey" attribute expects space-separated list. the the content of the list part includes unexpected characters. It expects one code point character (https://html.spec.whatwg.org/multipage/interaction.html#the-accesskey-attribute)',
22
- {
23
- col: 2,
24
- line: 0,
25
- raw: '12',
26
- },
27
- ]);
28
- });
29
-
30
- test('BrowsingContextNameOrKeyword', () => {
31
- expect(valueCheck(t, 'target', '', 'BrowsingContextNameOrKeyword')).toStrictEqual([
32
- 'the "target" attribute must not be empty. It expects either "_blank", "_self", "_parent", "_top", "browsing context name" (https://html.spec.whatwg.org/multipage/browsers.html#valid-browsing-context-name-or-keyword)',
33
- {
34
- col: 0,
35
- line: 0,
36
- raw: '',
37
- },
38
- ]);
39
- });
40
-
41
- test('BCP47', () => {
42
- expect(valueCheck(t, 'lang', '', 'BCP47')).toStrictEqual([
43
- 'the "lang" attribute must not be empty. It expects the BCP47 format (https://tools.ietf.org/rfc/bcp/bcp47.html)',
44
- {
45
- col: 0,
46
- line: 0,
47
- raw: '',
48
- },
49
- ]);
50
- });
51
-
52
- test('DateTime', () => {
53
- expect(valueCheck(t, 'datetime', '200-1-1', 'DateTime')).toStrictEqual([
54
- 'the year part of the "datetime" attribute expects four or more digits (https://html.spec.whatwg.org/multipage/text-level-semantics.html#datetime-value)',
55
- {
56
- col: 0,
57
- line: 0,
58
- raw: '200',
59
- },
60
- ]);
61
- expect(valueCheck(t, 'datetime', '2000-1-1', 'DateTime')).toStrictEqual([
62
- 'the month part of the "datetime" attribute expects two digits (https://html.spec.whatwg.org/multipage/text-level-semantics.html#datetime-value)',
63
- {
64
- col: 5,
65
- line: 0,
66
- raw: '1',
67
- },
68
- ]);
69
- expect(valueCheck(t, 'datetime', '00:00:00.0000', 'DateTime')).toStrictEqual([
70
- 'the fractional part part of the "datetime" attribute expects one to three digits (https://html.spec.whatwg.org/multipage/text-level-semantics.html#datetime-value)',
71
- {
72
- col: 9,
73
- line: 0,
74
- raw: '0000',
75
- },
76
- ]);
77
- });
@@ -1,159 +0,0 @@
1
- const { mlRuleTest } = require('markuplint');
2
-
3
- const rule = require('../../lib/attr-duplication').default;
4
-
5
- test('is test 1', async () => {
6
- const { violations } = await mlRuleTest(
7
- rule,
8
- `
9
- <div data-attr="value" data-Attr='db' data-attR=tr>
10
- lorem
11
- <p>ipsam</p>
12
- </div>
13
- `,
14
- );
15
-
16
- expect(violations).toStrictEqual([
17
- {
18
- severity: 'error',
19
- message: 'The attribute name is duplicated',
20
- line: 2,
21
- col: 26,
22
- raw: 'data-Attr',
23
- },
24
- {
25
- severity: 'error',
26
- message: 'The attribute name is duplicated',
27
- line: 2,
28
- col: 41,
29
- raw: 'data-attR',
30
- },
31
- ]);
32
- });
33
-
34
- test('is test 2', async () => {
35
- const { violations } = await mlRuleTest(
36
- rule,
37
- `
38
- <div
39
- data-attr="value"
40
- data-Attr='db'
41
- data-attR=tr>
42
- lorem
43
- <p>ipsam</p>
44
- </div>
45
- `,
46
- );
47
-
48
- expect(violations).toStrictEqual([
49
- {
50
- severity: 'error',
51
- message: 'The attribute name is duplicated',
52
- line: 4,
53
- col: 4,
54
- raw: 'data-Attr',
55
- },
56
- {
57
- severity: 'error',
58
- message: 'The attribute name is duplicated',
59
- line: 5,
60
- col: 4,
61
- raw: 'data-attR',
62
- },
63
- ]);
64
- });
65
-
66
- test('is test 3', async () => {
67
- const { violations } = await mlRuleTest(rule, '<img src="/" SRC="/" >', undefined, false, 'ja');
68
-
69
- expect(violations.map(_ => _.message)).toStrictEqual(['属性名が重複しています']);
70
- });
71
-
72
- test('nodeRules disable', async () => {
73
- const { violations } = await mlRuleTest(rule, '<div><span attr attr></span></div>', {
74
- nodeRule: [
75
- {
76
- selector: 'span',
77
- rule: false,
78
- },
79
- ],
80
- });
81
-
82
- expect(violations.length).toStrictEqual(0);
83
- });
84
-
85
- test('Vue', async () => {
86
- const { violations } = await mlRuleTest(rule, '<template><div attr v-bind:attr /></template>', {
87
- parser: {
88
- '.*': '@markuplint/vue-parser',
89
- },
90
- });
91
-
92
- expect(violations).toStrictEqual([
93
- {
94
- severity: 'error',
95
- line: 1,
96
- col: 21,
97
- message: 'The attribute name is duplicated',
98
- raw: 'v-bind:attr',
99
- },
100
- ]);
101
- });
102
-
103
- test('Vue (exception)', async () => {
104
- const { violations } = await mlRuleTest(
105
- rule,
106
- '<template><div class="foo" v-bind:class="bar" style="a: b;" :style="{c: d}" /></template>',
107
- {
108
- parser: {
109
- '.*': '@markuplint/vue-parser',
110
- },
111
- },
112
- );
113
-
114
- expect(violations.length).toBe(0);
115
- });
116
-
117
- test('React', async () => {
118
- const { violations } = await mlRuleTest(rule, '<div tabindex tabIndex />', {
119
- parser: {
120
- '.*': '@markuplint/vue-parser',
121
- },
122
- });
123
-
124
- expect(violations).toStrictEqual([]);
125
- });
126
-
127
- test('Pug', async () => {
128
- const { violations } = await mlRuleTest(rule, '.hoge(class="hoge2")&attributes({class: "hoge3"})', {
129
- parser: {
130
- '.*': '@markuplint/pug-parser',
131
- },
132
- });
133
-
134
- expect(violations.length).toBe(0);
135
- });
136
-
137
- test('Svelte', async () => {
138
- const { violations } = await mlRuleTest(
139
- rule,
140
- '<div class:selected="{isSelected}" class:focused="{isFocused}"></div>',
141
- {
142
- parser: {
143
- '.*': '@markuplint/svelte-parser',
144
- },
145
- },
146
- );
147
-
148
- expect(violations.length).toBe(0);
149
- });
150
-
151
- test('Astro', async () => {
152
- const { violations } = await mlRuleTest(rule, '<div class:list="a" class="b"></div>', {
153
- parser: {
154
- '.*': '@markuplint/astro-parser',
155
- },
156
- });
157
-
158
- expect(violations.length).toBe(1);
159
- });
@@ -1,133 +0,0 @@
1
- const { mlRuleTest } = require('markuplint');
2
-
3
- const rule = require('../../lib/attr-value-quotes').default;
4
-
5
- describe('verify', () => {
6
- test('default', async () => {
7
- const { violations } = await mlRuleTest(
8
- rule,
9
- `
10
- <div data-attr="value" data-Attr='db' data-attR=tr>
11
- lorem
12
- <p>ipsam</p>
13
- </div>
14
- `,
15
- );
16
- expect(violations).toStrictEqual([
17
- {
18
- severity: 'warning',
19
- message: 'Attribute value is must quote on double quotation mark',
20
- line: 2,
21
- col: 26,
22
- raw: "data-Attr='db'",
23
- },
24
- {
25
- severity: 'warning',
26
- message: 'Attribute value is must quote on double quotation mark',
27
- line: 2,
28
- col: 41,
29
- raw: 'data-attR=tr',
30
- },
31
- ]);
32
- });
33
-
34
- test('double', async () => {
35
- const { violations } = await mlRuleTest(
36
- rule,
37
- `
38
- <div data-attr="value" data-Attr='db' data-attR=tr>
39
- lorem
40
- <p>ipsam</p>
41
- </div>
42
- `,
43
- {
44
- rule: {
45
- severity: 'error',
46
- value: 'double',
47
- options: null,
48
- },
49
- },
50
- );
51
- expect(violations).toStrictEqual([
52
- {
53
- severity: 'error',
54
- message: 'Attribute value is must quote on double quotation mark',
55
- line: 2,
56
- col: 26,
57
- raw: "data-Attr='db'",
58
- },
59
- {
60
- severity: 'error',
61
- message: 'Attribute value is must quote on double quotation mark',
62
- line: 2,
63
- col: 41,
64
- raw: 'data-attR=tr',
65
- },
66
- ]);
67
- });
68
-
69
- test('single', async () => {
70
- const { violations } = await mlRuleTest(
71
- rule,
72
- `
73
- <div data-attr="value" data-Attr='db' data-attR=tr>
74
- lorem
75
- <p>ipsam</p>
76
- </div>
77
- `,
78
- {
79
- rule: {
80
- severity: 'error',
81
- value: 'single',
82
- options: null,
83
- },
84
- },
85
- );
86
- expect(violations).toStrictEqual([
87
- {
88
- severity: 'error',
89
- message: 'Attribute value is must quote on single quotation mark',
90
- line: 2,
91
- col: 8,
92
- raw: 'data-attr="value"',
93
- },
94
- {
95
- severity: 'error',
96
- message: 'Attribute value is must quote on single quotation mark',
97
- line: 2,
98
- col: 41,
99
- raw: 'data-attR=tr',
100
- },
101
- ]);
102
- });
103
-
104
- test('empty', async () => {
105
- const { violations } = await mlRuleTest(
106
- rule,
107
- `
108
- <div data-attr>
109
- lorem
110
- <p>ipsam</p>
111
- </div>
112
- `,
113
- );
114
- expect(violations.length).toBe(0);
115
- });
116
- });
117
-
118
- // describe('fix', () => {
119
- // test('empty', async () => {
120
- // const { fixedCode } = await mlRuleTest(rule, '<div attr noop=noop foo="bar" hoge=\'fuga\'>', undefined, true);
121
- // expect(fixedCode).toEqual('<div attr noop="noop" foo="bar" hoge="fuga">');
122
- // });
123
-
124
- // test('empty', async () => {
125
- // const { fixedCode } = await mlRuleTest(
126
- // rule,
127
- // '<div attr noop=noop foo="bar" hoge=\'fuga\'>',
128
- // { rule: 'single' },
129
- // true,
130
- // );
131
- // expect(fixedCode).toEqual("<div attr noop='noop' foo='bar' hoge='fuga'>");
132
- // });
133
- // });
@@ -1,65 +0,0 @@
1
- const { mlRuleTest } = require('markuplint');
2
-
3
- const rule = require('../../lib/case-sensitive-attr-name').default;
4
-
5
- describe('verify', () => {
6
- test('lower case', async () => {
7
- const { violations } = await mlRuleTest(rule, '<div data-lowercase></div>');
8
- expect(violations).toStrictEqual([]);
9
- });
10
-
11
- test('upper case', async () => {
12
- const { violations } = await mlRuleTest(rule, '<div data-UPPERCASE="value"></div>');
13
- expect(violations[0].severity).toBe('warning');
14
- expect(violations[0].message).toBe('Attribute names of HTML elements should be lowercase');
15
- expect(violations[0].raw).toBe('data-UPPERCASE');
16
- });
17
-
18
- test('upper case', async () => {
19
- const { violations } = await mlRuleTest(rule, '<div data-UPPERCASE="value"></div>', {
20
- rule: {
21
- severity: 'error',
22
- value: 'upper',
23
- options: null,
24
- },
25
- });
26
- expect(violations[0].severity).toBe('error');
27
- expect(violations[0].message).toBe('Attribute names of HTML elements must be uppercase');
28
- });
29
-
30
- test('upper case', async () => {
31
- const { violations } = await mlRuleTest(rule, '<div data-uppercase="value"></div>', {
32
- rule: {
33
- severity: 'error',
34
- value: 'upper',
35
- options: null,
36
- },
37
- });
38
- expect(violations[0].severity).toBe('error');
39
- expect(violations[0].message).toBe('Attribute names of HTML elements must be uppercase');
40
- });
41
-
42
- test('upper case', async () => {
43
- const { violations } = await mlRuleTest(rule, '<div DATA-UPPERCASE="value"></div>', {
44
- rule: { severity: 'error', value: 'upper' },
45
- });
46
- expect(violations.length).toBe(0);
47
- });
48
-
49
- test('svg', async () => {
50
- const { violations } = await mlRuleTest(rule, '<svg viewBox="0 0 100 100"></svg>');
51
- expect(violations.length).toBe(0);
52
- });
53
- });
54
-
55
- // describe('fix', () => {
56
- // test('upper case', async () => {
57
- // const { fixedCode } = await mlRuleTest(rule, '<DIV DATA-LOWERCASE></DIV>', undefined, true);
58
- // expect(fixedCode).toBe('<DIV data-lowercase></DIV>');
59
- // });
60
-
61
- // test('upper case', async () => {
62
- // const { fixedCode } = await mlRuleTest(rule, '<DIV data-lowercase></DIV>', { rule: 'upper' }, true);
63
- // expect(fixedCode).toBe('<DIV DATA-LOWERCASE></DIV>');
64
- // });
65
- // });