@markuplint/rules 3.3.1 → 3.4.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.
@@ -199,7 +199,7 @@ function __createMessageValueExpected(t, baseTarget, expected, matches) {
199
199
  }
200
200
  exports.__createMessageValueExpected = __createMessageValueExpected;
201
201
  function createExpectedObject(type, matches, t) {
202
- var _a;
202
+ var _a, _b;
203
203
  const expectedObject = [];
204
204
  if ((_a = matches.expects) === null || _a === void 0 ? void 0 : _a.length) {
205
205
  expectedObject.push(...matches.expects.map(expect => {
@@ -221,7 +221,7 @@ function createExpectedObject(type, matches, t) {
221
221
  ? null
222
222
  : 1 < expectedObject.length
223
223
  ? t('either {0}', t(expectedObject))
224
- : expectedObject[0];
224
+ : (_b = expectedObject[0]) !== null && _b !== void 0 ? _b : null;
225
225
  return expects;
226
226
  }
227
227
  function expectValueToWord(t, expect, type) {
@@ -12,6 +12,10 @@ exports.default = (0, ml_core_1.createRule)({
12
12
  const nameList = new Set();
13
13
  let hasDynamicId = false;
14
14
  let hasDynamicName = false;
15
+ const isMutable = document.nodeList.some(node => node.is(node.MARKUPLINT_PREPROCESSOR_BLOCK));
16
+ if (isMutable) {
17
+ return;
18
+ }
15
19
  document.querySelectorAll('[id]').forEach(el => {
16
20
  const attr = el.getAttributeNode('id');
17
21
  if (!attr) {
@@ -143,6 +143,7 @@ function countPattern(pattern, elements, specs, options, depth) {
143
143
  exports.countPattern = countPattern;
144
144
  const cLog = debug_1.cmLog.extend('countCompereResult');
145
145
  function compereResult(a, b) {
146
+ var _a;
146
147
  cLog('current: %s %O\nbarely: %s %O', a.type, a.hint, b === null || b === void 0 ? void 0 : b.type, b === null || b === void 0 ? void 0 : b.hint);
147
148
  if (b == null) {
148
149
  return a;
@@ -150,6 +151,6 @@ function compereResult(a, b) {
150
151
  if (a.type === 'MATCHED' || a.type === 'MATCHED_ZERO' || a.type === 'UNEXPECTED_EXTRA_NODE') {
151
152
  return a;
152
153
  }
153
- const result = [a, b].sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.hint.missing) === null || _a === void 0 ? void 0 : _a.barelyMatchedElements) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.hint.missing) === null || _c === void 0 ? void 0 : _c.barelyMatchedElements) !== null && _d !== void 0 ? _d : 0); })[0];
154
+ const result = (_a = [a, b].sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.hint.missing) === null || _a === void 0 ? void 0 : _a.barelyMatchedElements) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.hint.missing) === null || _c === void 0 ? void 0 : _c.barelyMatchedElements) !== null && _d !== void 0 ? _d : 0); })[0]) !== null && _a !== void 0 ? _a : a;
154
155
  return result;
155
156
  }
