@markuplint/ml-config 3.5.0 → 3.6.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.
- package/lib/merge-config.d.ts +2 -1
- package/lib/merge-config.js +3 -3
- package/lib/types.d.ts +146 -130
- package/lib/utils.d.ts +7 -2
- package/lib/utils.js +5 -5
- package/package.json +4 -3
package/lib/merge-config.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { Config,
|
|
1
|
+
import type { Config, AnyRule, AnyRuleV2 } from './types';
|
|
2
|
+
import type { Nullable } from '@markuplint/shared';
|
|
2
3
|
export declare function mergeConfig(a: Config, b: Config): Config;
|
|
3
4
|
export declare function mergeRule(a: Nullable<AnyRule | AnyRuleV2>, b: AnyRule | AnyRuleV2): AnyRule;
|
package/lib/merge-config.js
CHANGED
|
@@ -70,10 +70,10 @@ function mergeRule(a, b) {
|
|
|
70
70
|
exports.mergeRule = mergeRule;
|
|
71
71
|
function mergeObject(a, b) {
|
|
72
72
|
if (a == null) {
|
|
73
|
-
return b
|
|
73
|
+
return b !== null && b !== void 0 ? b : undefined;
|
|
74
74
|
}
|
|
75
75
|
if (b == null) {
|
|
76
|
-
return a
|
|
76
|
+
return a !== null && a !== void 0 ? a : undefined;
|
|
77
77
|
}
|
|
78
78
|
const res = (0, deepmerge_1.default)(a, b);
|
|
79
79
|
(0, utils_1.deleteUndefProp)(res);
|
|
@@ -135,7 +135,7 @@ function mergeRules(a, b) {
|
|
|
135
135
|
return b && optimizeRules(b);
|
|
136
136
|
}
|
|
137
137
|
if (b == null) {
|
|
138
|
-
return
|
|
138
|
+
return optimizeRules(a);
|
|
139
139
|
}
|
|
140
140
|
const res = optimizeRules(a);
|
|
141
141
|
for (const [key, rule] of Object.entries(b)) {
|
package/lib/types.d.ts
CHANGED
|
@@ -1,187 +1,203 @@
|
|
|
1
1
|
import type { ParserOptions } from '@markuplint/ml-ast';
|
|
2
2
|
import type { RegexSelector } from '@markuplint/selector';
|
|
3
|
+
import type { Nullable } from '@markuplint/shared';
|
|
3
4
|
export type { RegexSelector } from '@markuplint/selector';
|
|
4
5
|
export type Config = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
readonly $schema?: string;
|
|
7
|
+
readonly extends?: string | readonly string[];
|
|
8
|
+
readonly plugins?: readonly (PluginConfig | string)[];
|
|
9
|
+
readonly parser?: ParserConfig;
|
|
10
|
+
readonly parserOptions?: ParserOptions;
|
|
11
|
+
readonly specs?: SpecConfig;
|
|
12
|
+
readonly excludeFiles?: readonly string[];
|
|
13
|
+
readonly pretenders?: readonly Pretender[];
|
|
14
|
+
readonly rules?: Rules;
|
|
15
|
+
readonly nodeRules?: readonly NodeRule[];
|
|
16
|
+
readonly childNodeRules?: readonly ChildNodeRule[];
|
|
17
|
+
readonly overrides?: Readonly<Record<string, OverrideConfig>>;
|
|
17
18
|
};
|
|
18
19
|
export type PrimitiveScalar = string | number | boolean;
|
|
19
|
-
export type PlainData =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
20
|
+
export type PlainData =
|
|
21
|
+
| Nullable<PrimitiveScalar>
|
|
22
|
+
| readonly PlainData[]
|
|
23
|
+
| {
|
|
24
|
+
readonly [key: string]: PlainData | any;
|
|
25
|
+
};
|
|
26
|
+
export type NonNullablePlainData =
|
|
27
|
+
| PrimitiveScalar
|
|
28
|
+
| readonly NonNullablePlainData[]
|
|
29
|
+
| {
|
|
30
|
+
readonly [key: string]: NonNullablePlainData;
|
|
31
|
+
};
|
|
25
32
|
export type OverrideConfig = Omit<Config, '$schema' | 'extends' | 'overrides'>;
|
|
26
33
|
export type PluginConfig = {
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly settings: Readonly<Record<string, NonNullablePlainData>>;
|
|
29
36
|
};
|
|
30
37
|
export type ParserConfig = {
|
|
31
|
-
|
|
38
|
+
readonly [extensionPattern: string]: string;
|
|
32
39
|
};
|
|
33
40
|
export type SpecConfig = {
|
|
34
|
-
|
|
41
|
+
readonly [extensionPattern: string]: string;
|
|
35
42
|
};
|
|
36
43
|
export type Pretender = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Target node selectors
|
|
46
|
+
*/
|
|
47
|
+
readonly selector: string;
|
|
48
|
+
/**
|
|
49
|
+
* If it is a string, it is resolved as an element name.
|
|
50
|
+
* An element has the same attributes as the pretended custom element
|
|
51
|
+
* because attributes are just inherited.
|
|
52
|
+
*
|
|
53
|
+
* If it is an Object, It creates the element by that.
|
|
54
|
+
*/
|
|
55
|
+
readonly as: string | OriginalNode;
|
|
49
56
|
};
|
|
50
57
|
export type OriginalNode = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Element name
|
|
60
|
+
*/
|
|
61
|
+
readonly element: string;
|
|
62
|
+
/**
|
|
63
|
+
* Namespace
|
|
64
|
+
*
|
|
65
|
+
* Supports `"svg"` and `undefined` only.
|
|
66
|
+
* If it is `undefined`, the namespace is HTML.
|
|
67
|
+
*/
|
|
68
|
+
readonly namespace?: 'svg';
|
|
69
|
+
/**
|
|
70
|
+
* Attributes
|
|
71
|
+
*/
|
|
72
|
+
readonly attrs?: readonly {
|
|
73
|
+
/**
|
|
74
|
+
* Attribute name
|
|
75
|
+
*/
|
|
76
|
+
readonly name: string;
|
|
77
|
+
/**
|
|
78
|
+
* If it omits this property, the attribute is resolved as a boolean.
|
|
79
|
+
*/
|
|
80
|
+
readonly value?:
|
|
81
|
+
| string
|
|
82
|
+
| {
|
|
83
|
+
readonly fromAttr: string;
|
|
84
|
+
};
|
|
85
|
+
}[];
|
|
86
|
+
/**
|
|
87
|
+
* To have attributes the defined element has.
|
|
88
|
+
*/
|
|
89
|
+
readonly inheritAttrs?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* ARIA properties
|
|
92
|
+
*/
|
|
93
|
+
readonly aria?: PretenderARIA;
|
|
85
94
|
};
|
|
86
95
|
/**
|
|
87
96
|
* Pretender Node ARIA properties
|
|
88
97
|
*/
|
|
89
98
|
export type PretenderARIA = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Accessible name
|
|
101
|
+
*
|
|
102
|
+
* - If it is `true`, it assumes the element has any text on its accessible name.
|
|
103
|
+
* - If it specifies `fromAttr` property, it assumes the accessible name refers to the value of the attribute.
|
|
104
|
+
*/
|
|
105
|
+
readonly name?:
|
|
106
|
+
| boolean
|
|
107
|
+
| {
|
|
108
|
+
readonly fromAttr: string;
|
|
109
|
+
};
|
|
99
110
|
};
|
|
100
111
|
export type Rule<T extends RuleConfigValue, O extends PlainData = undefined> = RuleConfig<T, O> | Readonly<T> | boolean;
|
|
101
112
|
/**
|
|
102
113
|
* @deprecated
|
|
103
114
|
*/
|
|
104
|
-
export type RuleV2<T extends RuleConfigValue, O extends PlainData = undefined> =
|
|
115
|
+
export type RuleV2<T extends RuleConfigValue, O extends PlainData = undefined> =
|
|
116
|
+
| RuleConfigV2<T, O>
|
|
117
|
+
| Readonly<T>
|
|
118
|
+
| boolean;
|
|
105
119
|
export type AnyRule = Rule<RuleConfigValue, PlainData>;
|
|
106
120
|
/**
|
|
107
121
|
* @deprecated
|
|
108
122
|
*/
|
|
109
123
|
export type AnyRuleV2 = RuleV2<RuleConfigValue, PlainData>;
|
|
110
124
|
export type Rules = {
|
|
111
|
-
|
|
125
|
+
readonly [ruleName: string]: AnyRule;
|
|
112
126
|
};
|
|
113
127
|
export type RuleConfig<T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
readonly severity?: Severity;
|
|
129
|
+
readonly value?: Readonly<T>;
|
|
130
|
+
readonly options?: Readonly<O>;
|
|
131
|
+
readonly reason?: string;
|
|
118
132
|
};
|
|
119
133
|
/**
|
|
120
134
|
* @deprecated
|
|
121
135
|
*/
|
|
122
136
|
export type RuleConfigV2<T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
137
|
+
readonly severity?: Severity;
|
|
138
|
+
readonly value?: Readonly<T>;
|
|
139
|
+
readonly reason?: string;
|
|
140
|
+
/**
|
|
141
|
+
* Old property
|
|
142
|
+
*
|
|
143
|
+
* @deprecated
|
|
144
|
+
* @see {this.options}
|
|
145
|
+
*/
|
|
146
|
+
readonly option?: Readonly<O>;
|
|
133
147
|
};
|
|
134
148
|
export type Severity = 'error' | 'warning' | 'info';
|
|
135
149
|
export type RuleConfigValue = PrimitiveScalar | readonly (PrimitiveScalar | Readonly<Record<string, any>>)[] | null;
|
|
136
150
|
export type NodeRule = {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
151
|
+
readonly selector?: string;
|
|
152
|
+
readonly regexSelector?: RegexSelector;
|
|
153
|
+
readonly categories?: readonly string[];
|
|
154
|
+
readonly roles?: readonly string[];
|
|
155
|
+
readonly obsolete?: boolean;
|
|
156
|
+
readonly rules?: Rules;
|
|
143
157
|
};
|
|
144
158
|
export type ChildNodeRule = {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
};
|
|
150
|
-
export type Report<T extends RuleConfigValue, O extends PlainData = undefined> =
|
|
159
|
+
readonly selector?: string;
|
|
160
|
+
readonly regexSelector?: RegexSelector;
|
|
161
|
+
readonly inheritance?: boolean;
|
|
162
|
+
readonly rules?: Rules;
|
|
163
|
+
};
|
|
164
|
+
export type Report<T extends RuleConfigValue, O extends PlainData = undefined> =
|
|
165
|
+
| Report1<T, O>
|
|
166
|
+
| Report2
|
|
167
|
+
| (Report1<T, O> & Report2);
|
|
151
168
|
export type Report1<T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
152
|
-
|
|
153
|
-
|
|
169
|
+
readonly message: string;
|
|
170
|
+
readonly scope: Scope<T, O>;
|
|
154
171
|
};
|
|
155
172
|
export type Report2 = {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
173
|
+
readonly message: string;
|
|
174
|
+
readonly line: number;
|
|
175
|
+
readonly col: number;
|
|
176
|
+
readonly raw: string;
|
|
160
177
|
};
|
|
161
178
|
export type Scope<T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
179
|
+
readonly rule: RuleInfo<T, O>;
|
|
180
|
+
readonly startLine: number;
|
|
181
|
+
readonly startCol: number;
|
|
182
|
+
readonly raw: string;
|
|
166
183
|
};
|
|
167
184
|
export type Violation = {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
185
|
+
readonly ruleId: string;
|
|
186
|
+
readonly severity: Severity;
|
|
187
|
+
readonly message: string;
|
|
188
|
+
readonly reason?: string;
|
|
189
|
+
readonly line: number;
|
|
190
|
+
readonly col: number;
|
|
191
|
+
readonly raw: string;
|
|
175
192
|
};
|
|
176
193
|
export type RuleInfo<T extends RuleConfigValue, O extends PlainData = undefined> = {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
194
|
+
readonly disabled: boolean;
|
|
195
|
+
readonly severity: Severity;
|
|
196
|
+
readonly value: Readonly<T>;
|
|
197
|
+
readonly options: Readonly<O>;
|
|
198
|
+
readonly reason?: string;
|
|
182
199
|
};
|
|
183
200
|
export type GlobalRuleInfo<T extends RuleConfigValue, O extends PlainData = undefined> = RuleInfo<T, O> & {
|
|
184
|
-
|
|
185
|
-
|
|
201
|
+
nodeRules: RuleInfo<T, O>[];
|
|
202
|
+
childNodeRules: RuleInfo<T, O>[];
|
|
186
203
|
};
|
|
187
|
-
export type Nullable<T> = T | null | undefined;
|
package/lib/utils.d.ts
CHANGED
|
@@ -7,8 +7,13 @@ import type { AnyRule, AnyRuleV2, PlainData, RuleConfig, RuleConfigV2, RuleConfi
|
|
|
7
7
|
* @param data Captured string for replacement
|
|
8
8
|
*/
|
|
9
9
|
export declare function provideValue(template: string, data: Readonly<Record<string, string>>): string | undefined;
|
|
10
|
-
export declare function exchangeValueOnRule(
|
|
11
|
-
|
|
10
|
+
export declare function exchangeValueOnRule(
|
|
11
|
+
rule: AnyRule | AnyRuleV2,
|
|
12
|
+
data: Readonly<Record<string, string>>,
|
|
13
|
+
): AnyRule | undefined;
|
|
14
|
+
export declare function cleanOptions(
|
|
15
|
+
rule: RuleConfig<RuleConfigValue, PlainData> | RuleConfigV2<RuleConfigValue, PlainData>,
|
|
16
|
+
): RuleConfig<RuleConfigValue, PlainData>;
|
|
12
17
|
export declare function isRuleConfigValue(v: any): v is RuleConfigValue;
|
|
13
18
|
/**
|
|
14
19
|
*
|
package/lib/utils.js
CHANGED
|
@@ -39,7 +39,7 @@ function exchangeValueOnRule(rule, data) {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
const options = extractOptions(result);
|
|
42
|
-
if (options) {
|
|
42
|
+
if (options != null && options !== '' && options !== 0) {
|
|
43
43
|
const newOptions = exchangeOption(options, data);
|
|
44
44
|
result = {
|
|
45
45
|
...result,
|
|
@@ -54,7 +54,7 @@ function exchangeValueOnRule(rule, data) {
|
|
|
54
54
|
const exchangedValue = exchangeValue(result.reason, data);
|
|
55
55
|
result = {
|
|
56
56
|
...result,
|
|
57
|
-
reason: exchangedValue ? `${exchangedValue}` : undefined,
|
|
57
|
+
reason: exchangedValue != null ? `${exchangedValue}` : undefined,
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
deleteUndefProp(result);
|
|
@@ -109,10 +109,10 @@ exports.deleteUndefProp = deleteUndefProp;
|
|
|
109
109
|
* @returns
|
|
110
110
|
*/
|
|
111
111
|
function extractOptions(rule) {
|
|
112
|
-
if ('options' in rule && rule.options) {
|
|
112
|
+
if ('options' in rule && rule.options != null) {
|
|
113
113
|
return rule.options;
|
|
114
114
|
}
|
|
115
|
-
if ('option' in rule && rule.option) {
|
|
115
|
+
if ('option' in rule && rule.option != null) {
|
|
116
116
|
return rule.option;
|
|
117
117
|
}
|
|
118
118
|
}
|
|
@@ -132,7 +132,7 @@ function exchangeValue(rule, data) {
|
|
|
132
132
|
return val;
|
|
133
133
|
})
|
|
134
134
|
.filter((item) => item !== undefined);
|
|
135
|
-
return ruleArray.length ? ruleArray : undefined;
|
|
135
|
+
return ruleArray.length > 0 ? ruleArray : undefined;
|
|
136
136
|
}
|
|
137
137
|
return rule;
|
|
138
138
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/ml-config",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "JSON Schema and TypeScript types of markuplint configure JSON",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@markuplint/ml-ast": "3.1.0",
|
|
23
|
+
"@markuplint/shared": "3.5.0",
|
|
23
24
|
"@types/mustache": "^4.2.2"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@markuplint/selector": "3.
|
|
27
|
+
"@markuplint/selector": "3.6.0",
|
|
27
28
|
"deepmerge": "^4.2.2",
|
|
28
29
|
"is-plain-object": "^5.0.0",
|
|
29
30
|
"mustache": "^4.2.0",
|
|
30
31
|
"type-fest": "^3.6.1"
|
|
31
32
|
},
|
|
32
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
|
|
33
34
|
}
|