@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.
@@ -1,3 +1,4 @@
1
- import type { Config, Nullable, AnyRule, AnyRuleV2 } from './types';
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;
@@ -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 || undefined;
73
+ return b !== null && b !== void 0 ? b : undefined;
74
74
  }
75
75
  if (b == null) {
76
- return a || undefined;
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 a && optimizeRules(a);
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
- 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>>;
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 = Nullable<PrimitiveScalar> | readonly PlainData[] | {
20
- readonly [key: string]: PlainData | any;
21
- };
22
- export type NonNullablePlainData = PrimitiveScalar | readonly NonNullablePlainData[] | {
23
- readonly [key: string]: NonNullablePlainData;
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
- readonly name: string;
28
- readonly settings: Readonly<Record<string, NonNullablePlainData>>;
34
+ readonly name: string;
35
+ readonly settings: Readonly<Record<string, NonNullablePlainData>>;
29
36
  };
30
37
  export type ParserConfig = {
31
- readonly [extensionPattern: string]: string;
38
+ readonly [extensionPattern: string]: string;
32
39
  };
33
40
  export type SpecConfig = {
34
- readonly [extensionPattern: string]: string;
41
+ readonly [extensionPattern: string]: string;
35
42
  };
36
43
  export type Pretender = {
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;
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
- * 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;
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
- * 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
+ * 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> = RuleConfigV2<T, O> | Readonly<T> | boolean;
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
- readonly [ruleName: string]: AnyRule;
125
+ readonly [ruleName: string]: AnyRule;
112
126
  };
113
127
  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;
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
- 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>;
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
- 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;
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
- 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);
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
- readonly message: string;
153
- readonly scope: Scope<T, O>;
169
+ readonly message: string;
170
+ readonly scope: Scope<T, O>;
154
171
  };
155
172
  export type Report2 = {
156
- readonly message: string;
157
- readonly line: number;
158
- readonly col: number;
159
- readonly raw: string;
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
- readonly rule: RuleInfo<T, O>;
163
- readonly startLine: number;
164
- readonly startCol: number;
165
- readonly raw: string;
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
- 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;
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
- readonly disabled: boolean;
178
- readonly severity: Severity;
179
- readonly value: Readonly<T>;
180
- readonly options: Readonly<O>;
181
- readonly reason?: string;
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
- nodeRules: RuleInfo<T, O>[];
185
- childNodeRules: RuleInfo<T, O>[];
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(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>;
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.5.0",
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.5.0",
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": "0c47b2c2722f6823a17f36edbab98486275f8ab4"
33
+ "gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
33
34
  }