@platformos/platformos-check-common 0.0.17 → 0.0.18
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/CHANGELOG.md +8 -0
- package/dist/checks/index.d.ts +1 -1
- package/dist/checks/index.js +6 -2
- package/dist/checks/index.js.map +1 -1
- package/dist/checks/json-literal-quote-style/index.d.ts +2 -0
- package/dist/checks/json-literal-quote-style/index.js +42 -0
- package/dist/checks/json-literal-quote-style/index.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.d.ts +21 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.js +60 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidOutputPush.d.ts +17 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidOutputPush.js +37 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidOutputPush.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.js +1 -1
- package/dist/checks/liquid-html-syntax-error/index.js +17 -0
- package/dist/checks/liquid-html-syntax-error/index.js.map +1 -1
- package/dist/checks/partial-call-arguments/extract-undefined-variables.d.ts +14 -0
- package/dist/checks/partial-call-arguments/extract-undefined-variables.js +234 -0
- package/dist/checks/partial-call-arguments/extract-undefined-variables.js.map +1 -0
- package/dist/checks/partial-call-arguments/index.d.ts +2 -0
- package/dist/checks/partial-call-arguments/index.js +117 -0
- package/dist/checks/partial-call-arguments/index.js.map +1 -0
- package/dist/checks/valid-frontmatter/index.d.ts +2 -0
- package/dist/checks/valid-frontmatter/index.js +279 -0
- package/dist/checks/valid-frontmatter/index.js.map +1 -0
- package/dist/frontmatter/index.d.ts +1 -59
- package/dist/frontmatter/index.js +6 -298
- package/dist/frontmatter/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/checks/index.ts +6 -2
- package/src/checks/json-literal-quote-style/index.spec.ts +129 -0
- package/src/checks/json-literal-quote-style/index.ts +45 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.spec.ts +422 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidAssignSyntax.ts +63 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidOutputPush.spec.ts +104 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidOutputPush.ts +39 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.spec.ts +86 -2
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.ts +1 -1
- package/src/checks/liquid-html-syntax-error/index.ts +19 -0
- package/src/checks/partial-call-arguments/extract-undefined-variables.spec.ts +218 -0
- package/src/checks/{metadata-params → partial-call-arguments}/extract-undefined-variables.ts +31 -6
- package/src/checks/partial-call-arguments/index.spec.ts +436 -0
- package/src/checks/{metadata-params → partial-call-arguments}/index.ts +18 -11
- package/src/checks/undefined-object/index.spec.ts +101 -0
- package/src/checks/valid-frontmatter/index.spec.ts +666 -0
- package/src/checks/valid-frontmatter/index.ts +344 -0
- package/src/frontmatter/index.ts +9 -344
- package/src/checks/metadata-params/extract-undefined-variables.spec.ts +0 -115
- package/src/checks/metadata-params/index.spec.ts +0 -257
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { extractUndefinedVariables } from './extract-undefined-variables';
|
|
3
|
-
|
|
4
|
-
describe('extractUndefinedVariables', () => {
|
|
5
|
-
it('should return variables used but not defined', () => {
|
|
6
|
-
const source = `{% liquid
|
|
7
|
-
assign b = a
|
|
8
|
-
%}
|
|
9
|
-
{{ b }}`;
|
|
10
|
-
const result = extractUndefinedVariables(source);
|
|
11
|
-
expect(result).to.deep.equal(['a']);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should not include assigned variables', () => {
|
|
15
|
-
const source = `{% assign x = 1 %}{{ x }}`;
|
|
16
|
-
const result = extractUndefinedVariables(source);
|
|
17
|
-
expect(result).to.deep.equal([]);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should not include captured variables', () => {
|
|
21
|
-
const source = `{% capture x %}hello{% endcapture %}{{ x }}`;
|
|
22
|
-
const result = extractUndefinedVariables(source);
|
|
23
|
-
expect(result).to.deep.equal([]);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should not include for loop variables', () => {
|
|
27
|
-
const source = `{% for item in items %}{{ item }}{% endfor %}`;
|
|
28
|
-
const result = extractUndefinedVariables(source);
|
|
29
|
-
expect(result).to.deep.equal(['items']);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should not include forloop variable', () => {
|
|
33
|
-
const source = `{% for item in items %}{{ forloop.index }}{% endfor %}`;
|
|
34
|
-
const result = extractUndefinedVariables(source);
|
|
35
|
-
expect(result).to.deep.equal(['items']);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should handle function result variables', () => {
|
|
39
|
-
const source = `{% function res = 'my_partial' %}{{ res }}`;
|
|
40
|
-
const result = extractUndefinedVariables(source);
|
|
41
|
-
expect(result).to.deep.equal([]);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should handle graphql result variables', () => {
|
|
45
|
-
const source = `{% graphql res = 'my_query' %}{{ res }}`;
|
|
46
|
-
const result = extractUndefinedVariables(source);
|
|
47
|
-
expect(result).to.deep.equal([]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should handle inline graphql result variables', () => {
|
|
51
|
-
const source = `{% graphql res %}{ users { id } }{% endgraphql %}{{ res }}`;
|
|
52
|
-
const result = extractUndefinedVariables(source);
|
|
53
|
-
expect(result).to.deep.equal([]);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should handle parse_json result variables', () => {
|
|
57
|
-
const source = `{% parse_json data %}{"a":1}{% endparse_json %}{{ data }}`;
|
|
58
|
-
const result = extractUndefinedVariables(source);
|
|
59
|
-
expect(result).to.deep.equal([]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should not include global objects', () => {
|
|
63
|
-
const source = `{{ context.session }}`;
|
|
64
|
-
const result = extractUndefinedVariables(source, [
|
|
65
|
-
'context',
|
|
66
|
-
'null',
|
|
67
|
-
'true',
|
|
68
|
-
'false',
|
|
69
|
-
'blank',
|
|
70
|
-
'empty',
|
|
71
|
-
]);
|
|
72
|
-
expect(result).to.deep.equal([]);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should deduplicate results', () => {
|
|
76
|
-
const source = `{{ a }}{{ a }}`;
|
|
77
|
-
const result = extractUndefinedVariables(source);
|
|
78
|
-
expect(result).to.deep.equal(['a']);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should return empty array if source fails to parse', () => {
|
|
82
|
-
const source = `{% invalid unclosed`;
|
|
83
|
-
const result = extractUndefinedVariables(source);
|
|
84
|
-
expect(result).to.deep.equal([]);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should handle increment/decrement as definitions', () => {
|
|
88
|
-
const source = `{% increment counter %}{{ counter }}`;
|
|
89
|
-
const result = extractUndefinedVariables(source);
|
|
90
|
-
expect(result).to.deep.equal([]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should handle background file-based result variables', () => {
|
|
94
|
-
const source = `{% background my_job = 'some_partial' %}{{ my_job }}`;
|
|
95
|
-
const result = extractUndefinedVariables(source);
|
|
96
|
-
expect(result).to.deep.equal([]);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should handle inline background tag without job_id', () => {
|
|
100
|
-
const source = `{% background source_name: 'my_task' %}echo "hello"{% endbackground %}{{ my_job }}`;
|
|
101
|
-
const result = extractUndefinedVariables(source);
|
|
102
|
-
expect(result).to.deep.equal(['my_job']);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should not include doc param names', () => {
|
|
106
|
-
const source = `
|
|
107
|
-
{% doc %}
|
|
108
|
-
@param {String} name - a name
|
|
109
|
-
{% enddoc %}
|
|
110
|
-
{{ name }}
|
|
111
|
-
`;
|
|
112
|
-
const result = extractUndefinedVariables(source);
|
|
113
|
-
expect(result).to.deep.equal(['name']);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { expect, describe, it } from 'vitest';
|
|
2
|
-
import { MetadataParamsCheck } from '.';
|
|
3
|
-
import { check } from '../../test';
|
|
4
|
-
|
|
5
|
-
describe('Module: MetadataParamsCheck', () => {
|
|
6
|
-
it('should use doc tag as complete param list when present', async () => {
|
|
7
|
-
const file = `
|
|
8
|
-
{% doc %}
|
|
9
|
-
@param {Number} variable - param with description
|
|
10
|
-
@param {Number} variable2 - param with description
|
|
11
|
-
{% enddoc %}
|
|
12
|
-
|
|
13
|
-
{% assign a = 5 | plus: variable | plus: variable2 %}
|
|
14
|
-
{{ a }}
|
|
15
|
-
`;
|
|
16
|
-
const file2 = `
|
|
17
|
-
{% function a = 'commands/call/fileToCall', variable: 2, variable2: 12 %}
|
|
18
|
-
{{ a }}
|
|
19
|
-
`;
|
|
20
|
-
const files = {
|
|
21
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
22
|
-
'app/lib/caller.liquid': file2,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
26
|
-
|
|
27
|
-
expect(offenses).to.have.length(0);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should report missing required doc params', async () => {
|
|
31
|
-
const file = `
|
|
32
|
-
{% doc %}
|
|
33
|
-
@param {Number} variable - param with description
|
|
34
|
-
@param {Number} variable2 - param with description
|
|
35
|
-
{% enddoc %}
|
|
36
|
-
|
|
37
|
-
{% assign a = 5 | plus: variable | plus: variable2 %}
|
|
38
|
-
{{ a }}
|
|
39
|
-
`;
|
|
40
|
-
const file2 = `
|
|
41
|
-
{% function a = 'commands/call/fileToCall', variable: 2 %}
|
|
42
|
-
{{ a }}
|
|
43
|
-
`;
|
|
44
|
-
const files = {
|
|
45
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
46
|
-
'app/lib/caller.liquid': file2,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
50
|
-
|
|
51
|
-
expect(offenses).to.have.length(1);
|
|
52
|
-
expect(offenses).to.containOffense(
|
|
53
|
-
'Required parameter variable2 must be passed to function call',
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should report unknown params not in doc', async () => {
|
|
58
|
-
const file = `
|
|
59
|
-
{% doc %}
|
|
60
|
-
@param {Number} variable - param with description
|
|
61
|
-
{% enddoc %}
|
|
62
|
-
|
|
63
|
-
{% assign a = 5 | plus: variable %}
|
|
64
|
-
{{ a }}
|
|
65
|
-
`;
|
|
66
|
-
const file2 = `
|
|
67
|
-
{% function a = 'commands/call/fileToCall', variable: 2, extra: 12 %}
|
|
68
|
-
{{ a }}
|
|
69
|
-
`;
|
|
70
|
-
const files = {
|
|
71
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
72
|
-
'app/lib/caller.liquid': file2,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
76
|
-
|
|
77
|
-
expect(offenses).to.have.length(1);
|
|
78
|
-
expect(offenses).to.containOffense('Unknown parameter extra passed to function call');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should allow doc-optional params without requiring them', async () => {
|
|
82
|
-
const file = `
|
|
83
|
-
{% doc %}
|
|
84
|
-
@param {String} a - required
|
|
85
|
-
@param {String} [b] - optional
|
|
86
|
-
{% enddoc %}
|
|
87
|
-
{{ a }}{{ b }}
|
|
88
|
-
`;
|
|
89
|
-
const file2 = `
|
|
90
|
-
{% function res = 'commands/call/fileToCall', a: 'hello' %}
|
|
91
|
-
{{ res }}
|
|
92
|
-
`;
|
|
93
|
-
const files = {
|
|
94
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
95
|
-
'app/lib/caller.liquid': file2,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
99
|
-
|
|
100
|
-
expect(offenses).to.have.length(0);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should allow passing doc-optional params without reporting unknown', async () => {
|
|
104
|
-
const file = `
|
|
105
|
-
{% doc %}
|
|
106
|
-
@param {String} a - required
|
|
107
|
-
@param {String} [b] - optional
|
|
108
|
-
{% enddoc %}
|
|
109
|
-
{{ a }}{{ b }}
|
|
110
|
-
`;
|
|
111
|
-
const file2 = `
|
|
112
|
-
{% function res = 'commands/call/fileToCall', a: 'hello', b: 'world' %}
|
|
113
|
-
{{ res }}
|
|
114
|
-
`;
|
|
115
|
-
const files = {
|
|
116
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
117
|
-
'app/lib/caller.liquid': file2,
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
121
|
-
|
|
122
|
-
expect(offenses).to.have.length(0);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('should not require doc params that are not used in source', async () => {
|
|
126
|
-
const file = `
|
|
127
|
-
{% doc %}
|
|
128
|
-
@param {String} a - required param
|
|
129
|
-
@param {String} unused - required but not used in source
|
|
130
|
-
{% enddoc %}
|
|
131
|
-
{{ a }}
|
|
132
|
-
`;
|
|
133
|
-
const file2 = `
|
|
134
|
-
{% function res = 'commands/call/fileToCall', a: 'hello' %}
|
|
135
|
-
{{ res }}
|
|
136
|
-
`;
|
|
137
|
-
const files = {
|
|
138
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
139
|
-
'app/lib/caller.liquid': file2,
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
143
|
-
|
|
144
|
-
expect(offenses).to.have.length(0);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('should infer required params from undefined variables when no doc', async () => {
|
|
148
|
-
const file = `
|
|
149
|
-
{% assign b = a %}
|
|
150
|
-
{{ b }}
|
|
151
|
-
`;
|
|
152
|
-
const file2 = `
|
|
153
|
-
{% function res = 'commands/call/fileToCall', a: 'hello' %}
|
|
154
|
-
{{ res }}
|
|
155
|
-
`;
|
|
156
|
-
const files = {
|
|
157
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
158
|
-
'app/lib/caller.liquid': file2,
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
162
|
-
|
|
163
|
-
expect(offenses).to.have.length(0);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should report missing inferred params when no doc', async () => {
|
|
167
|
-
const file = `
|
|
168
|
-
{% assign b = a %}
|
|
169
|
-
{{ b }}
|
|
170
|
-
`;
|
|
171
|
-
const file2 = `
|
|
172
|
-
{% function res = 'commands/call/fileToCall' %}
|
|
173
|
-
{{ res }}
|
|
174
|
-
`;
|
|
175
|
-
const files = {
|
|
176
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
177
|
-
'app/lib/caller.liquid': file2,
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
181
|
-
|
|
182
|
-
expect(offenses).to.have.length(1);
|
|
183
|
-
expect(offenses).to.containOffense('Required parameter a must be passed to function call');
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should report unknown params when passing args not in inferred set', async () => {
|
|
187
|
-
const file = `
|
|
188
|
-
{% assign b = a %}
|
|
189
|
-
{{ b }}
|
|
190
|
-
`;
|
|
191
|
-
const file2 = `
|
|
192
|
-
{% function res = 'commands/call/fileToCall', a: 'hello', extra: 'world' %}
|
|
193
|
-
{{ res }}
|
|
194
|
-
`;
|
|
195
|
-
const files = {
|
|
196
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
197
|
-
'app/lib/caller.liquid': file2,
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
201
|
-
|
|
202
|
-
expect(offenses).to.have.length(1);
|
|
203
|
-
expect(offenses).to.containOffense('Unknown parameter extra passed to function call');
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('should not include global objects like context in inferred params', async () => {
|
|
207
|
-
const file = `
|
|
208
|
-
{{ context.session }}
|
|
209
|
-
{{ a }}
|
|
210
|
-
`;
|
|
211
|
-
const file2 = `
|
|
212
|
-
{% function res = 'commands/call/fileToCall', a: 'hello' %}
|
|
213
|
-
{{ res }}
|
|
214
|
-
`;
|
|
215
|
-
const files = {
|
|
216
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
217
|
-
'app/lib/caller.liquid': file2,
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
221
|
-
|
|
222
|
-
expect(offenses).to.have.length(0);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it('should work with render tags too', async () => {
|
|
226
|
-
const file = `{{ a }}`;
|
|
227
|
-
const file2 = `{% render 'fileToRender' %}`;
|
|
228
|
-
const files = {
|
|
229
|
-
'app/views/partials/fileToRender.liquid': file,
|
|
230
|
-
'app/views/pages/caller.liquid': file2,
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
234
|
-
|
|
235
|
-
expect(offenses).to.have.length(1);
|
|
236
|
-
expect(offenses).to.containOffense('Required parameter a must be passed to render call');
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it('should skip validation when no doc and no undefined vars', async () => {
|
|
240
|
-
const file = `
|
|
241
|
-
{% assign a = 5 %}
|
|
242
|
-
{{ a }}
|
|
243
|
-
`;
|
|
244
|
-
const file2 = `
|
|
245
|
-
{% function res = 'commands/call/fileToCall', extra: 'hello' %}
|
|
246
|
-
{{ res }}
|
|
247
|
-
`;
|
|
248
|
-
const files = {
|
|
249
|
-
'app/lib/commands/call/fileToCall.liquid': file,
|
|
250
|
-
'app/lib/caller.liquid': file2,
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
const offenses = await check(files, [MetadataParamsCheck]);
|
|
254
|
-
|
|
255
|
-
expect(offenses).to.have.length(0);
|
|
256
|
-
});
|
|
257
|
-
});
|