@markuplint/rules 4.10.5 → 4.10.6
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/CHANGELOG.md +6 -0
- package/lib/attr-check.d.ts +4 -3
- package/lib/attr-check.js +10 -19
- package/lib/helpers.d.ts +9 -1
- package/lib/helpers.js +1 -1
- package/lib/invalid-attr/index.js +39 -35
- package/lib/wai-aria/checkings/implicit-props.js +1 -1
- package/package.json +11 -11
- package/lib/__foo/index.d.ts +0 -2
- package/lib/__foo/index.js +0 -31
- package/lib/__foo/meta.d.ts +0 -4
- package/lib/__foo/meta.js +0 -3
- package/lib/permitted-contents/opt-condition.d.ts +0 -8
- package/lib/permitted-contents/opt-condition.js +0 -54
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.10.6](https://github.com/markuplint/markuplint/compare/@markuplint/rules@4.10.5...@markuplint/rules@4.10.6) (2024-11-17)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **rules:** change to spread syntax ([6f2688b](https://github.com/markuplint/markuplint/commit/6f2688bfd4a7f10d63f653d90bbb19463c1066fb))
|
|
11
|
+
|
|
6
12
|
## [4.10.5](https://github.com/markuplint/markuplint/compare/@markuplint/rules@4.10.4...@markuplint/rules@4.10.5) (2024-10-31)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @markuplint/rules
|
package/lib/attr-check.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Translator } from '@markuplint/i18n';
|
|
2
2
|
import type { Attribute as AttrSpec, AttributeType } from '@markuplint/ml-spec';
|
|
3
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
4
|
-
type
|
|
5
|
-
|
|
4
|
+
type InvalidTYpe = 'non-existent' | 'invalid-value' | 'disallowed-attr';
|
|
5
|
+
type Invalid<T extends InvalidTYpe = InvalidTYpe> = {
|
|
6
|
+
invalidType: T;
|
|
6
7
|
message: string;
|
|
7
8
|
loc?: Loc;
|
|
8
9
|
};
|
|
@@ -19,6 +20,6 @@ type Loc = {
|
|
|
19
20
|
* @param isCustomRule
|
|
20
21
|
* @param spec
|
|
21
22
|
*/
|
|
22
|
-
export declare function attrCheck(t: Translator, name: string, value: string, isCustomRule: boolean, spec?: AttrSpec): Invalid | false;
|
|
23
|
+
export declare function attrCheck(t: Translator, name: string, value: string, isCustomRule: boolean, spec?: AttrSpec): Invalid | Invalid<'invalid-value'>[] | false;
|
|
23
24
|
export declare function valueCheck(t: Translator, name: string, value: string, type: ReadonlyDeep<AttributeType>): [string, Loc] | false;
|
|
24
25
|
export {};
|
package/lib/attr-check.js
CHANGED
|
@@ -52,30 +52,21 @@ export function attrCheck(t, name, value, isCustomRule, spec) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
const types = toNonNullableArrayFromItemOrArray(spec.type);
|
|
55
|
-
const
|
|
55
|
+
const invalidMap = new Map();
|
|
56
|
+
for (const type of types) {
|
|
56
57
|
const invalid = valueCheck(t, name, value, type);
|
|
57
58
|
if (invalid === false) {
|
|
58
59
|
return false;
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
invalidType: 'invalid-value',
|
|
69
|
-
message: invalid[0],
|
|
70
|
-
loc: invalid[1],
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
if (invalidList.includes(false)) {
|
|
75
|
-
return false;
|
|
61
|
+
const key = `${invalid[1].line}:${invalid[1].col}`;
|
|
62
|
+
const current = invalidMap.get(key);
|
|
63
|
+
invalidMap.set(key, {
|
|
64
|
+
invalidType: 'invalid-value',
|
|
65
|
+
message: current?.message ? [current.message, invalid[0]].join(t('. ') + t('Or, ')) : invalid[0],
|
|
66
|
+
loc: invalid[1],
|
|
67
|
+
});
|
|
76
68
|
}
|
|
77
|
-
|
|
78
|
-
return invalid ?? false;
|
|
69
|
+
return [...invalidMap.values()];
|
|
79
70
|
}
|
|
80
71
|
export function valueCheck(t, name, value, type) {
|
|
81
72
|
if (type === 'Boolean') {
|
package/lib/helpers.d.ts
CHANGED
|
@@ -30,7 +30,15 @@ export declare function isValidAttr(t: Translator, name: string, value: string,
|
|
|
30
30
|
line: number;
|
|
31
31
|
col: number;
|
|
32
32
|
};
|
|
33
|
-
}
|
|
33
|
+
} | {
|
|
34
|
+
invalidType: "invalid-value";
|
|
35
|
+
message: string;
|
|
36
|
+
loc?: {
|
|
37
|
+
raw: string;
|
|
38
|
+
line: number;
|
|
39
|
+
col: number;
|
|
40
|
+
};
|
|
41
|
+
}[];
|
|
34
42
|
export declare function toNormalizedValue(value: string, spec: Attribute): string;
|
|
35
43
|
export declare function accnameMayBeMutable(el: Element<any, any>, document: Document<any, any>): boolean;
|
|
36
44
|
export declare function getOwnedLabel<V extends RuleConfigValue, O extends PlainData>(el: Element<V, O>, document: Document<V, O>): Element<V, O> | null;
|
package/lib/helpers.js
CHANGED
|
@@ -79,7 +79,7 @@ log) {
|
|
|
79
79
|
message: t('{0} is {1}', t('the "{0*}" {1}', name, 'attribute'), 'disallowed'),
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
if (invalid !== false && invalid.invalidType === 'invalid-value' && isDynamicValue) {
|
|
82
|
+
if (invalid !== false && (Array.isArray(invalid) || invalid.invalidType === 'invalid-value') && isDynamicValue) {
|
|
83
83
|
invalid = false;
|
|
84
84
|
}
|
|
85
85
|
return invalid;
|
|
@@ -167,45 +167,49 @@ export default createRule({
|
|
|
167
167
|
log('Checking %s[%s="%s"]', attr.nodeName, name, value);
|
|
168
168
|
invalid = isValidAttr(t, name, value, attr.isDynamicValue || false, attr.ownerElement, attrSpecs, log);
|
|
169
169
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
case 'invalid-value': {
|
|
180
|
-
if (attr.isDynamicValue) {
|
|
170
|
+
const invalidList = Array.isArray(invalid) ? invalid : [invalid];
|
|
171
|
+
for (const invalid of invalidList) {
|
|
172
|
+
if (invalid !== false) {
|
|
173
|
+
switch (invalid.invalidType) {
|
|
174
|
+
case 'disallowed-attr': {
|
|
175
|
+
report({
|
|
176
|
+
scope: attr,
|
|
177
|
+
message: invalid.message,
|
|
178
|
+
});
|
|
181
179
|
break;
|
|
182
180
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
181
|
+
case 'invalid-value': {
|
|
182
|
+
if (attr.isDynamicValue) {
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
report({
|
|
186
|
+
scope: attr,
|
|
187
|
+
message: invalid.message,
|
|
188
|
+
line: (valueNode?.startLine ?? 0) + (invalid.loc?.line ?? 0),
|
|
189
|
+
col: invalid.loc && invalid.loc.line > 0
|
|
190
|
+
? invalid.loc?.col + 1
|
|
191
|
+
: (valueNode?.startCol ?? 0) + (invalid.loc?.col ?? 0),
|
|
192
|
+
raw: invalid.loc?.raw ?? value,
|
|
193
|
+
});
|
|
194
|
+
break;
|
|
197
195
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
196
|
+
case 'non-existent': {
|
|
197
|
+
if (allowToAddPropertiesForPretender &&
|
|
198
|
+
attr.ownerElement.pretenderContext?.type === 'origin') {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const spec = getSpec(attr.ownerElement, document.specs.specs);
|
|
202
|
+
if (spec?.possibleToAddProperties) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
report({
|
|
206
|
+
scope: attr,
|
|
207
|
+
message: invalid.message,
|
|
208
|
+
line: attrName?.startLine,
|
|
209
|
+
col: attrName?.startCol,
|
|
210
|
+
raw: attrName?.raw,
|
|
211
|
+
});
|
|
201
212
|
}
|
|
202
|
-
report({
|
|
203
|
-
scope: attr,
|
|
204
|
-
message: invalid.message,
|
|
205
|
-
line: attrName?.startLine,
|
|
206
|
-
col: attrName?.startCol,
|
|
207
|
-
raw: attrName?.raw,
|
|
208
|
-
});
|
|
209
213
|
}
|
|
210
214
|
}
|
|
211
215
|
}
|
|
@@ -13,7 +13,7 @@ export const checkingImplicitProps = ({ attr, propSpecs, attrSpecs }) => t => {
|
|
|
13
13
|
for (const equivalentHtmlAttr of propSpec.equivalentHtmlAttrs) {
|
|
14
14
|
const htmlAttrSpec = attrSpecs.find(a => a.name === equivalentHtmlAttr.htmlAttrName);
|
|
15
15
|
const isValid = isValidAttr(t, equivalentHtmlAttr.htmlAttrName, equivalentHtmlAttr.value ?? '', false, attr.ownerElement, attrSpecs);
|
|
16
|
-
if (isValid !== false && isValid.invalidType === 'non-existent') {
|
|
16
|
+
if (isValid !== false && !Array.isArray(isValid) && isValid.invalidType === 'non-existent') {
|
|
17
17
|
continue;
|
|
18
18
|
}
|
|
19
19
|
const value = attr.value.trim().toLowerCase();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/rules",
|
|
3
|
-
"version": "4.10.
|
|
3
|
+
"version": "4.10.6",
|
|
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>",
|
|
@@ -17,26 +17,26 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "tsc",
|
|
21
|
-
"dev": "tsc --
|
|
20
|
+
"build": "tsc --project tsconfig.build.json",
|
|
21
|
+
"dev": "tsc --watch --project tsconfig.build.json",
|
|
22
22
|
"clean": "tsc --build --clean"
|
|
23
23
|
},
|
|
24
24
|
"browser": {
|
|
25
25
|
"./lib/permitted-contents/debug.js": "./lib/permitted-contents/debug.browser.js"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@markuplint/html-spec": "4.
|
|
29
|
-
"@markuplint/ml-core": "4.10.
|
|
30
|
-
"@markuplint/ml-spec": "4.
|
|
31
|
-
"@markuplint/selector": "4.6.
|
|
32
|
-
"@markuplint/shared": "4.4.
|
|
33
|
-
"@markuplint/types": "4.
|
|
28
|
+
"@markuplint/html-spec": "4.11.0",
|
|
29
|
+
"@markuplint/ml-core": "4.10.5",
|
|
30
|
+
"@markuplint/ml-spec": "4.9.0",
|
|
31
|
+
"@markuplint/selector": "4.6.13",
|
|
32
|
+
"@markuplint/shared": "4.4.10",
|
|
33
|
+
"@markuplint/types": "4.7.0",
|
|
34
34
|
"@types/debug": "4.1.12",
|
|
35
35
|
"@ungap/structured-clone": "1.2.0",
|
|
36
36
|
"ansi-colors": "4.1.3",
|
|
37
37
|
"chrono-node": "2.7.7",
|
|
38
38
|
"debug": "4.3.7",
|
|
39
|
-
"type-fest": "4.
|
|
39
|
+
"type-fest": "4.27.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "b2154ecf1e67559a3791991752f45c9c0283801a"
|
|
42
42
|
}
|
package/lib/__foo/index.d.ts
DELETED
package/lib/__foo/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createRule } from "@markuplint/ml-core";
|
|
2
|
-
import meta from "./meta.js";
|
|
3
|
-
export default createRule({
|
|
4
|
-
meta: meta,
|
|
5
|
-
defaultValue: true,
|
|
6
|
-
defaultOptions: null,
|
|
7
|
-
async verify({ document, report, t }) {
|
|
8
|
-
// Element
|
|
9
|
-
await document.walkOn("Element", (el) => {
|
|
10
|
-
const raw = el.raw.trim();
|
|
11
|
-
if (/./.test(raw)) {
|
|
12
|
-
report({
|
|
13
|
-
scope: el,
|
|
14
|
-
message: t("It is {0}", "issue"),
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
// Attribute
|
|
19
|
-
await document.walkOn("Attr", (attr) => {
|
|
20
|
-
if (/./.test(attr.name)) {
|
|
21
|
-
report({
|
|
22
|
-
scope: attr,
|
|
23
|
-
line: attr.nameNode?.startLine,
|
|
24
|
-
col: attr.nameNode?.startCol,
|
|
25
|
-
raw: attr.nameNode?.raw,
|
|
26
|
-
message: t("It is {0}", "issue"),
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
});
|
package/lib/__foo/meta.d.ts
DELETED
package/lib/__foo/meta.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { contentModelCategoryToTagNames } from '@markuplint/ml-spec';
|
|
2
|
-
const conditionWithoutSpecs = {
|
|
3
|
-
'#custom': {
|
|
4
|
-
selector: '#custom',
|
|
5
|
-
hasCustom: true,
|
|
6
|
-
hasText: false,
|
|
7
|
-
},
|
|
8
|
-
'#text': {
|
|
9
|
-
selector: '#text',
|
|
10
|
-
hasCustom: false,
|
|
11
|
-
hasText: true,
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
const optConditionSpecsBaseCaches = new Map();
|
|
15
|
-
export function optCondition(query, specs) {
|
|
16
|
-
const condWithoutSpecs = conditionWithoutSpecs[query];
|
|
17
|
-
if (condWithoutSpecs) {
|
|
18
|
-
return condWithoutSpecs;
|
|
19
|
-
}
|
|
20
|
-
const queryCaches = optConditionSpecsBaseCaches.get(specs) ?? new Map();
|
|
21
|
-
const cached = queryCaches.get(query);
|
|
22
|
-
if (cached) {
|
|
23
|
-
return cached;
|
|
24
|
-
}
|
|
25
|
-
let hasCustom = false;
|
|
26
|
-
let hasText = false;
|
|
27
|
-
const selector = query.replace(/^:model\(([^)]+)\)|^#([a-z-]+)/, (_, $model, _model) => {
|
|
28
|
-
const _selectors = contentModelCategoryToTagNames(`#${$model ?? _model}`, specs.def);
|
|
29
|
-
if (_selectors.length === 0) {
|
|
30
|
-
throw new Error(`${$model ?? _model} is empty`);
|
|
31
|
-
}
|
|
32
|
-
const selectors = [];
|
|
33
|
-
for (const selector of _selectors) {
|
|
34
|
-
if (selector === '#custom') {
|
|
35
|
-
hasCustom = true;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (selector === '#text') {
|
|
39
|
-
hasText = true;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
selectors.push(selector);
|
|
43
|
-
}
|
|
44
|
-
return `:is(${selectors.join(',')})`;
|
|
45
|
-
});
|
|
46
|
-
const result = {
|
|
47
|
-
selector,
|
|
48
|
-
hasCustom,
|
|
49
|
-
hasText,
|
|
50
|
-
};
|
|
51
|
-
queryCaches.set(query, result);
|
|
52
|
-
optConditionSpecsBaseCaches.set(specs, queryCaches);
|
|
53
|
-
return result;
|
|
54
|
-
}
|