@markuplint/ml-config 3.6.1 → 3.8.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/types.d.ts CHANGED
@@ -3,185 +3,201 @@ import type { RegexSelector } from '@markuplint/selector';
3
3
  import type { Nullable } from '@markuplint/shared';
4
4
  export type { RegexSelector } from '@markuplint/selector';
5
5
  export type Config = {
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>>;
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>>;
18
18
  };
19
19
  export type PrimitiveScalar = string | number | boolean;
20
- export type PlainData = Nullable<PrimitiveScalar> | readonly PlainData[] | {
21
- readonly [key: string]: PlainData | any;
22
- };
23
- export type NonNullablePlainData = PrimitiveScalar | readonly NonNullablePlainData[] | {
24
- readonly [key: string]: NonNullablePlainData;
25
- };
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
+ };
26
32
  export type OverrideConfig = Omit<Config, '$schema' | 'extends' | 'overrides'>;
27
33
  export type PluginConfig = {
28
- readonly name: string;
29
- readonly settings: Readonly<Record<string, NonNullablePlainData>>;
34
+ readonly name: string;
35
+ readonly settings: Readonly<Record<string, NonNullablePlainData>>;
30
36
  };
31
37
  export type ParserConfig = {
32
- readonly [extensionPattern: string]: string;
38
+ readonly [extensionPattern: string]: string;
33
39
  };
34
40
  export type SpecConfig = {
35
- readonly [extensionPattern: string]: string;
41
+ readonly [extensionPattern: string]: string;
36
42
  };
37
43
  export type Pretender = {
38
- /**
39
- * Target node selectors
40
- */
41
- readonly selector: string;
42
- /**
43
- * If it is a string, it is resolved as an element name.
44
- * An element has the same attributes as the pretended custom element
45
- * because attributes are just inherited.
46
- *
47
- * If it is an Object, It creates the element by that.
48
- */
49
- 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;
50
56
  };
51
57
  export type OriginalNode = {
52
- /**
53
- * Element name
54
- */
55
- readonly element: string;
56
- /**
57
- * Namespace
58
- *
59
- * Supports `"svg"` and `undefined` only.
60
- * If it is `undefined`, the namespace is HTML.
61
- */
62
- readonly namespace?: 'svg';
63
- /**
64
- * Attributes
65
- */
66
- readonly attrs?: readonly {
67
- /**
68
- * Attribute name
69
- */
70
- readonly name: string;
71
- /**
72
- * If it omits this property, the attribute is resolved as a boolean.
73
- */
74
- readonly value?: string | {
75
- readonly fromAttr: string;
76
- };
77
- }[];
78
- /**
79
- * To have attributes the defined element has.
80
- */
81
- readonly inheritAttrs?: boolean;
82
- /**
83
- * ARIA properties
84
- */
85
- 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;
86
94
  };
87
95
  /**
88
96
  * Pretender Node ARIA properties
89
97
  */
90
98
  export type PretenderARIA = {
91
- /**
92
- * Accessible name
93
- *
94
- * - If it is `true`, it assumes the element has any text on its accessible name.
95
- * - If it specifies `fromAttr` property, it assumes the accessible name refers to the value of the attribute.
96
- */
97
- readonly name?: boolean | {
98
- readonly fromAttr: string;
99
- };
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
+ };
100
110
  };
101
111
  export type Rule<T extends RuleConfigValue, O extends PlainData = undefined> = RuleConfig<T, O> | Readonly<T> | boolean;
102
112
  /**
103
113
  * @deprecated
104
114
  */
105
- 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;
106
119
  export type AnyRule = Rule<RuleConfigValue, PlainData>;
107
120
  /**
108
121
  * @deprecated
109
122
  */
110
123
  export type AnyRuleV2 = RuleV2<RuleConfigValue, PlainData>;
111
124
  export type Rules = {
112
- readonly [ruleName: string]: AnyRule;
125
+ readonly [ruleName: string]: AnyRule;
113
126
  };
114
127
  export type RuleConfig<T extends RuleConfigValue, O extends PlainData = undefined> = {
115
- readonly severity?: Severity;
116
- readonly value?: Readonly<T>;
117
- readonly options?: Readonly<O>;
118
- readonly reason?: string;
128
+ readonly severity?: Severity;
129
+ readonly value?: Readonly<T>;
130
+ readonly options?: Readonly<O>;
131
+ readonly reason?: string;
119
132
  };
120
133
  /**
121
134
  * @deprecated
122
135
  */
