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