@markuplint/ml-config 3.7.0 → 3.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-config",
3
- "version": "3.7.0",
3
+ "version": "3.9.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.7.0",
28
- "deepmerge": "^4.2.2",
22
+ "@markuplint/ml-ast": "3.1.0",
23
+ "@markuplint/selector": "3.9.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.10.0"
32
30
  },
33
- "gitHead": "42b97b47d22b37437024e693a72a458e2963e261"
31
+ "gitHead": "af370797bfc887e5a5a2ff57fbaa8392ac98ead2"
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
+ });