123
136
  export type RuleConfigV2<T extends RuleConfigValue, O extends PlainData = undefined> = {
124
- readonly severity?: Severity;
125
- readonly value?: Readonly<T>;
126
- readonly reason?: string;
127
- /**
128
- * Old property
129
- *
130
- * @deprecated
131
- * @see {this.options}
132
- */
133
- 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>;
134
147
  };
135
148
  export type Severity = 'error' | 'warning' | 'info';
136
149
  export type RuleConfigValue = PrimitiveScalar | readonly (PrimitiveScalar | Readonly<Record<string, any>>)[] | null;
137
150
  export type NodeRule = {
138
- readonly selector?: string;
139
- readonly regexSelector?: RegexSelector;
140
- readonly categories?: readonly string[];
141
- readonly roles?: readonly string[];
142
- readonly obsolete?: boolean;
143
- 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;
144
157
  };
145
158
  export type ChildNodeRule = {
146
- readonly selector?: string;
147
- readonly regexSelector?: RegexSelector;
148
- readonly inheritance?: boolean;
149
- readonly rules?: Rules;
150
- };
151
- 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);
152
168
  export type Report1<T extends RuleConfigValue, O extends PlainData = undefined> = {
153
- readonly message: string;
154
- readonly scope: Scope<T, O>;
169
+ readonly message: string;
170
+ readonly scope: Scope<T, O>;
155
171
  };
156
172
  export type Report2 = {
157
- readonly message: string;
158
- readonly line: number;
159
- readonly col: number;
160
- readonly raw: string;
173
+ readonly message: string;
174
+ readonly line: number;
175
+ readonly col: number;
176
+ readonly raw: string;
161
177
  };
162
178
  export type Scope<T extends RuleConfigValue, O extends PlainData = undefined> = {
163
- readonly rule: RuleInfo<T, O>;
164
- readonly startLine: number;
165
- readonly startCol: number;
166
- readonly raw: string;
179
+ readonly rule: RuleInfo<T, O>;
180
+ readonly startLine: number;
181
+ readonly startCol: number;
182
+ readonly raw: string;
167
183
  };
168
184
  export type Violation = {
169
- readonly ruleId: string;
170
- readonly severity: Severity;
171
- readonly message: string;
172
- readonly reason?: string;
173
- readonly line: number;
174
- readonly col: number;
175
- 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;
176
192
  };
177
193
  export type RuleInfo<T extends RuleConfigValue, O extends PlainData = undefined> = {
178
- readonly disabled: boolean;
179
- readonly severity: Severity;
180
- readonly value: Readonly<T>;
181
- readonly options: Readonly<O>;
182
- 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;
183
199
  };
184
200
  export type GlobalRuleInfo<T extends RuleConfigValue, O extends PlainData = undefined> = RuleInfo<T, O> & {
185
- nodeRules: RuleInfo<T, O>[];
186
- childNodeRules: RuleInfo<T, O>[];
201
+ nodeRules: RuleInfo<T, O>[];
202
+ childNodeRules: RuleInfo<T, O>[];
187
203
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-config",
3
- "version": "3.6.1",
3
+ "version": "3.8.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>",
@@ -18,17 +18,15 @@
18
18
  "build": "tsc",
19
19
  "clean": "tsc --build --clean"
20
20
  },
21
- "devDependencies": {
22
- "@markuplint/ml-ast": "3.1.0",
23
- "@markuplint/shared": "3.5.0",
24
- "@types/mustache": "^4.2.2"
25
- },
26
21
  "dependencies": {
27
- "@markuplint/selector": "3.6.1",
28
- "deepmerge": "^4.2.2",
22
+ "@markuplint/ml-ast": "3.1.0",
23
+ "@markuplint/selector": "3.8.0",
24
+ "@markuplint/shared": "3.6.0",
25
+ "@types/mustache": "^4.2.2",
26
+ "deepmerge": "^4.3.1",
29
27
  "is-plain-object": "^5.0.0",
30
28
  "mustache": "^4.2.0",
31
- "type-fest": "^3.6.1"
29
+ "type-fest": "^3.8.0"
32
30
  },
33
- "gitHead": "3cdf5a088b2da03773d5d4461d0e65ec32290a00"
31
+ "gitHead": "adc6e432cccba7cfad0dc8bf9f92e5aaf1107359"
34
32
  }
