@salesforcedevs/sfdocs-liquid-lint-capture 0.0.4-alpha → 0.0.6-alpha
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/README.md +45 -142
- package/coverage/clover.xml +30 -0
- package/coverage/coverage-final.json +2 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +116 -0
- package/coverage/lcov-report/index.ts.html +277 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +45 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -37
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/index.test.ts +175 -258
- package/src/index.ts +15 -47
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
TN:
|
|
2
|
+
SF:src/index.ts
|
|
3
|
+
FN:20,isInPartialsFolder
|
|
4
|
+
FN:24,extractCaptureBlocks
|
|
5
|
+
FN:40,checkLiquidCapture
|
|
6
|
+
FNF:3
|
|
7
|
+
FNH:3
|
|
8
|
+
FNDA:31,isInPartialsFolder
|
|
9
|
+
FNDA:19,extractCaptureBlocks
|
|
10
|
+
FNDA:32,checkLiquidCapture
|
|
11
|
+
DA:5,1
|
|
12
|
+
DA:7,1
|
|
13
|
+
DA:9,1
|
|
14
|
+
DA:12,1
|
|
15
|
+
DA:21,31
|
|
16
|
+
DA:25,19
|
|
17
|
+
DA:26,19
|
|
18
|
+
DA:29,19
|
|
19
|
+
DA:30,19
|
|
20
|
+
DA:37,19
|
|
21
|
+
DA:42,32
|
|
22
|
+
DA:43,11
|
|
23
|
+
DA:46,21
|
|
24
|
+
DA:47,21
|
|
25
|
+
DA:49,19
|
|
26
|
+
DA:50,19
|
|
27
|
+
DA:52,19
|
|
28
|
+
DA:53,14
|
|
29
|
+
DA:54,19
|
|
30
|
+
DA:55,19
|
|
31
|
+
DA:64,1
|
|
32
|
+
LF:21
|
|
33
|
+
LH:21
|
|
34
|
+
BRDA:42,0,0,11
|
|
35
|
+
BRDA:42,1,0,32
|
|
36
|
+
BRDA:42,1,1,31
|
|
37
|
+
BRDA:46,2,0,20
|
|
38
|
+
BRDA:46,2,1,1
|
|
39
|
+
BRDA:46,3,0,21
|
|
40
|
+
BRDA:46,3,1,20
|
|
41
|
+
BRDA:47,4,0,2
|
|
42
|
+
BRDA:52,5,0,14
|
|
43
|
+
BRF:9
|
|
44
|
+
BRH:9
|
|
45
|
+
end_of_record
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;;AA6DH,kBAA0C"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* For .md files outside shared/partials folder, a file should not contain capture block - Throw Warning
|
|
4
|
+
*/
|
|
2
5
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
6
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
7
|
};
|
|
5
8
|
const unified_lint_rule_1 = __importDefault(require("unified-lint-rule"));
|
|
6
9
|
const sfdocs_liquid_lint_utils_1 = require("@salesforcedevs/sfdocs-liquid-lint-utils");
|
|
7
10
|
const SOURCE = 'sfdocs-liquid-lint:liquid-capture';
|
|
8
|
-
// Regex
|
|
11
|
+
// Regex pattern
|
|
9
12
|
const CAPTURE_BLOCK_RE = /{%-?\s*capture\s+(\w+)\s*-?%}([\s\S]*?){%-?\s*endcapture\s*-?%}/g;
|
|
10
13
|
function isInPartialsFolder(filePath) {
|
|
11
14
|
return filePath.includes('/shared/partials/');
|
|
@@ -23,50 +26,20 @@ function extractCaptureBlocks(content) {
|
|
|
23
26
|
}
|
|
24
27
|
return captures;
|
|
25
28
|
}
|
|
26
|
-
function findDuplicateCaptures(captures) {
|
|
27
|
-
const nameMap = new Map();
|
|
28
|
-
for (const capture of captures) {
|
|
29
|
-
if (!nameMap.has(capture.name)) {
|
|
30
|
-
nameMap.set(capture.name, []);
|
|
31
|
-
}
|
|
32
|
-
nameMap.get(capture.name).push(capture);
|
|
33
|
-
}
|
|
34
|
-
// Filter to only duplicates
|
|
35
|
-
const duplicates = new Map();
|
|
36
|
-
for (const [name, blocks] of nameMap.entries()) {
|
|
37
|
-
if (blocks.length > 1) {
|
|
38
|
-
duplicates.set(name, blocks);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return duplicates;
|
|
42
|
-
}
|
|
43
29
|
function checkLiquidCapture(_tree, file) {
|
|
44
30
|
var _a;
|
|
45
|
-
if (!file.path)
|
|
31
|
+
if (!file.path || isInPartialsFolder(file.path)) {
|
|
46
32
|
return;
|
|
33
|
+
}
|
|
47
34
|
const raw = String((_a = file.contents) !== null && _a !== void 0 ? _a : '');
|
|
48
35
|
if (!raw)
|
|
49
36
|
return;
|
|
50
37
|
const protectedContent = (0, sfdocs_liquid_lint_utils_1.protectCodeBlocks)(raw);
|
|
51
38
|
const captureBlocks = extractCaptureBlocks(protectedContent);
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const msg = file.message(`Capture blocks are not allowed in files outside shared/partials folder. Found capture block "${capture.name}".`, position);
|
|
57
|
-
msg.fatal = false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const duplicates = findDuplicateCaptures(captureBlocks);
|
|
63
|
-
if (duplicates.size > 0) {
|
|
64
|
-
for (const [name, blocks] of duplicates.entries()) {
|
|
65
|
-
// Report on all occurrences after the first
|
|
66
|
-
for (let i = 1; i < blocks.length; i++) {
|
|
67
|
-
const position = (0, sfdocs_liquid_lint_utils_1.offsetToPosition)(raw, blocks[i].startOffset);
|
|
68
|
-
file.message(`Duplicate capture block name "${name}". This variable already exists in file.`, position);
|
|
69
|
-
}
|
|
39
|
+
if (captureBlocks.length > 0) {
|
|
40
|
+
for (const capture of captureBlocks) {
|
|
41
|
+
const position = (0, sfdocs_liquid_lint_utils_1.offsetToPosition)(raw, capture.startOffset);
|
|
42
|
+
file.message(`Capture block "${capture.name}" is outside the shared/partials directory. Consider moving it to shared/partials for reuse.`, position);
|
|
70
43
|
}
|
|
71
44
|
}
|
|
72
45
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,0EAAqC;AAErC,uFAA+F;AAE/F,MAAM,MAAM,GAAG,mCAAmC,CAAC;AAEnD,gBAAgB;AAChB,MAAM,gBAAgB,GAAG,kEAAkE,CAAC;AAQ5F,SAAS,kBAAkB,CAAC,QAAgB;IACxC,OAAO,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAe;IACzC,MAAM,QAAQ,GAAmB,EAAE,CAAC;IACpC,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpD,IAAI,KAA6B,CAAC;IAElC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE;QACxC,QAAQ,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;YACd,WAAW,EAAE,KAAK,CAAC,KAAK;YACxB,SAAS,EAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM;SAC3C,CAAC,CAAC;KACN;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc,EAAE,IAAW;;IAEnD,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC7C,OAAO;KACV;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,MAAA,IAAI,CAAC,QAAQ,mCAAI,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,GAAG;QAAE,OAAO;IAEjB,MAAM,gBAAgB,GAAG,IAAA,4CAAiB,EAAC,GAAG,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;IAE7D,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1B,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE;YACjC,MAAM,QAAQ,GAAG,IAAA,2CAAgB,EAAC,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;YAC5D,IAAI,CAAC,OAAO,CACR,kBAAkB,OAAO,CAAC,IAAI,8FAA8F,EAC5H,QAAQ,CACX,CAAC;SACL;KACJ;AAEL,CAAC;AAED,iBAAS,IAAA,2BAAI,EAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/sfdocs-liquid-lint-capture",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.6-alpha",
|
|
4
|
+
"description": "Warns when capture blocks are used outside shared/partials folder",
|
|
5
5
|
"author": "SFDocs Team",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"scripts": {
|