@platformos/platformos-check-common 0.0.8 → 0.0.9
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/README.md +4 -4
- package/dist/checks/graphql-variables/index.js +4 -0
- package/dist/checks/graphql-variables/index.js.map +1 -1
- package/dist/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.js +1 -1
- package/dist/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.js.map +1 -1
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.d.ts +19 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.js +79 -0
- package/dist/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/checks/UnknownTag.d.ts +3 -0
- package/dist/checks/liquid-html-syntax-error/checks/UnknownTag.js +32 -0
- package/dist/checks/liquid-html-syntax-error/checks/UnknownTag.js.map +1 -0
- package/dist/checks/liquid-html-syntax-error/index.js +21 -3
- package/dist/checks/liquid-html-syntax-error/index.js.map +1 -1
- package/dist/checks/matching-translations/index.js +103 -68
- package/dist/checks/matching-translations/index.js.map +1 -1
- package/dist/checks/undefined-object/index.js +6 -1
- package/dist/checks/undefined-object/index.js.map +1 -1
- package/dist/context-utils.d.ts +16 -0
- package/dist/context-utils.js +30 -1
- package/dist/context-utils.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/liquid-doc/arguments.js +8 -1
- package/dist/liquid-doc/arguments.js.map +1 -1
- package/dist/liquid-doc/utils.d.ts +2 -2
- package/dist/liquid-doc/utils.js +10 -0
- package/dist/liquid-doc/utils.js.map +1 -1
- package/dist/path.d.ts +1 -1
- package/dist/path.js +12 -1
- package/dist/path.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
- package/src/checks/duplicate-render-partial-arguments/index.spec.ts +12 -12
- package/src/checks/graphql-variables/index.spec.ts +95 -0
- package/src/checks/graphql-variables/index.ts +4 -0
- package/src/checks/img-width-and-height/index.ts +1 -1
- package/src/checks/invalid-hash-assign-target/index.spec.ts +26 -26
- package/src/checks/json-syntax-error/index.ts +1 -1
- package/src/checks/liquid-html-syntax-error/checks/InvalidLoopArguments.ts +2 -2
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.spec.ts +259 -0
- package/src/checks/liquid-html-syntax-error/checks/InvalidTagSyntax.ts +89 -0
- package/src/checks/liquid-html-syntax-error/checks/UnknownTag.spec.ts +293 -0
- package/src/checks/liquid-html-syntax-error/checks/UnknownTag.ts +43 -0
- package/src/checks/liquid-html-syntax-error/index.ts +24 -3
- package/src/checks/matching-translations/index.spec.ts +114 -24
- package/src/checks/matching-translations/index.ts +102 -81
- package/src/checks/metadata-params/index.ts +1 -1
- package/src/checks/missing-partial/index.ts +6 -6
- package/src/checks/undefined-object/index.spec.ts +29 -2
- package/src/checks/undefined-object/index.ts +7 -1
- package/src/checks/unused-assign/index.ts +1 -1
- package/src/checks/valid-json/index.ts +1 -1
- package/src/checks/valid-render-partial-argument-types/index.spec.ts +13 -13
- package/src/context-utils.ts +42 -1
- package/src/disabled-checks/index.spec.ts +26 -61
- package/src/disabled-checks/index.ts +2 -4
- package/src/disabled-checks/test-checks.ts +4 -4
- package/src/ignore.spec.ts +4 -4
- package/src/index.ts +18 -0
- package/src/liquid-doc/arguments.ts +9 -3
- package/src/liquid-doc/liquidDoc.spec.ts +1 -1
- package/src/liquid-doc/utils.ts +13 -5
- package/src/path.ts +16 -1
- package/src/test/MockApp.ts +2 -2
- package/src/test/MockFileSystem.spec.ts +10 -11
- package/src/test/contain-offense.spec.ts +11 -3
- package/src/test/test-helper.ts +24 -28
- package/src/types.ts +8 -0
- package/src/visitor.spec.ts +2 -2
- package/src/types/schemas/index.ts +0 -3
- package/src/types/schemas/preset.ts +0 -52
- package/src/types/schemas/setting.ts +0 -320
- package/src/types/schemas/template.ts +0 -34
package/dist/types.d.ts
CHANGED
|
@@ -274,6 +274,14 @@ export interface AugmentedDependencies extends Dependencies {
|
|
|
274
274
|
fileSize: (uri: UriString) => Promise<number>;
|
|
275
275
|
getDefaultLocale: () => Promise<string>;
|
|
276
276
|
getDefaultTranslations(): Promise<Translations>;
|
|
277
|
+
/**
|
|
278
|
+
* Aggregates ALL translation files for `locale` within the given translations
|
|
279
|
+
* base directory (e.g. `file:///app/translations` or
|
|
280
|
+
* `file:///modules/common-styling/public/translations`).
|
|
281
|
+
*
|
|
282
|
+
* Covers both `{base}/{locale}.yml` and `{base}/{locale}/*.yml`.
|
|
283
|
+
*/
|
|
284
|
+
getTranslationsForBase(translationBaseUri: string, locale: string): Promise<Translations>;
|
|
277
285
|
}
|
|
278
286
|
type StaticContextProperties<T extends SourceCodeType> = T extends SourceCodeType ? {
|
|
279
287
|
report(problem: Problem<T>): void;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uEAAkG;AAwEzE,oGAxEa,8BAAmB,OAwEb;AAnD5C,gDAA8B;AAC9B,8DAA4C;AAC5C,iEAA+C;AAExC,MAAM,YAAY,GAAG,CAAC,IAAc,EAAsB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC;AAA/E,QAAA,YAAY,gBAAmE;AACrF,MAAM,WAAW,GAAG,CAAC,IAAc,EAAqB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;AAA5E,QAAA,WAAW,eAAiE;AAClF,MAAM,cAAc,GAAG,CAAC,IAAc,EAAwB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,UAAU,CAAC;AAArF,QAAA,cAAc,kBAAuE;AAC3F,MAAM,WAAW,GAAG,CAAC,IAAc,EAAqB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;AAA5E,QAAA,WAAW,eAAiE;AAClF,MAAM,aAAa,GAAG,CAAC,IAAc,EAAuB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,SAAS,CAAC;AAAlF,QAAA,aAAa,iBAAqE;AAkB/F,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,+BAAa,CAAA;IACb,2CAAyB,CAAA;IACzB,qCAAmB,CAAA;IACnB,+BAAa,CAAA;AACf,CAAC,EALW,cAAc,8BAAd,cAAc,QAKzB;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uEAAkG;AAwEzE,oGAxEa,8BAAmB,OAwEb;AAnD5C,gDAA8B;AAC9B,8DAA4C;AAC5C,iEAA+C;AAExC,MAAM,YAAY,GAAG,CAAC,IAAc,EAAsB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC;AAA/E,QAAA,YAAY,gBAAmE;AACrF,MAAM,WAAW,GAAG,CAAC,IAAc,EAAqB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;AAA5E,QAAA,WAAW,eAAiE;AAClF,MAAM,cAAc,GAAG,CAAC,IAAc,EAAwB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,UAAU,CAAC;AAArF,QAAA,cAAc,kBAAuE;AAC3F,MAAM,WAAW,GAAG,CAAC,IAAc,EAAqB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;AAA5E,QAAA,WAAW,eAAiE;AAClF,MAAM,aAAa,GAAG,CAAC,IAAc,EAAuB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,SAAS,CAAC;AAAlF,QAAA,aAAa,iBAAqE;AAkB/F,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,+BAAa,CAAA;IACb,2CAAyB,CAAA;IACzB,qCAAmB,CAAA;IACnB,+BAAa,CAAA;AACf,CAAC,EALW,cAAc,8BAAd,cAAc,QAKzB;AA0eD,gEAAgE;AAChE,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,yCAAS,CAAA;IACT,6CAAW,CAAA;IACX,uCAAQ,CAAA;AACV,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB;AAED,+CAA+C;AAC/C,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2BAAW,CAAA;IACX,2CAA2B,CAAA;AAC7B,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformos/platformos-check-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"type-check": "tsc --noEmit"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@platformos/liquid-html-parser": "0.0.
|
|
29
|
+
"@platformos/liquid-html-parser": "0.0.9",
|
|
30
30
|
"graphql": "^16.12.0",
|
|
31
31
|
"js-yaml": "^4.1.1",
|
|
32
32
|
"jsonc-parser": "^3.3.1",
|
|
@@ -10,7 +10,7 @@ describe('Module: DuplicateRenderPartialArguments', () => {
|
|
|
10
10
|
describe('detection', () => {
|
|
11
11
|
it('should report duplicate arguments in render tags', async () => {
|
|
12
12
|
const sourceCode = `
|
|
13
|
-
{% render '
|
|
13
|
+
{% render 'partial', param1: 'value1', param2: 'value2', param1: 'value3' %}
|
|
14
14
|
`;
|
|
15
15
|
|
|
16
16
|
const offenses = await runCheck(sourceCode);
|
|
@@ -24,7 +24,7 @@ describe('Module: DuplicateRenderPartialArguments', () => {
|
|
|
24
24
|
|
|
25
25
|
it('should report multiple duplicate arguments in render tags', async () => {
|
|
26
26
|
const sourceCode = `
|
|
27
|
-
{% render '
|
|
27
|
+
{% render 'partial', param1: 'value1', param2: 'value2', param1: 'value3', param2: 'value4', param1: 'value5' %}
|
|
28
28
|
`;
|
|
29
29
|
|
|
30
30
|
const offenses = await runCheck(sourceCode);
|
|
@@ -40,7 +40,7 @@ describe('Module: DuplicateRenderPartialArguments', () => {
|
|
|
40
40
|
|
|
41
41
|
it('should not report when render tag is using `with/for` alias syntax', async () => {
|
|
42
42
|
const sourceCode = `
|
|
43
|
-
{% render '
|
|
43
|
+
{% render 'partial' with 'string' as param1, param1: 'value1' %}
|
|
44
44
|
`;
|
|
45
45
|
|
|
46
46
|
const offenses = await runCheck(sourceCode);
|
|
@@ -52,7 +52,7 @@ describe('Module: DuplicateRenderPartialArguments', () => {
|
|
|
52
52
|
|
|
53
53
|
describe('suggestions', () => {
|
|
54
54
|
it('should correctly suggest fixing all duplicate arguments except for the first', async () => {
|
|
55
|
-
const sourceCode = `{% render '
|
|
55
|
+
const sourceCode = `{% render 'partial', param1: 'value1', param2: 'value2', param1: 'value3', param1: 'value4' %}`;
|
|
56
56
|
const offenses = await runCheck(sourceCode);
|
|
57
57
|
|
|
58
58
|
expect(offenses).toHaveLength(2);
|
|
@@ -60,18 +60,18 @@ describe('Module: DuplicateRenderPartialArguments', () => {
|
|
|
60
60
|
expect(offenses[1].start.index).toBe(sourceCode.indexOf("param1: 'value4'"));
|
|
61
61
|
const suggestionResult = applySuggestions(sourceCode, offenses[0]);
|
|
62
62
|
expect(suggestionResult).toEqual([
|
|
63
|
-
`{% render '
|
|
63
|
+
`{% render 'partial', param1: 'value1', param2: 'value2', param1: 'value4' %}`,
|
|
64
64
|
]);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it('should suggest removing duplicates when with / for alias is used', async () => {
|
|
68
|
-
const sourceCode = `{% render '
|
|
68
|
+
const sourceCode = `{% render 'partial' with 'string' as param2, param1: 'value1', param2: 'value2' %}`;
|
|
69
69
|
const offenses = await runCheck(sourceCode);
|
|
70
70
|
|
|
71
71
|
expect(offenses).toHaveLength(1);
|
|
72
72
|
const suggestionResult = applySuggestions(sourceCode, offenses[0]);
|
|
73
73
|
expect(suggestionResult).toEqual([
|
|
74
|
-
`{% render '
|
|
74
|
+
`{% render 'partial' with 'string' as param2, param1: 'value1' %}`,
|
|
75
75
|
]);
|
|
76
76
|
});
|
|
77
77
|
});
|
|
@@ -79,7 +79,7 @@ describe('Module: DuplicateRenderPartialArguments', () => {
|
|
|
79
79
|
describe('edge cases', () => {
|
|
80
80
|
it('should not report when there are no duplicate arguments', async () => {
|
|
81
81
|
const sourceCode = `
|
|
82
|
-
{% render '
|
|
82
|
+
{% render 'partial', param1: 'value1', param2: 'value2', param3: 'value3' %}
|
|
83
83
|
`;
|
|
84
84
|
|
|
85
85
|
const offenses = await runCheck(sourceCode);
|
|
@@ -99,8 +99,8 @@ describe('Module: DuplicateRenderPartialArguments', () => {
|
|
|
99
99
|
|
|
100
100
|
it('should handle remove duplicate param when there are multiple render tags', async () => {
|
|
101
101
|
const sourceCode = `
|
|
102
|
-
{% render '
|
|
103
|
-
{% render '
|
|
102
|
+
{% render 'partial', param1: 'value1', param2: 'value2', param3: 'value3' %}
|
|
103
|
+
{% render 'partial', param1: 'value4', param2: 'value5', param1: 'value6' %}
|
|
104
104
|
`;
|
|
105
105
|
|
|
106
106
|
const offenses = await runCheck(sourceCode);
|
|
@@ -111,8 +111,8 @@ describe('Module: DuplicateRenderPartialArguments', () => {
|
|
|
111
111
|
const suggestionResult = applySuggestions(sourceCode, offenses[0]);
|
|
112
112
|
expect(suggestionResult).toEqual([
|
|
113
113
|
`
|
|
114
|
-
{% render '
|
|
115
|
-
{% render '
|
|
114
|
+
{% render 'partial', param1: 'value1', param2: 'value2', param3: 'value3' %}
|
|
115
|
+
{% render 'partial', param1: 'value4', param2: 'value5' %}
|
|
116
116
|
`,
|
|
117
117
|
]);
|
|
118
118
|
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { expect, describe, it } from 'vitest';
|
|
2
|
+
import { GraphQLVariablesCheck } from '.';
|
|
3
|
+
import { check } from '../../test';
|
|
4
|
+
|
|
5
|
+
const GRAPHQL_WITH_REQUIRED = `
|
|
6
|
+
query MyQuery($content: String!) {
|
|
7
|
+
records(filter: { table: { value: "posts" } }) {
|
|
8
|
+
results {
|
|
9
|
+
id
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
const GRAPHQL_WITH_OPTIONAL = `
|
|
16
|
+
query MyQuery($content: String) {
|
|
17
|
+
records(filter: { table: { value: "posts" } }) {
|
|
18
|
+
results {
|
|
19
|
+
id
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
describe('Module: GraphQLVariablesCheck', () => {
|
|
26
|
+
it('reports a missing required parameter', async () => {
|
|
27
|
+
const files = {
|
|
28
|
+
'app/views/partials/page.liquid': `{% graphql r = 'create' %}`,
|
|
29
|
+
'app/graphql/create.graphql': GRAPHQL_WITH_REQUIRED,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const offenses = await check(files, [GraphQLVariablesCheck]);
|
|
33
|
+
|
|
34
|
+
expect(offenses).to.have.length(1);
|
|
35
|
+
expect(offenses[0].message).to.equal(
|
|
36
|
+
'Required parameter content must be passed to GraphQL call',
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('does not report when all required parameters are provided', async () => {
|
|
41
|
+
const files = {
|
|
42
|
+
'app/views/partials/page.liquid': `{% graphql r = 'create', content: 'hello' %}`,
|
|
43
|
+
'app/graphql/create.graphql': GRAPHQL_WITH_REQUIRED,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const offenses = await check(files, [GraphQLVariablesCheck]);
|
|
47
|
+
|
|
48
|
+
expect(offenses).to.be.empty;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('does not report when the parameter is optional', async () => {
|
|
52
|
+
const files = {
|
|
53
|
+
'app/views/partials/page.liquid': `{% graphql r = 'create' %}`,
|
|
54
|
+
'app/graphql/create.graphql': GRAPHQL_WITH_OPTIONAL,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const offenses = await check(files, [GraphQLVariablesCheck]);
|
|
58
|
+
|
|
59
|
+
expect(offenses).to.be.empty;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('does not report when args is used (hash splat)', async () => {
|
|
63
|
+
const files = {
|
|
64
|
+
'app/views/partials/page.liquid': `{% graphql r = 'create', args: object %}`,
|
|
65
|
+
'app/graphql/create.graphql': GRAPHQL_WITH_REQUIRED,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const offenses = await check(files, [GraphQLVariablesCheck]);
|
|
69
|
+
|
|
70
|
+
expect(offenses).to.be.empty;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('does not report unknown parameter when args is used', async () => {
|
|
74
|
+
const files = {
|
|
75
|
+
'app/views/partials/page.liquid': `{% graphql r = 'create', args: object, extra: 'x' %}`,
|
|
76
|
+
'app/graphql/create.graphql': GRAPHQL_WITH_REQUIRED,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const offenses = await check(files, [GraphQLVariablesCheck]);
|
|
80
|
+
|
|
81
|
+
expect(offenses).to.be.empty;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('reports an unknown parameter when args is not used', async () => {
|
|
85
|
+
const files = {
|
|
86
|
+
'app/views/partials/page.liquid': `{% graphql r = 'create', content: 'hello', unknown: 'x' %}`,
|
|
87
|
+
'app/graphql/create.graphql': GRAPHQL_WITH_REQUIRED,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const offenses = await check(files, [GraphQLVariablesCheck]);
|
|
91
|
+
|
|
92
|
+
expect(offenses).to.have.length(1);
|
|
93
|
+
expect(offenses[0].message).to.equal('Unknown parameter unknown passed to GraphQL call');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -64,6 +64,10 @@ export const GraphQLVariablesCheck: LiquidCheckDefinition = {
|
|
|
64
64
|
args: LiquidNamedArgument[],
|
|
65
65
|
position: Position,
|
|
66
66
|
) => {
|
|
67
|
+
// `args` is a special parameter that splats a hash as all GraphQL variables
|
|
68
|
+
// at runtime — we can't know which keys will be provided statically.
|
|
69
|
+
if (args.some((arg) => arg.name === 'args')) return;
|
|
70
|
+
|
|
67
71
|
const locatedFile = await locator.locate(
|
|
68
72
|
URI.parse(context.config.rootUri),
|
|
69
73
|
'graphql',
|
|
@@ -7,7 +7,7 @@ export const ImgWidthAndHeight: LiquidCheckDefinition = {
|
|
|
7
7
|
name: 'Width and height attributes on image tags',
|
|
8
8
|
docs: {
|
|
9
9
|
description:
|
|
10
|
-
'This check is aimed at eliminating content layout shift
|
|
10
|
+
'This check is aimed at eliminating content layout shift by enforcing the use of the width and height attributes on img tags.',
|
|
11
11
|
recommended: true,
|
|
12
12
|
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/img-width-and-height',
|
|
13
13
|
},
|
|
@@ -4,72 +4,72 @@ import { check, MockApp } from '../../test';
|
|
|
4
4
|
|
|
5
5
|
describe('Module: InvalidHashAssignTarget', () => {
|
|
6
6
|
it('should report an error when hash_assign is used on a number', async () => {
|
|
7
|
-
const
|
|
7
|
+
const app: MockApp = {
|
|
8
8
|
'file.liquid': `
|
|
9
9
|
{% assign x = 10 %}
|
|
10
10
|
{% hash_assign x['key'] = 'value' %}
|
|
11
11
|
`,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const offenses = await check(
|
|
14
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
15
15
|
expect(offenses).toHaveLength(1);
|
|
16
16
|
expect(offenses[0].message).toContain('number');
|
|
17
17
|
expect(offenses[0].message).toContain('hash_assign');
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
it('should report an error when hash_assign is used on a string', async () => {
|
|
21
|
-
const
|
|
21
|
+
const app: MockApp = {
|
|
22
22
|
'file.liquid': `
|
|
23
23
|
{% assign x = 'hello' %}
|
|
24
24
|
{% hash_assign x['key'] = 'value' %}
|
|
25
25
|
`,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const offenses = await check(
|
|
28
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
29
29
|
expect(offenses).toHaveLength(1);
|
|
30
30
|
expect(offenses[0].message).toContain('string');
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
it('should report an error when hash_assign is used on a boolean', async () => {
|
|
34
|
-
const
|
|
34
|
+
const app: MockApp = {
|
|
35
35
|
'file.liquid': `
|
|
36
36
|
{% assign x = true %}
|
|
37
37
|
{% hash_assign x['key'] = 'value' %}
|
|
38
38
|
`,
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
const offenses = await check(
|
|
41
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
42
42
|
expect(offenses).toHaveLength(1);
|
|
43
43
|
expect(offenses[0].message).toContain('boolean');
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
it('should report an error when hash_assign is used on an array (range)', async () => {
|
|
47
|
-
const
|
|
47
|
+
const app: MockApp = {
|
|
48
48
|
'file.liquid': `
|
|
49
49
|
{% assign x = (1..5) %}
|
|
50
50
|
{% hash_assign x['key'] = 'value' %}
|
|
51
51
|
`,
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
const offenses = await check(
|
|
54
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
55
55
|
expect(offenses).toHaveLength(1);
|
|
56
56
|
expect(offenses[0].message).toContain('array');
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
it('should not report an error when hash_assign is used on an object from parse_json', async () => {
|
|
60
|
-
const
|
|
60
|
+
const app: MockApp = {
|
|
61
61
|
'file.liquid': `
|
|
62
62
|
{% assign x = '{}' | parse_json %}
|
|
63
63
|
{% hash_assign x['key'] = 'value' %}
|
|
64
64
|
`,
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
const offenses = await check(
|
|
67
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
68
68
|
expect(offenses).toHaveLength(0);
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
it('should not report an error when hash_assign is used on an object from parse_json tag', async () => {
|
|
72
|
-
const
|
|
72
|
+
const app: MockApp = {
|
|
73
73
|
'file.liquid': `
|
|
74
74
|
{% parse_json x %}
|
|
75
75
|
{}
|
|
@@ -78,12 +78,12 @@ describe('Module: InvalidHashAssignTarget', () => {
|
|
|
78
78
|
`,
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
-
const offenses = await check(
|
|
81
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
82
82
|
expect(offenses).toHaveLength(0);
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
it('should not report an error when hash_assign is used on an object from graphql', async () => {
|
|
86
|
-
const
|
|
86
|
+
const app: MockApp = {
|
|
87
87
|
'file.liquid': `
|
|
88
88
|
{% graphql result %}
|
|
89
89
|
query { user { id } }
|
|
@@ -92,35 +92,35 @@ describe('Module: InvalidHashAssignTarget', () => {
|
|
|
92
92
|
`,
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
const offenses = await check(
|
|
95
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
96
96
|
expect(offenses).toHaveLength(0);
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
it('should not report an error when hash_assign is used on an untyped variable', async () => {
|
|
100
|
-
const
|
|
100
|
+
const app: MockApp = {
|
|
101
101
|
'file.liquid': `
|
|
102
102
|
{% hash_assign unknown_var['key'] = 'value' %}
|
|
103
103
|
`,
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
const offenses = await check(
|
|
106
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
107
107
|
expect(offenses).toHaveLength(0);
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
it('should not report an error when hash_assign is used on a function return', async () => {
|
|
111
|
-
const
|
|
111
|
+
const app: MockApp = {
|
|
112
112
|
'file.liquid': `
|
|
113
113
|
{% function data = 'lib/get_data' %}
|
|
114
114
|
{% hash_assign data['extra'] = 'value' %}
|
|
115
115
|
`,
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
const offenses = await check(
|
|
118
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
119
119
|
expect(offenses).toHaveLength(0);
|
|
120
120
|
});
|
|
121
121
|
|
|
122
122
|
it('should track reassignment and report error on new type', async () => {
|
|
123
|
-
const
|
|
123
|
+
const app: MockApp = {
|
|
124
124
|
'file.liquid': `
|
|
125
125
|
{% assign x = '{}' | parse_json %}
|
|
126
126
|
{% hash_assign x['key1'] = 'value1' %}
|
|
@@ -129,39 +129,39 @@ describe('Module: InvalidHashAssignTarget', () => {
|
|
|
129
129
|
`,
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
const offenses = await check(
|
|
132
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
133
133
|
expect(offenses).toHaveLength(1);
|
|
134
134
|
expect(offenses[0].message).toContain('number');
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
it('should handle increment/decrement as numbers', async () => {
|
|
138
|
-
const
|
|
138
|
+
const app: MockApp = {
|
|
139
139
|
'file.liquid': `
|
|
140
140
|
{% increment counter %}
|
|
141
141
|
{% hash_assign counter['key'] = 'value' %}
|
|
142
142
|
`,
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
-
const offenses = await check(
|
|
145
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
146
146
|
expect(offenses).toHaveLength(1);
|
|
147
147
|
expect(offenses[0].message).toContain('number');
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
it('should handle capture as string', async () => {
|
|
151
|
-
const
|
|
151
|
+
const app: MockApp = {
|
|
152
152
|
'file.liquid': `
|
|
153
153
|
{% capture x %}hello{% endcapture %}
|
|
154
154
|
{% hash_assign x['key'] = 'value' %}
|
|
155
155
|
`,
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
-
const offenses = await check(
|
|
158
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
159
159
|
expect(offenses).toHaveLength(1);
|
|
160
160
|
expect(offenses[0].message).toContain('string');
|
|
161
161
|
});
|
|
162
162
|
|
|
163
163
|
it('should allow multiple hash_assign on same object', async () => {
|
|
164
|
-
const
|
|
164
|
+
const app: MockApp = {
|
|
165
165
|
'file.liquid': `
|
|
166
166
|
{% assign x = '{}' | parse_json %}
|
|
167
167
|
{% hash_assign x['key1'] = 'value1' %}
|
|
@@ -170,7 +170,7 @@ describe('Module: InvalidHashAssignTarget', () => {
|
|
|
170
170
|
`,
|
|
171
171
|
};
|
|
172
172
|
|
|
173
|
-
const offenses = await check(
|
|
173
|
+
const offenses = await check(app, [InvalidHashAssignTarget]);
|
|
174
174
|
expect(offenses).toHaveLength(0);
|
|
175
175
|
});
|
|
176
176
|
});
|
|
@@ -13,7 +13,7 @@ export const JSONSyntaxError: JSONCheckDefinition = {
|
|
|
13
13
|
code: 'JSONSyntaxError',
|
|
14
14
|
name: 'Enforce valid JSON',
|
|
15
15
|
docs: {
|
|
16
|
-
description: 'This check exists to prevent invalid JSON files in
|
|
16
|
+
description: 'This check exists to prevent invalid JSON files in apps.',
|
|
17
17
|
recommended: true,
|
|
18
18
|
url: 'https://documentation.platformos.com/developer-guide/platformos-check/checks/json-syntax-error',
|
|
19
19
|
},
|
|
@@ -101,13 +101,13 @@ export function detectInvalidLoopArguments(
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
function isSupportedTagArgument(
|
|
104
|
-
tags: TagEntry[],
|
|
104
|
+
tags: TagEntry[] | undefined,
|
|
105
105
|
tagName: string,
|
|
106
106
|
key: string,
|
|
107
107
|
positional: boolean,
|
|
108
108
|
) {
|
|
109
109
|
return (
|
|
110
|
-
tags
|
|
110
|
+
(tags ?? [])
|
|
111
111
|
.find((tag) => tag.name === tagName)
|
|
112
112
|
?.parameters?.some(
|
|
113
113
|
(parameter) => parameter.name === key && parameter.positional === positional,
|