@markuplint/ml-config 3.12.0 → 4.0.0-alpha.2
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/index.d.ts +3 -3
- package/lib/index.js +3 -6
- package/lib/merge-config.d.ts +1 -1
- package/lib/merge-config.js +25 -32
- package/lib/types.js +1 -2
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +13 -22
- package/package.json +13 -8
- package/test/merge-config.spec.js +0 -294
- package/test/utils.spec.js +0 -119
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './merge-config';
|
|
2
|
-
export * from './utils';
|
|
3
|
-
export * from './types';
|
|
1
|
+
export * from './merge-config.js';
|
|
2
|
+
export * from './utils.js';
|
|
3
|
+
export * from './types.js';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./merge-config"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./utils"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './merge-config.js';
|
|
2
|
+
export * from './utils.js';
|
|
3
|
+
export * from './types.js';
|
package/lib/merge-config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Config, AnyRule, AnyRuleV2 } from './types';
|
|
1
|
+
import type { Config, AnyRule, AnyRuleV2 } from './types.js';
|
|
2
2
|
import type { Nullable } from '@markuplint/shared';
|
|
3
3
|
export declare function mergeConfig(a: Config, b: Config): Config;
|
|
4
4
|
export declare function mergeRule(a: Nullable<AnyRule | AnyRuleV2>, b: AnyRule | AnyRuleV2): AnyRule;
|
package/lib/merge-config.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
function mergeConfig(a, b) {
|
|
1
|
+
import deepmerge from 'deepmerge';
|
|
2
|
+
import { deleteUndefProp, cleanOptions, isRuleConfigValue } from './utils.js';
|
|
3
|
+
export function mergeConfig(a, b) {
|
|
8
4
|
const config = {
|
|
9
5
|
...a,
|
|
10
6
|
...b,
|
|
@@ -22,61 +18,58 @@ function mergeConfig(a, b) {
|
|
|
22
18
|
// delete all
|
|
23
19
|
extends: undefined,
|
|
24
20
|
};
|
|
25
|
-
|
|
21
|
+
deleteUndefProp(config);
|
|
26
22
|
return config;
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
function mergeRule(a, b) {
|
|
30
|
-
var _a, _b, _c;
|
|
24
|
+
export function mergeRule(a, b) {
|
|
31
25
|
const oA = optimizeRule(a);
|
|
32
26
|
const oB = optimizeRule(b);
|
|
33
27
|
// Particular behavior:
|
|
34
28
|
// If the right-side value is false, return false.
|
|
35
29
|
// In short; The `false` makes the rule to be disabled absolutely.
|
|
36
|
-
if (oB === false || (!
|
|
30
|
+
if (oB === false || (!isRuleConfigValue(oB) && oB?.value === false)) {
|
|
37
31
|
return false;
|
|
38
32
|
}
|
|
39
33
|
if (oA === undefined) {
|
|
40
|
-
return oB
|
|
34
|
+
return oB ?? {};
|
|
41
35
|
}
|
|
42
36
|
if (oB === undefined) {
|
|
43
37
|
return oA;
|
|
44
38
|
}
|
|
45
|
-
if (
|
|
46
|
-
if (
|
|
39
|
+
if (isRuleConfigValue(oB)) {
|
|
40
|
+
if (isRuleConfigValue(oA)) {
|
|
47
41
|
if (Array.isArray(oA) && Array.isArray(oB)) {
|
|
48
42
|
return [...oA, ...oB];
|
|
49
43
|
}
|
|
50
44
|
return oB;
|
|
51
45
|
}
|
|
52
46
|
const value = Array.isArray(oA.value) && Array.isArray(oB) ? [...oA.value, ...oB] : oB;
|
|
53
|
-
const res =
|
|
54
|
-
|
|
47
|
+
const res = cleanOptions({ ...oA, value });
|
|
48
|
+
deleteUndefProp(res);
|
|
55
49
|
return res;
|
|
56
50
|
}
|
|
57
|
-
const severity =
|
|
58
|
-
const value =
|
|
59
|
-
const options = mergeObject(!
|
|
60
|
-
const reason =
|
|
51
|
+
const severity = oB.severity ?? (!isRuleConfigValue(oA) ? oA.severity : undefined);
|
|
52
|
+
const value = oB.value ?? (isRuleConfigValue(oA) ? oA : oA.value);
|
|
53
|
+
const options = mergeObject(!isRuleConfigValue(oA) ? oA.options : undefined, oB.options);
|
|
54
|
+
const reason = oB.reason ?? (!isRuleConfigValue(oA) ? oA.reason : undefined);
|
|
61
55
|
const res = {
|
|
62
56
|
severity,
|
|
63
57
|
value,
|
|
64
58
|
options,
|
|
65
59
|
reason,
|
|
66
60
|
};
|
|
67
|
-
|
|
61
|
+
deleteUndefProp(res);
|
|
68
62
|
return res;
|
|
69
63
|
}
|
|
70
|
-
exports.mergeRule = mergeRule;
|
|
71
64
|
function mergeObject(a, b) {
|
|
72
65
|
if (a == null) {
|
|
73
|
-
return b
|
|
66
|
+
return b ?? undefined;
|
|
74
67
|
}
|
|
75
68
|
if (b == null) {
|
|
76
|
-
return a
|
|
69
|
+
return a ?? undefined;
|
|
77
70
|
}
|
|
78
|
-
const res = (
|
|
79
|
-
|
|
71
|
+
const res = deepmerge(a, b);
|
|
72
|
+
deleteUndefProp(res);
|
|
80
73
|
return res;
|
|
81
74
|
}
|
|
82
75
|
function concatArray(a, b, uniquely = false, comparePropName) {
|
|
@@ -114,8 +107,8 @@ function concatArray(a, b, uniquely = false, comparePropName) {
|
|
|
114
107
|
}
|
|
115
108
|
newArray.splice(existedIndex, 1, merged);
|
|
116
109
|
}
|
|
117
|
-
a
|
|
118
|
-
b
|
|
110
|
+
a?.forEach(concat);
|
|
111
|
+
b?.forEach(concat);
|
|
119
112
|
return newArray.length === 0 ? undefined : newArray;
|
|
120
113
|
}
|
|
121
114
|
function getName(item, comparePropName) {
|
|
@@ -144,7 +137,7 @@ function mergeRules(a, b) {
|
|
|
144
137
|
res[key] = merged;
|
|
145
138
|
}
|
|
146
139
|
}
|
|
147
|
-
|
|
140
|
+
deleteUndefProp(res);
|
|
148
141
|
return Object.freeze(res);
|
|
149
142
|
}
|
|
150
143
|
function optimizeRules(rules) {
|
|
@@ -161,8 +154,8 @@ function optimizeRule(rule) {
|
|
|
161
154
|
if (rule === undefined) {
|
|
162
155
|
return;
|
|
163
156
|
}
|
|
164
|
-
if (
|
|
157
|
+
if (isRuleConfigValue(rule)) {
|
|
165
158
|
return rule;
|
|
166
159
|
}
|
|
167
|
-
return
|
|
160
|
+
return cleanOptions(rule);
|
|
168
161
|
}
|
package/lib/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyRule, AnyRuleV2, PlainData, RuleConfig, RuleConfigV2, RuleConfigValue } from './types';
|
|
1
|
+
import type { AnyRule, AnyRuleV2, PlainData, RuleConfig, RuleConfigV2, RuleConfigValue } from './types.js';
|
|
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.
|
package/lib/utils.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const is_plain_object_1 = require("is-plain-object");
|
|
6
|
-
const mustache_1 = tslib_1.__importDefault(require("mustache"));
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { isPlainObject } from 'is-plain-object';
|
|
3
|
+
import mustache from 'mustache';
|
|
7
4
|
/**
|
|
8
5
|
* Return undefined if the template doesn't include the variable that is set as a property in data.
|
|
9
6
|
* But return template string without changes if it doesn't have a variable.
|
|
@@ -11,23 +8,21 @@ const mustache_1 = tslib_1.__importDefault(require("mustache"));
|
|
|
11
8
|
* @param template Mustache template string
|
|
12
9
|
* @param data Captured string for replacement
|
|
13
10
|
*/
|
|
14
|
-
function provideValue(template, data) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (ast.length === 1 && ((_a = ast[0]) === null || _a === void 0 ? void 0 : _a[0]) === 'text') {
|
|
11
|
+
export function provideValue(template, data) {
|
|
12
|
+
const ast = mustache.parse(template);
|
|
13
|
+
if (ast.length === 1 && ast[0]?.[0] === 'text') {
|
|
18
14
|
// It doesn't have a variable
|
|
19
15
|
return template;
|
|
20
16
|
}
|
|
21
|
-
const noDataResult =
|
|
22
|
-
const result =
|
|
17
|
+
const noDataResult = mustache.render(template, {});
|
|
18
|
+
const result = mustache.render(template, data);
|
|
23
19
|
// Assume variables are empty in the template if it matched.
|
|
24
20
|
if (noDataResult === result) {
|
|
25
21
|
return;
|
|
26
22
|
}
|
|
27
23
|
return result;
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
function exchangeValueOnRule(rule, data) {
|
|
25
|
+
export function exchangeValueOnRule(rule, data) {
|
|
31
26
|
if (isRuleConfigValue(rule)) {
|
|
32
27
|
return exchangeValue(rule, data);
|
|
33
28
|
}
|
|
@@ -60,8 +55,7 @@ function exchangeValueOnRule(rule, data) {
|
|
|
60
55
|
deleteUndefProp(result);
|
|
61
56
|
return result;
|
|
62
57
|
}
|
|
63
|
-
|
|
64
|
-
function cleanOptions(rule) {
|
|
58
|
+
export function cleanOptions(rule) {
|
|
65
59
|
const res = {
|
|
66
60
|
severity: rule.severity,
|
|
67
61
|
value: rule.value,
|
|
@@ -71,8 +65,7 @@ function cleanOptions(rule) {
|
|
|
71
65
|
deleteUndefProp(res);
|
|
72
66
|
return res;
|
|
73
67
|
}
|
|
74
|
-
|
|
75
|
-
function isRuleConfigValue(v) {
|
|
68
|
+
export function isRuleConfigValue(v) {
|
|
76
69
|
switch (typeof v) {
|
|
77
70
|
case 'string':
|
|
78
71
|
case 'number':
|
|
@@ -85,14 +78,13 @@ function isRuleConfigValue(v) {
|
|
|
85
78
|
}
|
|
86
79
|
return Array.isArray(v);
|
|
87
80
|
}
|
|
88
|
-
exports.isRuleConfigValue = isRuleConfigValue;
|
|
89
81
|
/**
|
|
90
82
|
*
|
|
91
83
|
* @param obj
|
|
92
84
|
* @returns
|
|
93
85
|
*/
|
|
94
|
-
function deleteUndefProp(obj) {
|
|
95
|
-
if (!
|
|
86
|
+
export function deleteUndefProp(obj) {
|
|
87
|
+
if (!isPlainObject(obj)) {
|
|
96
88
|
return;
|
|
97
89
|
}
|
|
98
90
|
for (const key in obj) {
|
|
@@ -101,7 +93,6 @@ function deleteUndefProp(obj) {
|
|
|
101
93
|
}
|
|
102
94
|
}
|
|
103
95
|
}
|
|
104
|
-
exports.deleteUndefProp = deleteUndefProp;
|
|
105
96
|
/**
|
|
106
97
|
* Return options from `options` or `option`
|
|
107
98
|
*
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/ml-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.2",
|
|
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>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"private": false,
|
|
9
|
-
"
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./lib/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
10
15
|
"types": "lib/index.d.ts",
|
|
11
16
|
"publishConfig": {
|
|
12
17
|
"access": "public"
|
|
@@ -19,14 +24,14 @@
|
|
|
19
24
|
"clean": "tsc --build --clean"
|
|
20
25
|
},
|
|
21
26
|
"dependencies": {
|
|
22
|
-
"@markuplint/ml-ast": "
|
|
23
|
-
"@markuplint/selector": "
|
|
24
|
-
"@markuplint/shared": "
|
|
25
|
-
"@types/mustache": "^4.2.
|
|
27
|
+
"@markuplint/ml-ast": "4.0.0-alpha.2",
|
|
28
|
+
"@markuplint/selector": "4.0.0-alpha.2",
|
|
29
|
+
"@markuplint/shared": "4.0.0-alpha.2",
|
|
30
|
+
"@types/mustache": "^4.2.3",
|
|
26
31
|
"deepmerge": "^4.3.1",
|
|
27
32
|
"is-plain-object": "^5.0.0",
|
|
28
33
|
"mustache": "^4.2.0",
|
|
29
|
-
"type-fest": "^4.
|
|
34
|
+
"type-fest": "^4.4.0"
|
|
30
35
|
},
|
|
31
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "51ad52c760435641f9bff8685707d8178b0787eb"
|
|
32
37
|
}
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
const { mergeConfig, mergeRule } = require('../lib/merge-config');
|
|
2
|
-
|
|
3
|
-
describe('mergeConfig', () => {
|
|
4
|
-
test('empty + empty', () => {
|
|
5
|
-
expect(mergeConfig({}, {})).toStrictEqual({});
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
test('plugins + plugins', () => {
|
|
9
|
-
expect(
|
|
10
|
-
mergeConfig(
|
|
11
|
-
{
|
|
12
|
-
plugins: ['a', 'b', 'c'],
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
plugins: ['c', 'b', 'd'],
|
|
16
|
-
},
|
|
17
|
-
),
|
|
18
|
-
).toStrictEqual({
|
|
19
|
-
plugins: ['a', 'b', 'c', 'd'],
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('plugins + plugins (with options)', () => {
|
|
24
|
-
expect(
|
|
25
|
-
mergeConfig(
|
|
26
|
-
{
|
|
27
|
-
plugins: ['a', 'b', { name: 'c', settings: { foo: 'foo', bar: 'bar' } }],
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
plugins: ['c', 'b', 'd', { name: 'c', settings: { foo2: 'foo2', bar: 'bar2' } }],
|
|
31
|
-
},
|
|
32
|
-
),
|
|
33
|
-
).toStrictEqual({
|
|
34
|
-
plugins: [
|
|
35
|
-
'a',
|
|
36
|
-
'b',
|
|
37
|
-
{
|
|
38
|
-
name: 'c',
|
|
39
|
-
settings: {
|
|
40
|
-
bar: 'bar2',
|
|
41
|
-
foo: 'foo',
|
|
42
|
-
foo2: 'foo2',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
'd',
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('parser + parser', () => {
|
|
51
|
-
expect(
|
|
52
|
-
mergeConfig(
|
|
53
|
-
{
|
|
54
|
-
parser: { '/\\.vue$/i': '@markuplint/vue-parser' },
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
parser: { '/\\.vue$/i': '@markuplint/vue-parser' },
|
|
58
|
-
},
|
|
59
|
-
),
|
|
60
|
-
).toStrictEqual({
|
|
61
|
-
parser: { '/\\.vue$/i': '@markuplint/vue-parser' },
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('parser + parser (2)', () => {
|
|
66
|
-
expect(
|
|
67
|
-
mergeConfig(
|
|
68
|
-
{
|
|
69
|
-
parser: { '/\\.vue$/i': '@markuplint/vue-parser' },
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
parser: { '/\\.[jt]sx?$/i': '@markuplint/jsx-parser' },
|
|
73
|
-
},
|
|
74
|
-
),
|
|
75
|
-
).toStrictEqual({
|
|
76
|
-
parser: {
|
|
77
|
-
'/\\.vue$/i': '@markuplint/vue-parser',
|
|
78
|
-
'/\\.[jt]sx?$/i': '@markuplint/jsx-parser',
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('overrides + overrides', () => {
|
|
84
|
-
expect(
|
|
85
|
-
mergeConfig(
|
|
86
|
-
{
|
|
87
|
-
overrides: {
|
|
88
|
-
a: {
|
|
89
|
-
rules: {
|
|
90
|
-
rule1: true,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
overrides: {
|
|
97
|
-
a: {
|
|
98
|
-
rules: {
|
|
99
|
-
rule1: false,
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
b: {
|
|
103
|
-
rules: {
|
|
104
|
-
rule1: true,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
),
|
|
110
|
-
).toStrictEqual({
|
|
111
|
-
overrides: {
|
|
112
|
-
a: {
|
|
113
|
-
rules: {
|
|
114
|
-
rule1: false,
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
b: {
|
|
118
|
-
rules: {
|
|
119
|
-
rule1: true,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test('rules + rules', () => {
|
|
127
|
-
expect(
|
|
128
|
-
mergeConfig(
|
|
129
|
-
{
|
|
130
|
-
rules: {
|
|
131
|
-
a: {
|
|
132
|
-
option: {
|
|
133
|
-
ruleA: true,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
rules: {
|
|
140
|
-
b: {
|
|
141
|
-
options: {
|
|
142
|
-
ruleB: true,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
),
|
|
148
|
-
).toStrictEqual({
|
|
149
|
-
rules: {
|
|
150
|
-
a: {
|
|
151
|
-
options: {
|
|
152
|
-
ruleA: true,
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
b: {
|
|
156
|
-
options: {
|
|
157
|
-
ruleB: true,
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test('rules[rule].value + rules[rule].value', () => {
|
|
165
|
-
expect(
|
|
166
|
-
mergeConfig(
|
|
167
|
-
{
|
|
168
|
-
rules: {
|
|
169
|
-
ruleA: true,
|
|
170
|
-
ruleB: [],
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
rules: {
|
|
175
|
-
ruleA: {
|
|
176
|
-
options: {
|
|
177
|
-
optionName: true,
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
ruleB: {
|
|
181
|
-
options: {
|
|
182
|
-
optionName: true,
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
),
|
|
188
|
-
).toStrictEqual({
|
|
189
|
-
rules: {
|
|
190
|
-
ruleA: {
|
|
191
|
-
value: true,
|
|
192
|
-
options: {
|
|
193
|
-
optionName: true,
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
ruleB: {
|
|
197
|
-
value: [],
|
|
198
|
-
options: {
|
|
199
|
-
optionName: true,
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
describe('mergeRule', () => {
|
|
208
|
-
test('{value} + shorthand', () => {
|
|
209
|
-
expect(
|
|
210
|
-
mergeRule(
|
|
211
|
-
{
|
|
212
|
-
value: true,
|
|
213
|
-
},
|
|
214
|
-
{},
|
|
215
|
-
),
|
|
216
|
-
).toStrictEqual({
|
|
217
|
-
value: true,
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test('{value} + shorthand (2)', () => {
|
|
222
|
-
expect(
|
|
223
|
-
mergeRule(
|
|
224
|
-
{
|
|
225
|
-
value: true,
|
|
226
|
-
},
|
|
227
|
-
false,
|
|
228
|
-
),
|
|
229
|
-
).toStrictEqual(false);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
test('{value} + shorthand (3)', () => {
|
|
233
|
-
expect(
|
|
234
|
-
mergeRule(
|
|
235
|
-
{
|
|
236
|
-
value: false,
|
|
237
|
-
},
|
|
238
|
-
true,
|
|
239
|
-
),
|
|
240
|
-
).toStrictEqual({
|
|
241
|
-
value: true,
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
test('{options} + {options}', () => {
|
|
246
|
-
expect(
|
|
247
|
-
mergeRule(
|
|
248
|
-
{
|
|
249
|
-
options: {
|
|
250
|
-
optional: 'OPTIONAL_VALUE',
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
options: {
|
|
255
|
-
optional: 'CHANGED_OPTIONAL_VALUE',
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
),
|
|
259
|
-
).toStrictEqual({
|
|
260
|
-
options: {
|
|
261
|
-
optional: 'CHANGED_OPTIONAL_VALUE',
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
test('{value} + empty', () => {
|
|
267
|
-
expect(
|
|
268
|
-
mergeRule(
|
|
269
|
-
{
|
|
270
|
-
value: [],
|
|
271
|
-
},
|
|
272
|
-
{},
|
|
273
|
-
),
|
|
274
|
-
).toStrictEqual({
|
|
275
|
-
value: [],
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
test('{value} + {options}', () => {
|
|
280
|
-
expect(
|
|
281
|
-
mergeRule(
|
|
282
|
-
{
|
|
283
|
-
value: [],
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
options: {},
|
|
287
|
-
},
|
|
288
|
-
),
|
|
289
|
-
).toStrictEqual({
|
|
290
|
-
value: [],
|
|
291
|
-
options: {},
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
});
|
package/test/utils.spec.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
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
|
-
});
|