@@ -27,7 +27,7 @@ function order(contents, nodes, specs, options, depth) {
27
27
  let backtrackMode = false;
28
28
  let afterBacktrack = false;
29
29
  const unmatchedResults = [];
30
- while (patterns.length) {
30
+ while (patterns.length && patterns[0]) {
31
31
  result = (0, complex_branch_1.complexBranch)(patterns[0], collection.unmatched, specs, options, depth);
32
32
  collection.addMatched(result.matched);
33
33
  if (result.type !== 'UNEXPECTED_EXTRA_NODE' && result.type !== 'MATCHED' && result.type !== 'MATCHED_ZERO') {
@@ -4,8 +4,8 @@ exports.transparent = void 0;
4
4
  const debug_1 = require("./debug");
5
5
  const transparentLog = debug_1.cmLog.extend('transparent');
6
6
  function transparent(nodes, specs, options, depth) {
7
- var _a;
8
- if (nodes.length === 0 || ((_a = nodes[0].parentElement) === null || _a === void 0 ? void 0 : _a.parentElement)) {
7
+ var _a, _b;
8
+ if (nodes.length === 0 || ((_b = (_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.parentElement)) {
9
9
  transparentLog('Skipped');
10
10
  return {
11
11
  type: nodes.length === 0 ? 'MATCHED_ZERO' : 'MATCHED',
@@ -268,7 +268,7 @@ function modelLog(model, repeat) {
268
268
  }
269
269
  exports.modelLog = modelLog;
270
270
  function orderLog(order, repeat) {
271
- return order.length === 1
271
+ return order.length === 1 && order[0]
272
272
  ? markRepeat(patternLog(order[0]), repeat)
273
273
  : markRepeat(order.map(pattern => patternLog(pattern)).join(''), repeat);
274
274
  }
@@ -98,13 +98,15 @@ function toDatetimeString(date) {
98
98
  }
99
99
  function parseTryMultipleLangs(content, langs, base) {
100
100
  for (const lang of langs) {
101
- // eslint-disable-next-line import/namespace
102
101
  const results = chrono[lang].casual.parse(content, base);
103
102
  // Is not multiple datetime contents
104
103
  if (results.length < 1) {
105
104
  continue;
106
105
  }
107
106
  const result = results[0];
107
+ if (!result) {
108
+ continue;
109
+ }
108
110
  // Is not a range or period
109
111
  if (result.end) {
110
112
  continue;
@@ -6,6 +6,7 @@ exports.default = (0, ml_core_1.createRule)({
6
6
  defaultValue: [],
7
7
  async verify({ document, report, t }) {
8
8
  await document.walkOn('Element', el => {
9
+ var _a;
9
10
  if (el.hasSpreadAttr) {
10
11
  return;
11
12
  }
@@ -71,17 +72,19 @@ exports.default = (0, ml_core_1.createRule)({
71
72
  const expects = spec.values.length === 1 ? t(spec.values) : t('either {0}', t(spec.values));
72
73
  const message = t('{0} expects {1}', t('the "{0*}" {1}', spec.name, 'attribute'), expects);
73
74
  const attrToken = el.getAttributeToken(spec.name);
74
- const valueToken = attrToken[0].valueNode;
75
+ const valueToken = (_a = attrToken[0]) === null || _a === void 0 ? void 0 : _a.valueNode;
75
76
  const token = valueToken || attrToken[0];
76
- report({
77
- scope: {
78
- rule: el.rule,
79
- raw: token.raw,
80
- startCol: token.startCol,
81
- startLine: token.startLine,
82
- },
83
- message,
84
- });
77
+ if (token) {
78
+ report({
79
+ scope: {
80
+ rule: el.rule,
81
+ raw: token.raw,
82
+ startCol: token.startCol,
83
+ startLine: token.startLine,
84
+ },
85
+ message,
86
+ });
87
+ }
85
88
  }
86
89
  }
87
90
  }
@@ -7,6 +7,7 @@ exports.default = (0, ml_core_1.createRule)({
7
7
  ignoreHasMutableContents: true,
8
8
  },
9
9
  async verify({ document, report, t }) {
10
+ var _a, _b;
10
11
  const hasMutableContent = document.nodeList.some(n => n.is(n.ELEMENT_NODE) && n.hasMutableChildren());
11
12
  if (!hasMutableContent) {
12
13
  for (const query of document.rule.value) {
@@ -17,7 +18,7 @@ exports.default = (0, ml_core_1.createRule)({
17
18
  message,
18
19
  line: 1,
19
20
  col: 1,
20
- raw: document.nodeList[0].raw.slice(0, 1),
21
+ raw: (_b = (_a = document.nodeList[0]) === null || _a === void 0 ? void 0 : _a.raw.slice(0, 1)) !== null && _b !== void 0 ? _b : '',
21
22
  });
22
23
  }
23
24
  }
@@ -7,6 +7,7 @@ exports.default = (0, ml_core_1.createRule)({
7
7
  'in-document-fragment': false,
8
8
  },
9
9
  async verify({ document, report, t }) {
10
+ var _a, _b;
10
11
  const h1Stack = [];
11
12
  if (document.nodeList.length === 0) {
12
13
  return;
@@ -25,10 +26,10 @@ exports.default = (0, ml_core_1.createRule)({
25
26
  message,
26
27
  line: 1,
27
28
  col: 1,
28
- raw: document.nodeList[0].raw.slice(0, 1),
29
+ raw: (_b = (_a = document.nodeList[0]) === null || _a === void 0 ? void 0 : _a.raw.slice(0, 1)) !== null && _b !== void 0 ? _b : '',
29
30
  });
30
31
  }
31
- else if (document.rule.options['expected-once'] && h1Stack.length > 1) {
32
+ else if (document.rule.options['expected-once'] && h1Stack.length > 1 && h1Stack[1]) {
32
33
  const message = t('{0} is {1:c}', t('the "{0*}" {1}', 'h1', 'element'), 'duplicated');
33
34
  report({
34
35
  message,
@@ -78,15 +78,16 @@ exports.default = (0, ml_core_1.createRule)({
78
78
  },
79
79
  });
80
80
  function isMayListItem(text, bullets, spaceNeededBullets) {
81
+ var _a;
81
82
  const textArray = Array.from(text);
82
- const firstLetter = textArray[0];
83
+ const firstLetter = (_a = textArray[0]) !== null && _a !== void 0 ? _a : '';
83
84
  const isBullet = bullets.includes(firstLetter);
84
85
  const needSpace = spaceNeededBullets.includes(firstLetter);
85
86
  const continuous = firstLetter === textArray[1];
86
87
  if (continuous) {
87
88
  return false;
88
89
  }
89
- if (isBullet && needSpace) {
90
+ if (isBullet && needSpace && text[1]) {
90
91
  const secondLetter = text[1];
91
92
  const isSpace = /^\s$/.test(secondLetter);
92
93
  return isSpace;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkingDisallowedProp = void 0;
4
+ const ml_spec_1 = require("@markuplint/ml-spec");
4
5
  const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
5
- var _a;
6
+ var _a, _b, _c, _d;
6
7
  if (!role) {
7
8
  return;
8
9
  }
@@ -10,13 +11,36 @@ const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
10
11
  return;
11
12
  }
12
13
  const statesAndProp = role.ownedProperties.find(p => p.name === attr.name);
14
+ const propSpec = propSpecs.find(p => p.name === attr.name);
15
+ const elAriaSpec = (0, ml_spec_1.getARIA)(attr.ownerMLDocument.specs, attr.ownerElement.localName, attr.ownerElement.namespaceURI, attr.rule.options.version, attr.ownerElement.matches.bind(attr.ownerElement));
16
+ if ((elAriaSpec === null || elAriaSpec === void 0 ? void 0 : elAriaSpec.properties) && ((_a = elAriaSpec === null || elAriaSpec === void 0 ? void 0 : elAriaSpec.properties) === null || _a === void 0 ? void 0 : _a.without)) {
17
+ for (const ignore of elAriaSpec.properties.without) {
18
+ if (ignore.name === attr.name) {
19
+ return {
20
+ scope: attr,
21
+ message: t('{0:c} on {1}', t(ignore.type === 'must-not'
22
+ ? '{0} must not {1}'
23
+ : ignore.type === 'should-not'
24
+ ? '{0} should not {1}'
25
+ : '{0} is not recommended to {1}',
26
+ // {0}
27
+ t('the "{0*}" {1}', attr.name, `ARIA ${(_b = propSpec === null || propSpec === void 0 ? void 0 : propSpec.type) !== null && _b !== void 0 ? _b : 'property'}`),
28
+ // {1}
29
+ 'use'), t('the "{0*}" {1}', attr.ownerElement.localName, 'element')) +
30
+ (ignore.alt
31
+ ? t('. ') +
32
+ t('{0} if you {1} {2}', t(ignore.alt.method === 'remove-attr' ? 'Remove {0}' : 'Add {0}', t('the "{0*}" {1}', ignore.alt.target, 'attribute')), 'use', t('the {0}', `ARIA ${(_c = propSpec === null || propSpec === void 0 ? void 0 : propSpec.type) !== null && _c !== void 0 ? _c : 'property'}`))
33
+ : ''),
34
+ };
35
+ }
36
+ }
37
+ }
13
38
  if (statesAndProp) {
14
39
  return;
15
40
  }
16
- const propSpec = propSpecs.find(p => p.name === attr.name);
17
41
  return {
18
42
  scope: attr,
19
- message: t('{0:c} on {1}', t('{0} is {1:c}', t('the "{0*}" {1}', attr.name, `ARIA ${(_a = propSpec === null || propSpec === void 0 ? void 0 : propSpec.type) !== null && _a !== void 0 ? _a : 'property'}`), 'disallowed'), t('the "{0*}" {1}', role.name, 'role')),
43
+ message: t('{0:c} on {1}', t('{0} is {1:c}', t('the "{0*}" {1}', attr.name, `ARIA ${(_d = propSpec === null || propSpec === void 0 ? void 0 : propSpec.type) !== null && _d !== void 0 ? _d : 'property'}`), 'disallowed'), t('the "{0*}" {1}', role.name, 'role')),
20
44
  };
21
45
  };
22
46
  exports.checkingDisallowedProp = checkingDisallowedProp;
@@ -78,14 +78,14 @@ const checkingRequiredOwnedElements = ({ el, role }) => t => {
78
78
  if (mayBeBeforeCreated(el)) {
79
79
  return {
80
80
  scope: el,
81
- message: t('{0}. Or, {1}', t('require {0}', role.requiredOwnedElements.length === 1
81
+ message: t('{0}. Or, {1}', t('require {0}', role.requiredOwnedElements.length === 1 && role.requiredOwnedElements[0]
82
82
  ? t('the "{0*}" {1}', role.requiredOwnedElements[0], 'role')
83
83
  : t('the {0}', 'roles') + `: ${t(role.requiredOwnedElements)}`), t('require {0}', 'aria-busy="true"')),
84
84
  };
85
85
  }
86
86
  return {
87
87
  scope: el,
88
- message: t('{0} expects {1}', t('the "{0*}" {1}', role.name, 'role'), role.requiredOwnedElements.length === 1
88
+ message: t('{0} expects {1}', t('the "{0*}" {1}', role.name, 'role'), role.requiredOwnedElements.length === 1 && role.requiredOwnedElements[0]
89
89
  ? t('the "{0*}" {1}', role.requiredOwnedElements[0], 'role')
90
90
  : t('the {0}', 'roles') + `: ${t(role.requiredOwnedElements)}`),
91
91
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/rules",
3
- "version": "3.3.1",
3
+ "version": "3.4.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,11 +20,11 @@
20
20
  "./lib/permitted-contents/debug.js": "./lib/permitted-contents/debug.browser.js"
21
21
  },
22
22
  "dependencies": {
23
- "@markuplint/html-spec": "3.3.1",
24
- "@markuplint/ml-core": "3.3.1",
25
- "@markuplint/ml-spec": "3.3.0",
26
- "@markuplint/selector": "3.3.0",
27
- "@markuplint/types": "3.2.0",
23
+ "@markuplint/html-spec": "3.4.0",
24
+ "@markuplint/ml-core": "3.4.0",
25
+ "@markuplint/ml-spec": "3.4.0",
26
+ "@markuplint/selector": "3.4.0",
27
+ "@markuplint/types": "3.3.0",
28
28
  "@ungap/structured-clone": "^1.0.1",
29
29
  "ansi-colors": "^4.1.3",
30
30
  "chrono-node": "^2.5.0",
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@types/debug": "^4.1.7"
37
37
  },
38
- "gitHead": "f19e7de726cf01d53342bc5513c30da75d28da63"
38
+ "gitHead": "a83e0f5f214a9bbcc0286b9e269074ddca6189e7"
39
39
  }