@markuplint/rules 3.15.0 → 4.0.0-alpha.10
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.
- package/.eslintrc +5 -0
- package/LICENSE +1 -1
- package/lib/attr-check.d.ts +8 -19
- package/lib/attr-check.js +16 -21
- package/lib/attr-duplication/index.d.ts +1 -3
- package/lib/attr-duplication/index.js +6 -6
- package/lib/attr-value-quotes/index.d.ts +2 -2
- package/lib/attr-value-quotes/index.js +8 -10
- package/lib/case-sensitive-attr-name/index.d.ts +1 -1
- package/lib/case-sensitive-attr-name/index.js +12 -13
- package/lib/case-sensitive-tag-name/index.d.ts +1 -1
- package/lib/case-sensitive-tag-name/index.js +5 -4
- package/lib/character-reference/index.d.ts +1 -1
- package/lib/character-reference/index.js +13 -12
- package/lib/class-naming/index.d.ts +1 -1
- package/lib/class-naming/index.js +14 -13
- package/lib/create-message.d.ts +2 -12
- package/lib/create-message.js +26 -26
- package/lib/debug.js +2 -6
- package/lib/deprecated-attr/index.d.ts +1 -3
- package/lib/deprecated-attr/index.js +9 -9
- package/lib/deprecated-element/index.d.ts +1 -3
- package/lib/deprecated-element/index.js +7 -6
- package/lib/disallowed-element/index.d.ts +1 -1
- package/lib/disallowed-element/index.js +9 -8
- package/lib/doctype/index.d.ts +2 -2
- package/lib/doctype/index.js +5 -4
- package/lib/end-tag/index.d.ts +1 -1
- package/lib/end-tag/index.js +8 -8
- package/lib/helpers.d.ts +17 -35
- package/lib/helpers.js +25 -32
- package/lib/id-duplication/index.d.ts +1 -3
- package/lib/id-duplication/index.js +5 -4
- package/lib/index.d.ts +21 -17
- package/lib/index.js +63 -66
- package/lib/ineffective-attr/index.d.ts +1 -3
- package/lib/ineffective-attr/index.js +8 -7
- package/lib/invalid-attr/index.d.ts +31 -38
- package/lib/invalid-attr/index.js +33 -33
- package/lib/label-has-control/index.d.ts +1 -3
- package/lib/label-has-control/index.js +5 -4
- package/lib/landmark-roles/index.d.ts +3 -3
- package/lib/landmark-roles/index.js +16 -18
- package/lib/no-boolean-attr-value/index.d.ts +1 -3
- package/lib/no-boolean-attr-value/index.js +9 -9
- package/lib/no-default-value/index.d.ts +1 -3
- package/lib/no-default-value/index.js +12 -12
- package/lib/no-empty-palpable-content/index.d.ts +3 -3
- package/lib/no-empty-palpable-content/index.js +9 -8
- package/lib/no-hard-code-id/index.d.ts +1 -3
- package/lib/no-hard-code-id/index.js +5 -4
- package/lib/no-refer-to-non-existent-id/index.d.ts +1 -1
- package/lib/no-refer-to-non-existent-id/index.js +37 -38
- package/lib/no-use-event-handler-attr/index.d.ts +2 -2
- package/lib/no-use-event-handler-attr/index.js +7 -6
- package/lib/permitted-contents/choice.d.ts +2 -8
- package/lib/permitted-contents/choice.js +14 -19
- package/lib/permitted-contents/complex-branch.d.ts +2 -8
- package/lib/permitted-contents/complex-branch.js +10 -14
- package/lib/permitted-contents/content-model.d.ts +1 -1
- package/lib/permitted-contents/content-model.js +10 -11
- package/lib/permitted-contents/count-pattern.d.ts +3 -18
- package/lib/permitted-contents/count-pattern.js +19 -24
- package/lib/permitted-contents/debug.browser.d.ts +16 -16
- package/lib/permitted-contents/debug.browser.js +9 -12
- package/lib/permitted-contents/debug.d.ts +10 -3
- package/lib/permitted-contents/debug.js +12 -13
- package/lib/permitted-contents/index.d.ts +2 -2
- package/lib/permitted-contents/index.js +13 -13
- package/lib/permitted-contents/matches-selector.d.ts +2 -7
- package/lib/permitted-contents/matches-selector.js +13 -18
- package/lib/permitted-contents/order.d.ts +2 -8
- package/lib/permitted-contents/order.js +19 -24
- package/lib/permitted-contents/recursive-branch.d.ts +3 -9
- package/lib/permitted-contents/recursive-branch.js +9 -13
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +4 -8
- package/lib/permitted-contents/represent-transparent-nodes.js +15 -20
- package/lib/permitted-contents/start.d.ts +2 -7
- package/lib/permitted-contents/start.js +13 -21
- package/lib/permitted-contents/transparent.d.ts +1 -1
- package/lib/permitted-contents/transparent.js +6 -11
- package/lib/permitted-contents/types.d.ts +29 -29
- package/lib/permitted-contents/types.js +1 -2
- package/lib/permitted-contents/utils.d.ts +42 -79
- package/lib/permitted-contents/utils.js +72 -82
- package/lib/placeholder-label-option/index.d.ts +1 -1
- package/lib/placeholder-label-option/index.js +12 -13
- package/lib/require-accessible-name/index.d.ts +2 -2
- package/lib/require-accessible-name/index.js +12 -15
- package/lib/require-datetime/index.d.ts +3 -3
- package/lib/require-datetime/index.js +14 -13
- package/lib/require-datetime/types.d.ts +2 -2
- package/lib/require-datetime/types.js +1 -2
- package/lib/require-datetime/utils.d.ts +1 -1
- package/lib/require-datetime/utils.js +5 -12
- package/lib/required-attr/index.d.ts +3 -3
- package/lib/required-attr/index.js +11 -11
- package/lib/required-element/index.d.ts +2 -2
- package/lib/required-element/index.js +7 -7
- package/lib/required-h1/index.d.ts +3 -3
- package/lib/required-h1/index.js +6 -6
- package/lib/use-list/index.d.ts +6 -2
- package/lib/use-list/index.js +27 -11
- package/lib/wai-aria/checkings/abstract-role.d.ts +1 -1
- package/lib/wai-aria/checkings/abstract-role.js +5 -10
- package/lib/wai-aria/checkings/default-value.d.ts +4 -8
- package/lib/wai-aria/checkings/default-value.js +2 -6
- package/lib/wai-aria/checkings/deprecated-props.d.ts +5 -9
- package/lib/wai-aria/checkings/deprecated-props.js +3 -8
- package/lib/wai-aria/checkings/disallowed-prop.d.ts +5 -9
- package/lib/wai-aria/checkings/disallowed-prop.js +7 -12
- package/lib/wai-aria/checkings/implicit-props.d.ts +5 -9
- package/lib/wai-aria/checkings/implicit-props.js +12 -17
- package/lib/wai-aria/checkings/implicit-role.d.ts +1 -1
- package/lib/wai-aria/checkings/implicit-role.js +4 -9
- package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +1 -1
- package/lib/wai-aria/checkings/interaction-in-hidden.js +4 -8
- package/lib/wai-aria/checkings/no-global-prop.d.ts +4 -8
- package/lib/wai-aria/checkings/no-global-prop.js +2 -7
- package/lib/wai-aria/checkings/non-existent-role.d.ts +1 -1
- package/lib/wai-aria/checkings/non-existent-role.js +4 -9
- package/lib/wai-aria/checkings/permitted-roles.d.ts +1 -1
- package/lib/wai-aria/checkings/permitted-roles.js +4 -9
- package/lib/wai-aria/checkings/presentational-children.d.ts +1 -1
- package/lib/wai-aria/checkings/presentational-children.js +5 -10
- package/lib/wai-aria/checkings/required-owned-elements.d.ts +4 -8
- package/lib/wai-aria/checkings/required-owned-elements.js +7 -11
- package/lib/wai-aria/checkings/required-prop.d.ts +7 -13
- package/lib/wai-aria/checkings/required-prop.js +2 -7
- package/lib/wai-aria/checkings/value.d.ts +7 -16
- package/lib/wai-aria/checkings/value.js +7 -13
- package/lib/wai-aria/index.d.ts +2 -2
- package/lib/wai-aria/index.js +41 -40
- package/lib/wai-aria/types.d.ts +10 -10
- package/lib/wai-aria/types.js +1 -2
- package/package.json +17 -13
- package/test/attr-check.spec.js +0 -77
- package/test/attr-duplication/index.spec.js +0 -159
- package/test/attr-value-quotes/index.spec.js +0 -133
- package/test/case-sensitive-attr-name/index.spec.js +0 -65
- package/test/case-sensitive-tag-name/index.spec.js +0 -80
- package/test/character-reference/index.spec.js +0 -72
- package/test/class-naming/index.spec.js +0 -470
- package/test/create-message.spec.js +0 -497
- package/test/deprecated-attr/index.spec.js +0 -48
- package/test/deprecated-element/index.spec.js +0 -35
- package/test/disallowed-element/index.spec.js +0 -90
- package/test/doctype/index.spec.js +0 -50
- package/test/end-tag/index.spec.js +0 -162
- package/test/id-duplication/index.spec.js +0 -47
- package/test/ineffective-attr/index.spec.js +0 -31
- package/test/invalid-attr/index.spec.js +0 -1631
- package/test/label-has-control/index.spec.js +0 -29
- package/test/landmark-roles/index.spec.js +0 -187
- package/test/no-boolean-attr-value/index.spec.js +0 -41
- package/test/no-default-value/index.spec.js +0 -74
- package/test/no-empty-palpable-content/index.spec.js +0 -115
- package/test/no-hard-code-id/index.spec.js +0 -100
- package/test/no-refer-to-non-existent-id/index.spec.js +0 -254
- package/test/no-use-event-handler-attr/index.spec.js +0 -57
- package/test/permitted-contents/choice.spec.js +0 -174
- package/test/permitted-contents/count-pattern.spec.js +0 -308
- package/test/permitted-contents/index.spec.js +0 -1395
- package/test/permitted-contents/matches-selector.spec.js +0 -59
- package/test/permitted-contents/order.spec.js +0 -351
- package/test/permitted-contents/recursive-branch.spec.js +0 -41
- package/test/permitted-contents/represent-transparent-nodes.spec.js +0 -24
- package/test/permitted-contents/start.spec.js +0 -67
- package/test/placeholder-label-option/index.spec.js +0 -113
- package/test/require-accessible-name/index.spec.js +0 -444
- package/test/require-datetime/index.spec.js +0 -54
- package/test/require-datetime/utils.spec.js +0 -52
- package/test/required-attr/index.spec.js +0 -414
- package/test/required-element/index.spec.js +0 -188
- package/test/required-h1/index.spec.js +0 -69
- package/test/use-list/index.spec.js +0 -109
- package/test/wai-aria/checkings/value.spec.js +0 -33
- package/test/wai-aria/index.spec.js +0 -1203
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { createRule, getRoleSpec, getComputedRole } from '@markuplint/ml-core';
|
|
2
|
+
import { ARIA_RECOMMENDED_VERSION, isExposed } from '@markuplint/ml-spec';
|
|
3
|
+
import { accnameMayBeMutable } from '../helpers.js';
|
|
4
|
+
export default createRule({
|
|
5
|
+
meta: {
|
|
6
|
+
category: 'a11y',
|
|
7
|
+
},
|
|
7
8
|
defaultOptions: {
|
|
8
|
-
ariaVersion:
|
|
9
|
+
ariaVersion: ARIA_RECOMMENDED_VERSION,
|
|
9
10
|
},
|
|
10
11
|
async verify({ document, report, t }) {
|
|
11
12
|
await document.walkOn('Element', el => {
|
|
12
|
-
|
|
13
|
-
if (((_a = el.pretenderContext) === null || _a === void 0 ? void 0 : _a.type) === 'pretender') {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if ((0, helpers_1.accnameMayBeMutable)(el, document)) {
|
|
13
|
+
if (accnameMayBeMutable(el, document)) {
|
|
17
14
|
return;
|
|
18
15
|
}
|
|
19
|
-
if (!
|
|
16
|
+
if (!isExposed(el, document.specs, el.rule.options.ariaVersion)) {
|
|
20
17
|
return;
|
|
21
18
|
}
|
|
22
|
-
const computed =
|
|
19
|
+
const computed = getComputedRole(document.specs, el, el.rule.options.ariaVersion);
|
|
23
20
|
if (!computed.role) {
|
|
24
21
|
return;
|
|
25
22
|
}
|
|
26
|
-
const roleSpec =
|
|
23
|
+
const roleSpec = getRoleSpec(document.specs, computed.role.name, el.namespaceURI, el.rule.options.ariaVersion);
|
|
27
24
|
if (!roleSpec || !roleSpec.accessibleNameRequired) {
|
|
28
25
|
return;
|
|
29
26
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Lang } from './types';
|
|
1
|
+
import type { Lang } from './types.js';
|
|
2
2
|
type Options = {
|
|
3
|
-
|
|
3
|
+
langs?: Lang[];
|
|
4
4
|
};
|
|
5
|
-
declare const _default: Readonly<import(
|
|
5
|
+
declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<boolean, Options>>;
|
|
6
6
|
export default _default;
|
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
import { check } from '@markuplint/types';
|
|
3
|
+
import { getCandidateDatetimeString } from './utils.js';
|
|
4
|
+
export default createRule({
|
|
5
|
+
meta: {
|
|
6
|
+
category: 'validation',
|
|
7
|
+
},
|
|
7
8
|
defaultOptions: {
|
|
8
9
|
langs: undefined,
|
|
9
10
|
},
|
|
10
11
|
verify({ document, report, t }) {
|
|
11
|
-
document.querySelectorAll('time:not([datetime])')
|
|
12
|
+
for (const time of document.querySelectorAll('time:not([datetime])')) {
|
|
12
13
|
if (time.hasMutableChildren()) {
|
|
13
|
-
|
|
14
|
+
continue;
|
|
14
15
|
}
|
|
15
16
|
const content = time.textContent.trim();
|
|
16
|
-
const result =
|
|
17
|
+
const result = check(content, 'DateTime');
|
|
17
18
|
if (result.matched) {
|
|
18
|
-
|
|
19
|
+
continue;
|
|
19
20
|
}
|
|
20
|
-
const candidate =
|
|
21
|
+
const candidate = getCandidateDatetimeString(content, time.rule.options.langs);
|
|
21
22
|
if (candidate) {
|
|
22
23
|
report({
|
|
23
24
|
scope: time,
|
|
24
25
|
message: t('need {0*}', `datetime="${candidate}"`),
|
|
25
26
|
});
|
|
26
|
-
|
|
27
|
+
continue;
|
|
27
28
|
}
|
|
28
29
|
report({
|
|
29
30
|
scope: time,
|
|
30
31
|
message: t('need {0}', t('the "{0*}" {1}', 'datetime', 'attribute')),
|
|
31
32
|
});
|
|
32
|
-
}
|
|
33
|
+
}
|
|
33
34
|
},
|
|
34
35
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type DateTimeKey = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'ms';
|
|
2
2
|
export type DateTimeData = Partial<Record<DateTimeKey, number>>;
|
|
3
3
|
export type DateTime = {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
datetime: DateTimeData;
|
|
5
|
+
zone?: number;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* @see https://github.com/wanasit/chrono#locales
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCandidateDatetimeString = exports.parseADatetime = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const chrono = tslib_1.__importStar(require("chrono-node"));
|
|
1
|
+
import * as chrono from 'chrono-node';
|
|
6
2
|
const defaultLangs = ['en', 'ja', 'fr', 'nl', 'ru', 'de', 'pt', 'zh'];
|
|
7
3
|
/**
|
|
8
4
|
* Datetime-ish text to a datetime data
|
|
@@ -12,8 +8,7 @@ const defaultLangs = ['en', 'ja', 'fr', 'nl', 'ru', 'de', 'pt', 'zh'];
|
|
|
12
8
|
* @param base Reference date for a test
|
|
13
9
|
* @returns
|
|
14
10
|
*/
|
|
15
|
-
function parseADatetime(content, langs, base) {
|
|
16
|
-
var _a;
|
|
11
|
+
export function parseADatetime(content, langs, base) {
|
|
17
12
|
const date = parseTryMultipleLangs(content, langs, base);
|
|
18
13
|
if (!date) {
|
|
19
14
|
return null;
|
|
@@ -32,7 +27,7 @@ function parseADatetime(content, langs, base) {
|
|
|
32
27
|
data.hour = date.get('hour');
|
|
33
28
|
}
|
|
34
29
|
if (date.isCertain('hour')) {
|
|
35
|
-
data.minute =
|
|
30
|
+
data.minute = date.get('minute') ?? 0;
|
|
36
31
|
}
|
|
37
32
|
if (date.isCertain('second')) {
|
|
38
33
|
data.second = date.get('second');
|
|
@@ -48,8 +43,7 @@ function parseADatetime(content, langs, base) {
|
|
|
48
43
|
}
|
|
49
44
|
return datetime;
|
|
50
45
|
}
|
|
51
|
-
|
|
52
|
-
function getCandidateDatetimeString(content, langs = defaultLangs) {
|
|
46
|
+
export function getCandidateDatetimeString(content, langs = defaultLangs) {
|
|
53
47
|
const date = parseADatetime(content, langs);
|
|
54
48
|
if (!date) {
|
|
55
49
|
return null;
|
|
@@ -66,7 +60,6 @@ function getCandidateDatetimeString(content, langs = defaultLangs) {
|
|
|
66
60
|
}
|
|
67
61
|
return datetimeStr;
|
|
68
62
|
}
|
|
69
|
-
exports.getCandidateDatetimeString = getCandidateDatetimeString;
|
|
70
63
|
function toDatetimeString(date) {
|
|
71
64
|
if (only(date, ['year', 'month'])) {
|
|
72
65
|
return `${f(date.year, 4)}-${f(date.month, 2)}`;
|
|
@@ -101,7 +94,7 @@ function parseTryMultipleLangs(content, langs, base) {
|
|
|
101
94
|
for (const lang of langs) {
|
|
102
95
|
const results = chrono[lang].casual.parse(content, base);
|
|
103
96
|
// Is not multiple datetime contents
|
|
104
|
-
if (results.length
|
|
97
|
+
if (results.length === 0) {
|
|
105
98
|
continue;
|
|
106
99
|
}
|
|
107
100
|
const result = results[0];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
type RequiredAttributes = string | (string | Attr)[];
|
|
2
2
|
type Attr = {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
name: string;
|
|
4
|
+
value?: string | string[];
|
|
5
5
|
};
|
|
6
|
-
declare const _default: Readonly<import(
|
|
6
|
+
declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<RequiredAttributes, undefined>>;
|
|
7
7
|
export default _default;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createRule, getAttrSpecs } from '@markuplint/ml-core';
|
|
2
|
+
import { attrMatches, match } from '../helpers.js';
|
|
3
|
+
export default createRule({
|
|
4
|
+
meta: {
|
|
5
|
+
category: 'validation',
|
|
6
|
+
},
|
|
6
7
|
defaultValue: [],
|
|
7
8
|
async verify({ document, report, t }) {
|
|
8
9
|
await document.walkOn('Element', el => {
|
|
9
|
-
var _a;
|
|
10
10
|
if (el.hasSpreadAttr) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
const customRequiredAttrs = typeof el.rule.value === 'string' ? [el.rule.value] : el.rule.value;
|
|
14
|
-
const attrSpec =
|
|
14
|
+
const attrSpec = getAttrSpecs(el, document.specs);
|
|
15
15
|
const attributeSpecs = {};
|
|
16
16
|
if (attrSpec && el.elementType === 'html') {
|
|
17
17
|
for (const spec of attrSpec) {
|
|
@@ -52,7 +52,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
52
52
|
invalid = !candidate.some(attrName => el.hasAttribute(attrName));
|
|
53
53
|
}
|
|
54
54
|
else if (spec.required === true) {
|
|
55
|
-
invalid =
|
|
55
|
+
invalid = attrMatches(el, spec.condition) && didntHave;
|
|
56
56
|
}
|
|
57
57
|
else if (spec.required != null && spec.required !== false) {
|
|
58
58
|
const selector = typeof spec.required === 'string' ? spec.required : spec.required.join(',');
|
|
@@ -67,13 +67,13 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
67
67
|
}
|
|
68
68
|
const value = el.getAttribute(spec.name);
|
|
69
69
|
if (spec.values.length > 0 && value) {
|
|
70
|
-
const matched = spec.values.some(pattern =>
|
|
70
|
+
const matched = spec.values.some(pattern => match(value, pattern));
|
|
71
71
|
if (!matched) {
|
|
72
72
|
const expects = spec.values.length === 1 ? t(spec.values) : t('either {0}', t(spec.values));
|
|
73
73
|
const message = t('{0} expects {1}', t('the "{0*}" {1}', spec.name, 'attribute'), expects);
|
|
74
74
|
const attrToken = el.getAttributeToken(spec.name);
|
|
75
|
-
const valueToken =
|
|
76
|
-
const token = valueToken
|
|
75
|
+
const valueToken = attrToken[0]?.valueNode;
|
|
76
|
+
const token = valueToken ?? attrToken[0];
|
|
77
77
|
if (token) {
|
|
78
78
|
report({
|
|
79
79
|
scope: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type Options = {
|
|
2
|
-
|
|
2
|
+
ignoreHasMutableContents: boolean;
|
|
3
3
|
};
|
|
4
|
-
declare const _default: Readonly<import(
|
|
4
|
+
declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<string[], Options>>;
|
|
5
5
|
export default _default;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
export default createRule({
|
|
3
|
+
meta: {
|
|
4
|
+
category: 'validation',
|
|
5
|
+
},
|
|
5
6
|
defaultValue: [],
|
|
6
7
|
defaultOptions: {
|
|
7
8
|
ignoreHasMutableContents: true,
|
|
8
9
|
},
|
|
9
10
|
async verify({ document, report, t }) {
|
|
10
|
-
var _a, _b;
|
|
11
11
|
const hasMutableContent = document.nodeList.some(n => n.is(n.ELEMENT_NODE) && n.hasMutableChildren());
|
|
12
12
|
if (!hasMutableContent) {
|
|
13
13
|
for (const query of document.rule.value) {
|
|
@@ -18,7 +18,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
18
18
|
message,
|
|
19
19
|
line: 1,
|
|
20
20
|
col: 1,
|
|
21
|
-
raw:
|
|
21
|
+
raw: document.nodeList[0]?.raw.slice(0, 1) ?? '',
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -31,7 +31,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
for (const query of el.rule.value) {
|
|
34
|
-
const exists =
|
|
34
|
+
const exists = [...el.children].find(child => child.matches(query));
|
|
35
35
|
if (!exists) {
|
|
36
36
|
const message = t('Require {0}', t('the "{0*}" {1}', query, 'element'));
|
|
37
37
|
report({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface Options {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
'expected-once': boolean;
|
|
3
|
+
'in-document-fragment': boolean;
|
|
4
4
|
}
|
|
5
|
-
declare const _default: Readonly<import(
|
|
5
|
+
declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<boolean, Options>>;
|
|
6
6
|
export default _default;
|
package/lib/required-h1/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
export default createRule({
|
|
3
|
+
meta: {
|
|
4
|
+
category: 'a11y',
|
|
5
|
+
},
|
|
5
6
|
defaultOptions: {
|
|
6
7
|
'expected-once': true,
|
|
7
8
|
'in-document-fragment': false,
|
|
8
9
|
},
|
|
9
10
|
async verify({ document, report, t }) {
|
|
10
|
-
var _a, _b;
|
|
11
11
|
const h1Stack = [];
|
|
12
12
|
if (document.nodeList.length === 0) {
|
|
13
13
|
return;
|
|
@@ -26,7 +26,7 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
26
26
|
message,
|
|
27
27
|
line: 1,
|
|
28
28
|
col: 1,
|
|
29
|
-
raw:
|
|
29
|
+
raw: document.nodeList[0]?.raw.slice(0, 1) ?? '',
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
else if (document.rule.options['expected-once'] && h1Stack.length > 1 && h1Stack[1]) {
|
package/lib/use-list/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
type Bullets = readonly string[];
|
|
2
2
|
type Options = {
|
|
3
|
-
|
|
3
|
+
spaceNeededBullets?: string[];
|
|
4
|
+
noPrev?: boolean;
|
|
5
|
+
prevElement?: boolean;
|
|
6
|
+
prevComment?: boolean;
|
|
7
|
+
prevCodeBlock?: boolean;
|
|
4
8
|
};
|
|
5
|
-
declare const _default: Readonly<import(
|
|
9
|
+
declare const _default: Readonly<import("@markuplint/ml-core").RuleSeed<Bullets, Options>>;
|
|
6
10
|
export default _default;
|
package/lib/use-list/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createRule } from '@markuplint/ml-core';
|
|
2
|
+
import { decodeEntities } from '@markuplint/shared';
|
|
3
|
+
export default createRule({
|
|
4
|
+
meta: {
|
|
5
|
+
category: 'a11y',
|
|
6
|
+
},
|
|
6
7
|
defaultValue: [
|
|
7
8
|
/**
|
|
8
9
|
* @see https://en.wikipedia.org/wiki/Bullet_(typography)#In_Unicode
|
|
@@ -53,12 +54,15 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
53
54
|
'*', // asterisks
|
|
54
55
|
'+', // plus signs
|
|
55
56
|
],
|
|
57
|
+
noPrev: true,
|
|
58
|
+
prevElement: true,
|
|
59
|
+
prevComment: true,
|
|
60
|
+
prevCodeBlock: false,
|
|
56
61
|
},
|
|
57
62
|
defaultSeverity: 'warning',
|
|
58
63
|
async verify({ document, report, t }) {
|
|
59
64
|
await document.walkOn('Text', textNode => {
|
|
60
|
-
|
|
61
|
-
const text = (0, shared_1.decodeEntities)(textNode.raw.trim());
|
|
65
|
+
const text = decodeEntities(textNode.raw.trim());
|
|
62
66
|
if (!text) {
|
|
63
67
|
// empty
|
|
64
68
|
return;
|
|
@@ -67,8 +71,21 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
67
71
|
// character only
|
|
68
72
|
return;
|
|
69
73
|
}
|
|
74
|
+
if (textNode.rule.options.noPrev === false && !textNode.prevNode) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (textNode.rule.options.prevElement === false && textNode.prevNode?.is(textNode.ELEMENT_NODE)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (textNode.rule.options.prevComment === false && textNode.prevNode?.is(textNode.COMMENT_NODE)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (textNode.rule.options.prevCodeBlock === false &&
|
|
84
|
+
textNode.prevNode?.is(textNode.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
70
87
|
const bullets = textNode.rule.value;
|
|
71
|
-
const spaceNeededBullets =
|
|
88
|
+
const spaceNeededBullets = textNode.rule.options.spaceNeededBullets ?? [];
|
|
72
89
|
if (isMayListItem(text, bullets, spaceNeededBullets)) {
|
|
73
90
|
report({
|
|
74
91
|
scope: textNode,
|
|
@@ -79,9 +96,8 @@ exports.default = (0, ml_core_1.createRule)({
|
|
|
79
96
|
},
|
|
80
97
|
});
|
|
81
98
|
function isMayListItem(text, bullets, spaceNeededBullets) {
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const firstLetter = (_a = textArray[0]) !== null && _a !== void 0 ? _a : '';
|
|
99
|
+
const textArray = [...text];
|
|
100
|
+
const firstLetter = textArray[0] ?? '';
|
|
85
101
|
const isBullet = bullets.includes(firstLetter);
|
|
86
102
|
const needSpace = spaceNeededBullets.includes(firstLetter);
|
|
87
103
|
const continuous = firstLetter === textArray[1];
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const checkingAbstractRole = ({ attr }) => t => {
|
|
6
|
-
var _a;
|
|
7
|
-
const { roles } = (0, ml_spec_1.ariaSpecs)(attr.ownerMLDocument.specs, attr.rule.options.version);
|
|
8
|
-
const tokens = (_a = attr.tokenList) === null || _a === void 0 ? void 0 : _a.allTokens();
|
|
1
|
+
import { ariaSpecs } from '@markuplint/ml-spec';
|
|
2
|
+
export const checkingAbstractRole = ({ attr }) => t => {
|
|
3
|
+
const { roles } = ariaSpecs(attr.ownerMLDocument.specs, attr.rule.options.version);
|
|
4
|
+
const tokens = attr.tokenList?.allTokens();
|
|
9
5
|
if (!tokens) {
|
|
10
6
|
return;
|
|
11
7
|
}
|
|
12
8
|
for (const token of tokens) {
|
|
13
9
|
const role = roles.find(r => r.name === token.raw);
|
|
14
|
-
if (role
|
|
10
|
+
if (role?.isAbstract) {
|
|
15
11
|
return {
|
|
16
12
|
scope: token,
|
|
17
13
|
message: t('{0} is {1}', t('the "{0*}" {1}', token.raw, 'role'), 'the abstract role'),
|
|
@@ -19,4 +15,3 @@ const checkingAbstractRole = ({ attr }) => t => {
|
|
|
19
15
|
}
|
|
20
16
|
}
|
|
21
17
|
};
|
|
22
|
-
exports.checkingAbstractRole = checkingAbstractRole;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import type { Options } from '../types';
|
|
1
|
+
import type { Options } from '../types.js';
|
|
2
2
|
import type { AttrChecker } from '@markuplint/ml-core';
|
|
3
3
|
import type { ARIAProperty } from '@markuplint/ml-spec';
|
|
4
|
-
export declare const checkingDefaultValue: AttrChecker<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
propSpecs: readonly ARIAProperty[];
|
|
9
|
-
}
|
|
10
|
-
>;
|
|
4
|
+
export declare const checkingDefaultValue: AttrChecker<boolean, Options, {
|
|
5
|
+
propSpecs: readonly ARIAProperty[];
|
|
6
|
+
}>;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkingDefaultValue = void 0;
|
|
4
|
-
const checkingDefaultValue = ({ attr, propSpecs }) => t => {
|
|
1
|
+
export const checkingDefaultValue = ({ attr, propSpecs }) => t => {
|
|
5
2
|
if (attr.isDynamicValue) {
|
|
6
3
|
return;
|
|
7
4
|
}
|
|
8
5
|
const propSpec = propSpecs.find(p => p.name === attr.name);
|
|
9
6
|
const value = attr.value.trim().toLowerCase();
|
|
10
|
-
if (
|
|
7
|
+
if (propSpec?.defaultValue != null && propSpec.defaultValue === value) {
|
|
11
8
|
return {
|
|
12
9
|
scope: attr,
|
|
13
10
|
message: t('It is {0}', 'default value'),
|
|
14
11
|
};
|
|
15
12
|
}
|
|
16
13
|
};
|
|
17
|
-
exports.checkingDefaultValue = checkingDefaultValue;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { Options } from '../types';
|
|
1
|
+
import type { Options } from '../types.js';
|
|
2
2
|
import type { AttrChecker } from '@markuplint/ml-core';
|
|
3
3
|
import type { ARIAProperty, ARIARole } from '@markuplint/ml-spec';
|
|
4
|
-
export declare const checkingDeprecatedProps: AttrChecker<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
role: ARIARole | null;
|
|
9
|
-
propSpecs: readonly ARIAProperty[];
|
|
10
|
-
}
|
|
11
|
-
>;
|
|
4
|
+
export declare const checkingDeprecatedProps: AttrChecker<boolean, Options, {
|
|
5
|
+
role: ARIARole | null;
|
|
6
|
+
propSpecs: readonly ARIAProperty[];
|
|
7
|
+
}>;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkingDeprecatedProps = void 0;
|
|
4
|
-
const checkingDeprecatedProps = ({ attr, role, propSpecs }) => t => {
|
|
5
|
-
var _a;
|
|
1
|
+
export const checkingDeprecatedProps = ({ attr, role, propSpecs }) => t => {
|
|
6
2
|
if (!role) {
|
|
7
3
|
return;
|
|
8
4
|
}
|
|
9
5
|
const props = role.ownedProperties.find(p => p.name === attr.name);
|
|
10
|
-
if (props
|
|
6
|
+
if (props?.deprecated) {
|
|
11
7
|
const propSpec = propSpecs.find(p => p.name === attr.name);
|
|
12
8
|
return {
|
|
13
9
|
scope: attr,
|
|
14
|
-
message: t('{0:c} on {1}', t('{0} is {1:c}', t('the "{0*}" {1}', attr.name, `ARIA ${
|
|
10
|
+
message: t('{0:c} on {1}', t('{0} is {1:c}', t('the "{0*}" {1}', attr.name, `ARIA ${propSpec?.type ?? 'property'}`), 'deprecated'), t('the "{0*}" {1}', role.name, 'role')),
|
|
15
11
|
};
|
|
16
12
|
}
|
|
17
13
|
};
|
|
18
|
-
exports.checkingDeprecatedProps = checkingDeprecatedProps;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { Options } from '../types';
|
|
1
|
+
import type { Options } from '../types.js';
|
|
2
2
|
import type { AttrChecker } from '@markuplint/ml-core';
|
|
3
3
|
import type { ARIAProperty, ARIARole } from '@markuplint/ml-spec';
|
|
4
|
-
export declare const checkingDisallowedProp: AttrChecker<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
role: ARIARole | null;
|
|
9
|
-
propSpecs: readonly ARIAProperty[];
|
|
10
|
-
}
|
|
11
|
-
>;
|
|
4
|
+
export declare const checkingDisallowedProp: AttrChecker<boolean, Options, {
|
|
5
|
+
role: ARIARole | null;
|
|
6
|
+
propSpecs: readonly ARIAProperty[];
|
|
7
|
+
}>;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.checkingDisallowedProp = void 0;
|
|
4
|
-
const ml_spec_1 = require("@markuplint/ml-spec");
|
|
5
|
-
const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
|
|
6
|
-
var _a, _b, _c, _d;
|
|
1
|
+
import { getARIA } from '@markuplint/ml-spec';
|
|
2
|
+
export const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
|
|
7
3
|
if (!role) {
|
|
8
4
|
return;
|
|
9
5
|
}
|
|
@@ -12,8 +8,8 @@ const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
|
|
|
12
8
|
}
|
|
13
9
|
const statesAndProp = role.ownedProperties.find(p => p.name === attr.name);
|
|
14
10
|
const propSpec = propSpecs.find(p => p.name === attr.name);
|
|
15
|
-
const elAriaSpec =
|
|
16
|
-
if (
|
|
11
|
+
const elAriaSpec = getARIA(attr.ownerMLDocument.specs, attr.ownerElement.localName, attr.ownerElement.namespaceURI, attr.rule.options.version, attr.ownerElement.matches.bind(attr.ownerElement));
|
|
12
|
+
if (elAriaSpec?.properties !== false && elAriaSpec?.properties?.without) {
|
|
17
13
|
for (const ignore of elAriaSpec.properties.without) {
|
|
18
14
|
if (ignore.name === attr.name) {
|
|
19
15
|
return {
|
|
@@ -24,12 +20,12 @@ const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
|
|
|
24
20
|
? '{0} should not {1}'
|
|
25
21
|
: '{0} is not recommended to {1}',
|
|
26
22
|
// {0}
|
|
27
|
-
t('the "{0*}" {1}', attr.name, `ARIA ${
|
|
23
|
+
t('the "{0*}" {1}', attr.name, `ARIA ${propSpec?.type ?? 'property'}`),
|
|
28
24
|
// {1}
|
|
29
25
|
'use'), t('the "{0*}" {1}', attr.ownerElement.localName, 'element')) +
|
|
30
26
|
(ignore.alt
|
|
31
27
|
? 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 ${
|
|
28
|
+
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 ${propSpec?.type ?? 'property'}`))
|
|
33
29
|
: ''),
|
|
34
30
|
};
|
|
35
31
|
}
|
|
@@ -40,7 +36,6 @@ const checkingDisallowedProp = ({ attr, role, propSpecs }) => t => {
|
|
|
40
36
|
}
|
|
41
37
|
return {
|
|
42
38
|
scope: attr,
|
|
43
|
-
message: t('{0:c} on {1}', t('{0} is {1:c}', t('the "{0*}" {1}', attr.name, `ARIA ${
|
|
39
|
+
message: t('{0:c} on {1}', t('{0} is {1:c}', t('the "{0*}" {1}', attr.name, `ARIA ${propSpec?.type ?? 'property'}`), 'disallowed'), t('the "{0*}" {1}', role.name, 'role')),
|
|
44
40
|
};
|
|
45
41
|
};
|
|
46
|
-
exports.checkingDisallowedProp = checkingDisallowedProp;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { Options } from '../types';
|
|
1
|
+
import type { Options } from '../types.js';
|
|
2
2
|
import type { AttrChecker } from '@markuplint/ml-core';
|
|
3
3
|
import type { ARIAProperty, Attribute } from '@markuplint/ml-spec';
|
|
4
|
-
export declare const checkingImplicitProps: AttrChecker<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
propSpecs: readonly ARIAProperty[];
|
|
9
|
-
attrSpecs: readonly Attribute[] | null;
|
|
10
|
-
}
|
|
11
|
-
>;
|
|
4
|
+
export declare const checkingImplicitProps: AttrChecker<boolean, Options, {
|
|
5
|
+
propSpecs: readonly ARIAProperty[];
|
|
6
|
+
attrSpecs: readonly Attribute[] | null;
|
|
7
|
+
}>;
|