@@ -0,0 +1,233 @@
1
+ const { mergeConfig, mergeRule } = require('../lib/merge-config');
2
+
3
+ it('test', () => {
4
+ expect(mergeConfig({}, {})).toStrictEqual({});
5
+ });
6
+
7
+ it('test', () => {
8
+ expect(
9
+ mergeConfig(
10
+ {
11
+ plugins: ['a', 'b', 'c'],
12
+ },
13
+ {
14
+ plugins: ['c', 'b', 'd'],
15
+ },
16
+ ),
17
+ ).toStrictEqual({
18
+ plugins: ['a', 'b', 'c', 'd'],
19
+ });
20
+ });
21
+
22
+ it('test', () => {
23
+ expect(
24
+ mergeConfig(
25
+ {
26
+ plugins: ['a', 'b', { name: 'c', settings: { foo: 'foo', bar: 'bar' } }],
27
+ },
28
+ {
29
+ plugins: ['c', 'b', 'd', { name: 'c', settings: { foo2: 'foo2', bar: 'bar2' } }],
30
+ },
31
+ ),
32
+ ).toStrictEqual({
33
+ plugins: [
34
+ 'a',
35
+ 'b',
36
+ {
37
+ name: 'c',
38
+ settings: {
39
+ bar: 'bar2',
40
+ foo: 'foo',
41
+ foo2: 'foo2',
42
+ },
43
+ },
44
+ 'd',
45
+ ],
46
+ });
47
+ });
48
+
49
+ it('test', () => {
50
+ expect(
51
+ mergeConfig(
52
+ {
53
+ parser: { '/\\.vue$/i': '@markuplint/vue-parser' },
54
+ },
55
+ {
56
+ parser: { '/\\.vue$/i': '@markuplint/vue-parser' },
57
+ },
58
+ ),
59
+ ).toStrictEqual({
60
+ parser: { '/\\.vue$/i': '@markuplint/vue-parser' },
61
+ });
62
+ });
63
+
64
+ it('test', () => {
65
+ expect(
66
+ mergeConfig(
67
+ {
68
+ parser: { '/\\.vue$/i': '@markuplint/vue-parser' },
69
+ },
70
+ {
71
+ parser: { '/\\.[jt]sx?$/i': '@markuplint/jsx-parser' },
72
+ },
73
+ ),
74
+ ).toStrictEqual({
75
+ parser: {
76
+ '/\\.vue$/i': '@markuplint/vue-parser',
77
+ '/\\.[jt]sx?$/i': '@markuplint/jsx-parser',
78
+ },
79
+ });
80
+ });
81
+
82
+ it('test', () => {
83
+ expect(
84
+ mergeRule(
85
+ {
86
+ value: true,
87
+ },
88
+ {},
89
+ ),
90
+ ).toStrictEqual({
91
+ value: true,
92
+ });
93
+
94
+ expect(
95
+ mergeRule(
96
+ {
97
+ value: true,
98
+ },
99
+ false,
100
+ ),
101
+ ).toStrictEqual(false);
102
+
103
+ expect(
104
+ mergeRule(
105
+ {
106
+ value: false,
107
+ },
108
+ true,
109
+ ),
110
+ ).toStrictEqual({
111
+ value: true,
112
+ });
113
+
114
+ expect(
115
+ mergeRule(
116
+ {
117
+ options: {
118
+ optional: 'OPTIONAL_VALUE',
119
+ },
120
+ },
121
+ {
122
+ options: {
123
+ optional: 'CHANGED_OPTIONAL_VALUE',
124
+ },
125
+ },
126
+ ),
127
+ ).toStrictEqual({
128
+ options: {
129
+ optional: 'CHANGED_OPTIONAL_VALUE',
130
+ },
131
+ });
132
+
133
+ expect(
134
+ mergeRule(
135
+ {
136
+ option: {
137
+ optional: 'OPTIONAL_VALUE',
138
+ },
139
+ },
140
+ {
141
+ option: {
142
+ optional: 'CHANGED_OPTIONAL_VALUE',
143
+ },
144
+ },
145
+ ),
146
+ ).toStrictEqual({
147
+ options: {
148
+ optional: 'CHANGED_OPTIONAL_VALUE',
149
+ },
150
+ });
151
+ });
152
+
153
+ it('test', () => {
154
+ expect(
155
+ mergeConfig(
156
+ {
157
+ overrides: {
158
+ a: {
159
+ rules: {
160
+ rule1: true,
161
+ },
162
+ },
163
+ },
164
+ },
165
+ {
166
+ overrides: {
167
+ a: {
168
+ rules: {
169
+ rule1: false,
170
+ },
171
+ },
172
+ b: {
173
+ rules: {
174
+ rule1: true,
175
+ },
176
+ },
177
+ },
178
+ },
179
+ ),
180
+ ).toStrictEqual({
181
+ overrides: {
182
+ a: {
183
+ rules: {
184
+ rule1: false,
185
+ },
186
+ },
187
+ b: {
188
+ rules: {
189
+ rule1: true,
190
+ },
191
+ },
192
+ },
193
+ });
194
+ });
195
+
196
+ it('test', () => {
197
+ expect(
198
+ mergeConfig(
199
+ {
200
+ rules: {
201
+ a: {
202
+ // @ts-ignore
203
+ option: {
204
+ ruleA: true,
205
+ },
206
+ },
207
+ },
208
+ },
209
+ {
210
+ rules: {
211
+ b: {
212
+ options: {
213
+ ruleB: true,
214
+ },
215
+ },
216
+ },
217
+ },
218
+ ),
219
+ ).toStrictEqual({
220
+ rules: {
221
+ a: {
222
+ options: {
223
+ ruleA: true,
224
+ },
225
+ },
226
+ b: {
227
+ options: {
228
+ ruleB: true,
229
+ },
230
+ },
231
+ },
232
+ });
233
+ });
@@ -0,0 +1,119 @@
1
+ const { exchangeValueOnRule, provideValue } = require('../lib/utils');
2
+
3
+ it('provideValue', () => {
4
+ expect(
5
+ provideValue('The name is {{ dataName }}', {
6
+ $0: 'data-hoge',
7
+ $1: 'hoge',
8
+ dataName: 'hoge',
9
+ }),
10
+ ).toBe('The name is hoge');
11
+
12
+ expect(provideValue('The name is {{ dataName }}', {})).toBeUndefined();
13
+
14
+ expect(
15
+ provideValue('No variable', {
16
+ $0: 'data-hoge',
17
+ $1: 'hoge',
18
+ dataName: 'hoge',
19
+ }),
20
+ ).toBe('No variable');
21
+ });
22
+
23
+ it('exchangeValueOnRule', () => {
24
+ expect(
25
+ exchangeValueOnRule('The name is {{ dataName }}', {
26
+ $0: 'data-hoge',
27
+ $1: 'hoge',
28
+ dataName: 'hoge',
29
+ }),
30
+ ).toBe('The name is hoge');
31
+
32
+ expect(
33
+ exchangeValueOnRule(
34
+ {
35
+ value: 'The name is {{ dataName }}',
36
+ },
37
+ {
38
+ $0: 'data-hoge',
39
+ $1: 'hoge',
40
+ dataName: 'hoge',
41
+ },
42
+ ),
43
+ ).toStrictEqual({
44
+ value: 'The name is hoge',
45
+ });
46
+
47
+ expect(
48
+ exchangeValueOnRule(
49
+ {
50
+ severity: 'error',
51
+ value: 'The name is {{ dataName }}',
52
+ reason: 'For {{ dataName }}',
53
+ },
54
+ {
55
+ $0: 'data-hoge',
56
+ $1: 'hoge',
57
+ dataName: 'hoge',
58
+ },
59
+ ),
60
+ ).toStrictEqual({
61
+ severity: 'error',
62
+ value: 'The name is hoge',
63
+ reason: 'For hoge',
64
+ });
65
+
66
+ expect(
67
+ exchangeValueOnRule(
68
+ {
69
+ value: 'The name is {{ dataName }}',
70
+ option: {
71
+ propA: 'The name is {{ dataName }}',
72
+ propB: ['The name is {{ dataName }}'],
73
+ propC: {
74
+ prop: 'The name is {{ dataName }}',
75
+ },
76
+ },
77
+ },
78
+ {
79
+ dataName: 'hoge',
80
+ },
81
+ ),
82
+ ).toStrictEqual({
83
+ value: 'The name is hoge',
84
+ options: {
85
+ propA: 'The name is hoge',
86
+ propB: ['The name is hoge'],
87
+ propC: {
88
+ prop: 'The name is hoge',
89
+ },
90
+ },
91
+ });
92
+
93
+ expect(
94
+ exchangeValueOnRule(
95
+ {
96
+ value: 'The name is {{ dataName }}',
97
+ options: {
98
+ propA: 'The name is {{ dataName }}',
99
+ propB: ['The name is {{ dataName }}'],
100
+ propC: {
101
+ prop: 'The name is {{ dataName }}',
102
+ },
103
+ },
104
+ },
105
+ {
106
+ dataName: 'hoge',
107
+ },
108
+ ),
109
+ ).toStrictEqual({
110
+ value: 'The name is hoge',
111
+ options: {
112
+ propA: 'The name is hoge',
113
+ propB: ['The name is hoge'],
114
+ propC: {
115
+ prop: 'The name is hoge',
116
+ },
117
+ },
118
+ });
119
+ });