podlite 0.0.78 → 0.0.80
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.podlite +40 -0
- package/esm/cli.js +100 -18
- package/esm/cli.js.map +1 -1
- package/esm/lint/config.d.ts +8 -0
- package/esm/lint/config.js +101 -0
- package/esm/lint/config.js.map +1 -0
- package/esm/lint/engine.js +3 -1
- package/esm/lint/engine.js.map +1 -1
- package/esm/lint/formatters/text.d.ts +1 -0
- package/esm/lint/formatters/text.js +3 -1
- package/esm/lint/formatters/text.js.map +1 -1
- package/esm/lint/grammar/lint.js +7 -4
- package/esm/lint/grammar/lint.js.map +1 -1
- package/esm/lint/grammar/scan.d.ts +1 -1
- package/esm/lint/grammar/scan.js +20 -3
- package/esm/lint/grammar/scan.js.map +1 -1
- package/esm/lint/index.d.ts +11 -0
- package/esm/lint/index.js +47 -18
- package/esm/lint/index.js.map +1 -1
- package/esm/lint/mute.d.ts +17 -0
- package/esm/lint/mute.js +75 -0
- package/esm/lint/mute.js.map +1 -0
- package/esm/lint/parallel.d.ts +4 -0
- package/esm/lint/parallel.js +57 -0
- package/esm/lint/parallel.js.map +1 -0
- package/esm/lint/rules/abbreviated-attrs.d.ts +4 -0
- package/esm/lint/rules/abbreviated-attrs.js +67 -0
- package/esm/lint/rules/abbreviated-attrs.js.map +1 -0
- package/esm/lint/rules/attr-value-dropped.js +3 -2
- package/esm/lint/rules/attr-value-dropped.js.map +1 -1
- package/esm/lint/rules/dead-definitions.d.ts +3 -0
- package/esm/lint/rules/dead-definitions.js +80 -0
- package/esm/lint/rules/dead-definitions.js.map +1 -0
- package/esm/lint/rules/index.js +4 -0
- package/esm/lint/rules/index.js.map +1 -1
- package/esm/lint/rules/markdown-in-pod.d.ts +4 -0
- package/esm/lint/rules/markdown-in-pod.js +67 -0
- package/esm/lint/rules/markdown-in-pod.js.map +1 -0
- package/esm/lint/rules/table-column-width.d.ts +4 -0
- package/esm/lint/rules/table-column-width.js +110 -0
- package/esm/lint/rules/table-column-width.js.map +1 -0
- package/esm/lint/rules/table-shape.d.ts +3 -0
- package/esm/lint/rules/table-shape.js +15 -0
- package/esm/lint/rules/table-shape.js.map +1 -0
- package/esm/lint/types.d.ts +5 -1
- package/esm/lint/worker.d.ts +5 -0
- package/esm/lint/worker.js +15 -0
- package/esm/lint/worker.js.map +1 -0
- package/esm/query.js +4 -1
- package/esm/query.js.map +1 -1
- package/esm/resolve-includes.js +56 -7
- package/esm/resolve-includes.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/cli.js +99 -17
- package/lib/cli.js.map +1 -1
- package/lib/lint/config.d.ts +8 -0
- package/lib/lint/config.js +143 -0
- package/lib/lint/config.js.map +1 -0
- package/lib/lint/engine.js +3 -1
- package/lib/lint/engine.js.map +1 -1
- package/lib/lint/formatters/text.d.ts +1 -0
- package/lib/lint/formatters/text.js +3 -1
- package/lib/lint/formatters/text.js.map +1 -1
- package/lib/lint/grammar/lint.js +7 -4
- package/lib/lint/grammar/lint.js.map +1 -1
- package/lib/lint/grammar/scan.d.ts +1 -1
- package/lib/lint/grammar/scan.js +19 -2
- package/lib/lint/grammar/scan.js.map +1 -1
- package/lib/lint/index.d.ts +11 -0
- package/lib/lint/index.js +89 -20
- package/lib/lint/index.js.map +1 -1
- package/lib/lint/mute.d.ts +17 -0
- package/lib/lint/mute.js +80 -0
- package/lib/lint/mute.js.map +1 -0
- package/lib/lint/parallel.d.ts +4 -0
- package/lib/lint/parallel.js +95 -0
- package/lib/lint/parallel.js.map +1 -0
- package/lib/lint/rules/abbreviated-attrs.d.ts +4 -0
- package/lib/lint/rules/abbreviated-attrs.js +71 -0
- package/lib/lint/rules/abbreviated-attrs.js.map +1 -0
- package/lib/lint/rules/attr-value-dropped.js +3 -2
- package/lib/lint/rules/attr-value-dropped.js.map +1 -1
- package/lib/lint/rules/dead-definitions.d.ts +3 -0
- package/lib/lint/rules/dead-definitions.js +83 -0
- package/lib/lint/rules/dead-definitions.js.map +1 -0
- package/lib/lint/rules/index.js +4 -0
- package/lib/lint/rules/index.js.map +1 -1
- package/lib/lint/rules/markdown-in-pod.d.ts +4 -0
- package/lib/lint/rules/markdown-in-pod.js +71 -0
- package/lib/lint/rules/markdown-in-pod.js.map +1 -0
- package/lib/lint/rules/table-column-width.d.ts +4 -0
- package/lib/lint/rules/table-column-width.js +114 -0
- package/lib/lint/rules/table-column-width.js.map +1 -0
- package/lib/lint/rules/table-shape.d.ts +3 -0
- package/lib/lint/rules/table-shape.js +18 -0
- package/lib/lint/rules/table-shape.js.map +1 -0
- package/lib/lint/types.d.ts +5 -1
- package/lib/lint/worker.d.ts +5 -0
- package/lib/lint/worker.js +17 -0
- package/lib/lint/worker.js.map +1 -0
- package/lib/query.js +4 -1
- package/lib/query.js.map +1 -1
- package/lib/resolve-includes.js +55 -6
- package/lib/resolve-includes.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +13 -7
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.abbreviatedAttrsRule = exports.ABBREVIATED_ATTRS_RULE_ID = void 0;
|
|
4
|
+
exports.scanAbbreviatedAttrs = scanAbbreviatedAttrs;
|
|
5
|
+
const schema_1 = require("@podlite/schema");
|
|
6
|
+
exports.ABBREVIATED_ATTRS_RULE_ID = 'abbreviated-attrs';
|
|
7
|
+
exports.abbreviatedAttrsRule = {
|
|
8
|
+
id: exports.ABBREVIATED_ATTRS_RULE_ID,
|
|
9
|
+
severity: 'warning',
|
|
10
|
+
};
|
|
11
|
+
// The specification is plain about it: the rest of an abbreviated block's line
|
|
12
|
+
// is block data, not configuration. What the author wrote as an attribute
|
|
13
|
+
// arrives as text, the markup stays legal, and nothing says the mechanism did
|
|
14
|
+
// not run.
|
|
15
|
+
const ABBREVIATED = /^\s*=([A-Za-z][\w-]*)[ \t]+(\S.*)$/;
|
|
16
|
+
const DELIMITED = /^\s*=(?:begin|end|for)[ \t]+([\w-]+)/;
|
|
17
|
+
// Only a line made of attributes and nothing else is reported. A line where
|
|
18
|
+
// attributes stand next to real text is the author writing prose that happens
|
|
19
|
+
// to hold a colon, and calling that a fault would bury the rule in noise.
|
|
20
|
+
const ONLY_ATTRIBUTES = /^(:[A-Za-z][\w-]*(<[^>]*>|\([^)]*\)|\{[^}]*\}|\[[^\]]*\])?[ \t]*)+$/;
|
|
21
|
+
// An attribute written with nothing inside documents the attribute itself,
|
|
22
|
+
// which is how the registries and the specifications spell one out.
|
|
23
|
+
const EMPTY_VALUE = /^:[A-Za-z][\w-]*<>$/;
|
|
24
|
+
const allEmpty = (rest) => rest
|
|
25
|
+
.trim()
|
|
26
|
+
.split(/[ \t]+/)
|
|
27
|
+
.every(part => EMPTY_VALUE.test(part));
|
|
28
|
+
function scanAbbreviatedAttrs(content) {
|
|
29
|
+
const lines = content.split(/\r?\n/);
|
|
30
|
+
const open = [];
|
|
31
|
+
const violations = [];
|
|
32
|
+
for (let i = 0; i < lines.length; i++) {
|
|
33
|
+
const line = lines[i];
|
|
34
|
+
const delimited = line.match(DELIMITED);
|
|
35
|
+
if (delimited) {
|
|
36
|
+
if (/^\s*=end\b/.test(line))
|
|
37
|
+
open.pop();
|
|
38
|
+
else if (/^\s*=begin\b/.test(line))
|
|
39
|
+
open.push(delimited[1]);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (open.some(schema_1.isVerbatimBlock))
|
|
43
|
+
continue;
|
|
44
|
+
const abbreviated = line.match(ABBREVIATED);
|
|
45
|
+
if (!abbreviated)
|
|
46
|
+
continue;
|
|
47
|
+
const [, name, rest] = abbreviated;
|
|
48
|
+
if ((0, schema_1.isVerbatimBlock)(name))
|
|
49
|
+
continue;
|
|
50
|
+
if (!ONLY_ATTRIBUTES.test(rest.trim()))
|
|
51
|
+
continue;
|
|
52
|
+
if (allEmpty(rest))
|
|
53
|
+
continue;
|
|
54
|
+
// content has to follow, otherwise the line is the whole block and the
|
|
55
|
+
// author wrote no data at all — a different mistake, if it is one
|
|
56
|
+
const next = lines[i + 1];
|
|
57
|
+
if (next === undefined || next.trim() === '' || /^\s*=/.test(next))
|
|
58
|
+
continue;
|
|
59
|
+
violations.push({
|
|
60
|
+
rule: exports.ABBREVIATED_ATTRS_RULE_ID,
|
|
61
|
+
severity: 'warning',
|
|
62
|
+
message: `=${name} takes the rest of its line as data, so ${rest.trim()} arrives as text; write =for ${name} to pass configuration`,
|
|
63
|
+
location: {
|
|
64
|
+
start: { line: i + 1, column: 1, offset: 0 },
|
|
65
|
+
end: { line: i + 1, column: 1, offset: 0 },
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return violations;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=abbreviated-attrs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abbreviated-attrs.js","sourceRoot":"","sources":["../../../src/lint/rules/abbreviated-attrs.ts"],"names":[],"mappings":";;;AAgCA,oDA0CC;AA1ED,4CAAiD;AAGpC,QAAA,yBAAyB,GAAG,mBAAmB,CAAA;AAE/C,QAAA,oBAAoB,GAAe;IAC9C,EAAE,EAAE,iCAAyB;IAC7B,QAAQ,EAAE,SAAS;CACpB,CAAA;AAED,+EAA+E;AAC/E,0EAA0E;AAC1E,8EAA8E;AAC9E,WAAW;AACX,MAAM,WAAW,GAAG,oCAAoC,CAAA;AACxD,MAAM,SAAS,GAAG,sCAAsC,CAAA;AAExD,4EAA4E;AAC5E,8EAA8E;AAC9E,0EAA0E;AAC1E,MAAM,eAAe,GAAG,qEAAqE,CAAA;AAE7F,2EAA2E;AAC3E,oEAAoE;AACpE,MAAM,WAAW,GAAG,qBAAqB,CAAA;AAEzC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAW,EAAE,CACzC,IAAI;KACD,IAAI,EAAE;KACN,KAAK,CAAC,QAAQ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AAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;QACzB,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,SAAQ;QAE5E,UAAU,CAAC,IAAI,CAAC;YACd,IAAI,EAAE,iCAAyB;YAC/B,QAAQ,EAAE,SAAS;YACnB,OAAO,EAAE,IAAI,IAAI,2CAA2C,IAAI,CAAC,IAAI,EAAE,gCAAgC,IAAI,wBAAwB;YACnI,QAAQ,EAAE;gBACR,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;gBAC5C,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;aAC3C;SACF,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
|
@@ -5,9 +5,10 @@ exports.ATTR_VALUE_DROPPED_RULE_ID = 'attr-value-dropped';
|
|
|
5
5
|
exports.attrValueDroppedRule = {
|
|
6
6
|
id: exports.ATTR_VALUE_DROPPED_RULE_ID,
|
|
7
7
|
severity: 'warning',
|
|
8
|
-
// a directive the parser could not read is the business of syntax-valid
|
|
8
|
+
// a directive the parser could not read is the business of syntax-valid,
|
|
9
|
+
// a table that was reshaped is the business of table-shape
|
|
9
10
|
check: (ast, _ctx) => (ast.diagnostics || [])
|
|
10
|
-
.filter(d => d.code
|
|
11
|
+
.filter(d => d.code === 'value-unreadable')
|
|
11
12
|
.map(d => ({
|
|
12
13
|
rule: exports.ATTR_VALUE_DROPPED_RULE_ID,
|
|
13
14
|
severity: d.severity,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attr-value-dropped.js","sourceRoot":"","sources":["../../../src/lint/rules/attr-value-dropped.ts"],"names":[],"mappings":";;;AAGa,QAAA,0BAA0B,GAAG,oBAAoB,CAAA;AAEjD,QAAA,oBAAoB,GAAS;IACxC,EAAE,EAAE,kCAA0B;IAC9B,QAAQ,EAAE,SAAS;IACnB,
|
|
1
|
+
{"version":3,"file":"attr-value-dropped.js","sourceRoot":"","sources":["../../../src/lint/rules/attr-value-dropped.ts"],"names":[],"mappings":";;;AAGa,QAAA,0BAA0B,GAAG,oBAAoB,CAAA;AAEjD,QAAA,oBAAoB,GAAS;IACxC,EAAE,EAAE,kCAA0B;IAC9B,QAAQ,EAAE,SAAS;IACnB,yEAAyE;IACzE,2DAA2D;IAC3D,KAAK,EAAE,CAAC,GAAoB,EAAE,IAAiB,EAAe,EAAE,CAC9D,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,kBAAkB,CAAC;SAC1C,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACT,IAAI,EAAE,kCAA0B;QAChC,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;KACrB,CAAC,CAAC;CACR,CAAA"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deadDefinitionsRule = exports.DEAD_DEFINITIONS_RULE_ID = void 0;
|
|
4
|
+
const schema_1 = require("@podlite/schema");
|
|
5
|
+
exports.DEAD_DEFINITIONS_RULE_ID = 'dead-definitions';
|
|
6
|
+
const attr = (node, name) => {
|
|
7
|
+
const item = (Array.isArray(node.config) ? node.config : []).find(c => c && c.name === name);
|
|
8
|
+
return item && item.value !== undefined && item.value !== null ? String(item.value) : undefined;
|
|
9
|
+
};
|
|
10
|
+
// An alias node carries no location, so the line is read back from the source;
|
|
11
|
+
// a warning that cannot say where is a warning the author cannot act on.
|
|
12
|
+
const aliasLine = (source, name) => {
|
|
13
|
+
const lines = source.split(/\r?\n/);
|
|
14
|
+
const at = lines.findIndex(line => new RegExp(`^\\s*=alias\\s+${name}(\\s|$)`).test(line));
|
|
15
|
+
if (at === -1)
|
|
16
|
+
return undefined;
|
|
17
|
+
return { start: { line: at + 1, column: 1, offset: 0 }, end: { line: at + 1, column: 1, offset: 0 } };
|
|
18
|
+
};
|
|
19
|
+
const definitions = (ast) => {
|
|
20
|
+
const nodes = (0, schema_1.getFromTree)(ast, () => true);
|
|
21
|
+
const found = [];
|
|
22
|
+
for (const node of nodes) {
|
|
23
|
+
if (node.type === 'alias' && node.name) {
|
|
24
|
+
found.push({ kind: 'alias', name: node.name, location: node.location });
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (node.name === 'data') {
|
|
28
|
+
const key = attr(node, 'key');
|
|
29
|
+
if (key)
|
|
30
|
+
found.push({ kind: 'data', name: key, location: node.location });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return found;
|
|
34
|
+
};
|
|
35
|
+
const aliasUses = (ast) => {
|
|
36
|
+
const nodes = (0, schema_1.getFromTree)(ast, () => true);
|
|
37
|
+
const used = new Set();
|
|
38
|
+
for (const node of nodes) {
|
|
39
|
+
if (node.type !== 'fcode' || node.name !== 'A')
|
|
40
|
+
continue;
|
|
41
|
+
const name = (0, schema_1.getTextContentFromNode)(node)
|
|
42
|
+
?.toString()
|
|
43
|
+
.trim();
|
|
44
|
+
if (name)
|
|
45
|
+
used.add(name);
|
|
46
|
+
}
|
|
47
|
+
return used;
|
|
48
|
+
};
|
|
49
|
+
// A data reference is read from the source rather than from the tree: the block
|
|
50
|
+
// that consumes it resolves the reference while the tree is built, so by the
|
|
51
|
+
// time a rule sees the tree the mention is already gone.
|
|
52
|
+
const dataUses = (source) => {
|
|
53
|
+
const used = new Set();
|
|
54
|
+
const reference = /data:([A-Za-z0-9_-]+)/g;
|
|
55
|
+
let match;
|
|
56
|
+
while ((match = reference.exec(source)) !== null)
|
|
57
|
+
used.add(match[1]);
|
|
58
|
+
return used;
|
|
59
|
+
};
|
|
60
|
+
exports.deadDefinitionsRule = {
|
|
61
|
+
id: exports.DEAD_DEFINITIONS_RULE_ID,
|
|
62
|
+
severity: 'warning',
|
|
63
|
+
check: (ast, ctx) => {
|
|
64
|
+
// without the source a data reference cannot be found at all, and reporting
|
|
65
|
+
// every keyed block as dead would be worse than saying nothing
|
|
66
|
+
const declared = definitions(ast).filter(item => item.kind === 'alias' || ctx.source !== undefined);
|
|
67
|
+
if (declared.length === 0)
|
|
68
|
+
return [];
|
|
69
|
+
const aliases = aliasUses(ast);
|
|
70
|
+
const keys = dataUses(ctx.source || '');
|
|
71
|
+
return declared
|
|
72
|
+
.filter(item => !(item.kind === 'alias' ? aliases.has(item.name) : keys.has(item.name)))
|
|
73
|
+
.map(item => ({
|
|
74
|
+
rule: exports.DEAD_DEFINITIONS_RULE_ID,
|
|
75
|
+
severity: 'warning',
|
|
76
|
+
message: item.kind === 'alias'
|
|
77
|
+
? `=alias ${item.name} is never used; A<${item.name}> appears nowhere in the document`
|
|
78
|
+
: `=data :key<${item.name}> is never used; data:${item.name} appears nowhere in the document`,
|
|
79
|
+
location: item.location || (item.kind === 'alias' ? aliasLine(ctx.source || '', item.name) : undefined),
|
|
80
|
+
}));
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=dead-definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dead-definitions.js","sourceRoot":"","sources":["../../../src/lint/rules/dead-definitions.ts"],"names":[],"mappings":";;;AAAA,4CAAsF;AAGzE,QAAA,wBAAwB,GAAG,kBAAkB,CAAA;AAY1D,MAAM,IAAI,GAAG,CAAC,IAAa,EAAE,IAAY,EAAsB,EAAE;IAC/D,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CA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OAAO;gBACnB,CAAC,CAAC,UAAU,IAAI,CAAC,IAAI,qBAAqB,IAAI,CAAC,IAAI,mCAAmC;gBACtF,CAAC,CAAC,cAAc,IAAI,CAAC,IAAI,yBAAyB,IAAI,CAAC,IAAI,kCAAkC;YACjG,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;SACxG,CAAC,CAAC,CAAA;IACP,CAAC;CACF,CAAA"}
|
package/lib/lint/rules/index.js
CHANGED
|
@@ -7,6 +7,8 @@ const id_unique_1 = require("./id-unique");
|
|
|
7
7
|
const media_absolute_file_1 = require("./media-absolute-file");
|
|
8
8
|
const link_target_resolves_1 = require("./link-target-resolves");
|
|
9
9
|
const attr_value_dropped_1 = require("./attr-value-dropped");
|
|
10
|
+
const table_shape_1 = require("./table-shape");
|
|
11
|
+
const dead_definitions_1 = require("./dead-definitions");
|
|
10
12
|
exports.DEFAULT_RULES = [
|
|
11
13
|
syntax_valid_1.syntaxValidRule,
|
|
12
14
|
heading_hierarchy_1.headingHierarchyRule,
|
|
@@ -14,5 +16,7 @@ exports.DEFAULT_RULES = [
|
|
|
14
16
|
media_absolute_file_1.mediaAbsoluteFileRule,
|
|
15
17
|
link_target_resolves_1.linkTargetResolvesRule,
|
|
16
18
|
attr_value_dropped_1.attrValueDroppedRule,
|
|
19
|
+
table_shape_1.tableShapeRule,
|
|
20
|
+
dead_definitions_1.deadDefinitionsRule,
|
|
17
21
|
];
|
|
18
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lint/rules/index.ts"],"names":[],"mappings":";;;AACA,iDAAgD;AAChD,2DAA0D;AAC1D,2CAA0C;AAC1C,+DAA6D;AAC7D,iEAA+D;AAC/D,6DAA2D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lint/rules/index.ts"],"names":[],"mappings":";;;AACA,iDAAgD;AAChD,2DAA0D;AAC1D,2CAA0C;AAC1C,+DAA6D;AAC7D,iEAA+D;AAC/D,6DAA2D;AAC3D,+CAA8C;AAC9C,yDAAwD;AAE3C,QAAA,aAAa,GAAW;IACnC,8BAAe;IACf,wCAAoB;IACpB,wBAAY;IACZ,2CAAqB;IACrB,6CAAsB;IACtB,yCAAoB;IACpB,4BAAc;IACd,sCAAmB;CACpB,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.markdownInPodRule = exports.MARKDOWN_IN_POD_RULE_ID = void 0;
|
|
4
|
+
exports.scanMarkdownInPod = scanMarkdownInPod;
|
|
5
|
+
const schema_1 = require("@podlite/schema");
|
|
6
|
+
exports.MARKDOWN_IN_POD_RULE_ID = 'markdown-in-pod';
|
|
7
|
+
exports.markdownInPodRule = {
|
|
8
|
+
id: exports.MARKDOWN_IN_POD_RULE_ID,
|
|
9
|
+
severity: 'warning',
|
|
10
|
+
};
|
|
11
|
+
const FOREIGN = [
|
|
12
|
+
{ test: /^\s*#{1,6}\s+\S/, says: 'a heading written with hashes is text here; write =head1 and its levels' },
|
|
13
|
+
{
|
|
14
|
+
test: /^\s*\|?[\s:|-]*-[\s:|-]*\|[\s:|-]*$/,
|
|
15
|
+
says: 'a row of bars and dashes is text here; a table is written as =begin table with its own separator',
|
|
16
|
+
},
|
|
17
|
+
{ test: /\*\*[^*\s](?:[^*]*[^*\s])?\*\*/, says: 'a pair of asterisks is text here; bold is written as B<>' },
|
|
18
|
+
];
|
|
19
|
+
// Talk about Markdown is legal: a line whose construct sits inside an inline
|
|
20
|
+
// code span is showing the markup, not using it.
|
|
21
|
+
const insideCode = (line) => /C<[^>]*>/.test(line) || /`[^`]+`/.test(line);
|
|
22
|
+
function scanMarkdownInPod(content) {
|
|
23
|
+
const lines = content.split(/\r?\n/);
|
|
24
|
+
const open = [];
|
|
25
|
+
const violations = [];
|
|
26
|
+
let abbreviatedTable = false;
|
|
27
|
+
for (let i = 0; i < lines.length; i++) {
|
|
28
|
+
const line = lines[i];
|
|
29
|
+
const end = line.match(/^\s*=end\s+([\w-]+)/);
|
|
30
|
+
if (end) {
|
|
31
|
+
open.pop();
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const begin = line.match(/^\s*=begin\s+([\w-]+)/);
|
|
35
|
+
if (begin) {
|
|
36
|
+
open.push(begin[1]);
|
|
37
|
+
abbreviatedTable = false;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// a dash separator belongs to a table written the short way too, and that
|
|
41
|
+
// block runs to the first blank line
|
|
42
|
+
if (/^\s*=(?:for\s+)?table\b/.test(line)) {
|
|
43
|
+
abbreviatedTable = true;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (abbreviatedTable && line.trim() === '')
|
|
47
|
+
abbreviatedTable = false;
|
|
48
|
+
if (/^\s*=/.test(line))
|
|
49
|
+
abbreviatedTable = false;
|
|
50
|
+
if (open.some(schema_1.isVerbatimBlock) || open.includes('data') || abbreviatedTable)
|
|
51
|
+
continue;
|
|
52
|
+
if (insideCode(line))
|
|
53
|
+
continue;
|
|
54
|
+
for (const foreign of FOREIGN) {
|
|
55
|
+
if (!foreign.test.test(line))
|
|
56
|
+
continue;
|
|
57
|
+
violations.push({
|
|
58
|
+
rule: exports.MARKDOWN_IN_POD_RULE_ID,
|
|
59
|
+
severity: 'warning',
|
|
60
|
+
message: foreign.says,
|
|
61
|
+
location: {
|
|
62
|
+
start: { line: i + 1, column: 1, offset: 0 },
|
|
63
|
+
end: { line: i + 1, column: 1, offset: 0 },
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return violations;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=markdown-in-pod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-in-pod.js","sourceRoot":"","sources":["../../../src/lint/rules/markdown-in-pod.ts"],"names":[],"mappings":";;;AA6BA,8CAgDC;AA7ED,4CAAiD;AAGpC,QAAA,uBAAuB,GAAG,iBAAiB,CAAA;AAE3C,QAAA,iBAAiB,GAAe;IAC3C,EAAE,EAAE,+BAAuB;IAC3B,QAAQ,EAAE,SAAS;CACpB,CAAA;AAQD,MAAM,OAAO,GAAc;IACzB,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,yEAAyE,EAAE;IAC5G;QACE,IAAI,EAAE,qCAAqC;QAC3C,IAAI,EAAE,kGAAkG;KACzG;IACD,EAAE,IAAI,EAAE,gCAAgC,EAAE,IAAI,EAAE,0DAA0D,EAAE;CAC7G,CAAA;AAED,6EAA6E;AAC7E,iDAAiD;AACjD,MAAM,UAAU,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAE3F,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACpC,MAAM,IAAI,GAAa,EAAE,CAAA;IACzB,MAAM,UAAU,GAAgB,EAAE,CAAA;IAClC,IAAI,gBAAgB,GAAG,KAAK,CAAA;IAE5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAErB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;QAC7C,IAAI,GAAG,EAAE,CAA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C,EAAE,MAAM,EAAE,CAAC,EAAE;iBAC3C;aACF,CAAC,CAAA;YACF,MAAK;QACP,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableColumnWidthRule = exports.TABLE_COLUMN_WIDTH_RULE_ID = void 0;
|
|
4
|
+
exports.scanTableColumns = scanTableColumns;
|
|
5
|
+
const schema_1 = require("@podlite/schema");
|
|
6
|
+
exports.TABLE_COLUMN_WIDTH_RULE_ID = 'table-column-width';
|
|
7
|
+
exports.tableColumnWidthRule = {
|
|
8
|
+
id: exports.TABLE_COLUMN_WIDTH_RULE_ID,
|
|
9
|
+
severity: 'warning',
|
|
10
|
+
};
|
|
11
|
+
const SEPARATOR_LINE = /^[\s=+|_-]*[|+][\s=+|_-]*$/;
|
|
12
|
+
const hasBar = (line) => line.includes('|') || line.includes('+');
|
|
13
|
+
// A table with visible bars is cut by the column positions its separator line
|
|
14
|
+
// sets, not by the bars in the row itself. A cell that reaches the boundary
|
|
15
|
+
// pushes the column open for the whole table, so every row loses its last
|
|
16
|
+
// column at once — and the document still parses, silently.
|
|
17
|
+
const boundaries = (separator) => {
|
|
18
|
+
const out = [];
|
|
19
|
+
for (let i = 0; i < separator.length; i++) {
|
|
20
|
+
if (separator[i] === '|' || separator[i] === '+')
|
|
21
|
+
out.push(i);
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
};
|
|
25
|
+
const isEdge = (char) => char === '|' || char === '+' || char === ' ';
|
|
26
|
+
const collides = (line, boundary) => {
|
|
27
|
+
if (boundary >= line.length)
|
|
28
|
+
return false;
|
|
29
|
+
// content standing on the boundary is wrong however the row is written
|
|
30
|
+
if (!isEdge(line[boundary]))
|
|
31
|
+
return true;
|
|
32
|
+
// pressed against the boundary only matters where the row draws a bar of its
|
|
33
|
+
// own: a row whose cells are held apart by spaces may fill its column to the
|
|
34
|
+
// last position, and the parser reads it correctly
|
|
35
|
+
const drawsBar = line[boundary] === '|' || line[boundary] === '+';
|
|
36
|
+
return drawsBar && boundary > 0 && !isEdge(line[boundary - 1]);
|
|
37
|
+
};
|
|
38
|
+
const checkTable = (lines) => {
|
|
39
|
+
const separator = lines.find(l => SEPARATOR_LINE.test(l.text) && hasBar(l.text));
|
|
40
|
+
if (!separator)
|
|
41
|
+
return [];
|
|
42
|
+
const columns = boundaries(separator.text);
|
|
43
|
+
if (columns.length === 0)
|
|
44
|
+
return [];
|
|
45
|
+
const violations = [];
|
|
46
|
+
for (const row of lines) {
|
|
47
|
+
if (row === separator || row.text.trim() === '')
|
|
48
|
+
continue;
|
|
49
|
+
if (SEPARATOR_LINE.test(row.text))
|
|
50
|
+
continue;
|
|
51
|
+
const hit = columns.find(b => collides(row.text, b));
|
|
52
|
+
if (hit === undefined)
|
|
53
|
+
continue;
|
|
54
|
+
violations.push({
|
|
55
|
+
rule: exports.TABLE_COLUMN_WIDTH_RULE_ID,
|
|
56
|
+
severity: 'warning',
|
|
57
|
+
message: `cell reaches the column boundary at column ${hit + 1}; leave a space before the bar or the table loses a column`,
|
|
58
|
+
location: {
|
|
59
|
+
start: { line: row.line, column: hit + 1, offset: 0 },
|
|
60
|
+
end: { line: row.line, column: hit + 1, offset: 0 },
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return violations;
|
|
65
|
+
};
|
|
66
|
+
function scanTableColumns(content) {
|
|
67
|
+
const lines = content.split(/\r?\n/);
|
|
68
|
+
// a table keeps its content verbatim too, and it is the one being read here
|
|
69
|
+
const verbatim = (name) => name !== 'table' && (0, schema_1.isVerbatimBlock)(name);
|
|
70
|
+
const openBlocks = [];
|
|
71
|
+
const violations = [];
|
|
72
|
+
let table = null;
|
|
73
|
+
const closeTable = () => {
|
|
74
|
+
if (table)
|
|
75
|
+
violations.push(...checkTable(table));
|
|
76
|
+
table = null;
|
|
77
|
+
};
|
|
78
|
+
for (let i = 0; i < lines.length; i++) {
|
|
79
|
+
const text = lines[i];
|
|
80
|
+
const begin = text.match(/^\s*=begin\s+([\w-]+)/);
|
|
81
|
+
const end = text.match(/^\s*=end\s+([\w-]+)/);
|
|
82
|
+
const abbreviated = text.match(/^\s*=(?:for\s+)?table\b/);
|
|
83
|
+
if (end) {
|
|
84
|
+
if (end[1] === 'table')
|
|
85
|
+
closeTable();
|
|
86
|
+
openBlocks.pop();
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (begin) {
|
|
90
|
+
closeTable();
|
|
91
|
+
openBlocks.push(begin[1]);
|
|
92
|
+
if (begin[1] === 'table' && !openBlocks.some(verbatim))
|
|
93
|
+
table = [];
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (openBlocks.some(verbatim))
|
|
97
|
+
continue;
|
|
98
|
+
if (abbreviated) {
|
|
99
|
+
closeTable();
|
|
100
|
+
table = [];
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
// an abbreviated table ends at the first blank line
|
|
104
|
+
if (table && text.trim() === '' && !openBlocks.includes('table')) {
|
|
105
|
+
closeTable();
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (table)
|
|
109
|
+
table.push({ text, line: i + 1 });
|
|
110
|
+
}
|
|
111
|
+
closeTable();
|
|
112
|
+
return violations;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=table-column-width.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-column-width.js","sourceRoot":"","sources":["../../../src/lint/rules/table-column-width.ts"],"names":[],"mappings":";;;AAmEA,4CA6CC;AAhHD,4CAAiD;AAGpC,QAAA,0BAA0B,GAAG,oBAAoB,CAAA;AAEjD,QAAA,oBAAoB,GAAe;IAC9C,EAAE,EAAE,kCAA0B;IAC9B,QAAQ,EAAE,SAAS;CACpB,CAAA;AAED,MAAM,cAAc,GAAG,4BAA4B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C,CAAC,CAAC,CAAA;YACzB,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAAE,KAAK,GAAG,EAAE,CAAA;YAClE,SAAQ;QACV,CAAC;QACD,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC;YAAE,SAAQ;QACvC,IAAI,WAAW,EAAE,CAAC;YAChB,UAAU,EAAE,CAAA;YACZ,KAAK,GAAG,EAAE,CAAA;YACV,SAAQ;QACV,CAAC;QACD,oDAAoD;QACpD,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACjE,UAAU,EAAE,CAAA;YACZ,SAAQ;QACV,CAAC;QACD,IAAI,KAAK;YAAE,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAC9C,CAAC;IACD,UAAU,EAAE,CAAA;IACZ,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableShapeRule = exports.TABLE_SHAPE_RULE_ID = void 0;
|
|
4
|
+
exports.TABLE_SHAPE_RULE_ID = 'table-shape';
|
|
5
|
+
const TABLE_CODES = ['table-row-cells', 'table-cell-outside-row', 'table-mixed-separators', 'table-source-unreadable'];
|
|
6
|
+
exports.tableShapeRule = {
|
|
7
|
+
id: exports.TABLE_SHAPE_RULE_ID,
|
|
8
|
+
severity: 'warning',
|
|
9
|
+
check: (ast, _ctx) => (ast.diagnostics || [])
|
|
10
|
+
.filter(d => TABLE_CODES.includes(d.code))
|
|
11
|
+
.map(d => ({
|
|
12
|
+
rule: exports.TABLE_SHAPE_RULE_ID,
|
|
13
|
+
severity: d.severity,
|
|
14
|
+
message: d.message,
|
|
15
|
+
location: d.location,
|
|
16
|
+
})),
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=table-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-shape.js","sourceRoot":"","sources":["../../../src/lint/rules/table-shape.ts"],"names":[],"mappings":";;;AAGa,QAAA,mBAAmB,GAAG,aAAa,CAAA;AAEhD,MAAM,WAAW,GAAG,CAAC,iBAAiB,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,yBAAyB,CAAC,CAAA;AAEzG,QAAA,cAAc,GAAS;IAClC,EAAE,EAAE,2BAAmB;IACvB,QAAQ,EAAE,SAAS;IACnB,KAAK,EAAE,CAAC,GAAoB,EAAE,IAAiB,EAAe,EAAE,CAC9D,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SACzC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACT,IAAI,EAAE,2BAAmB;QACzB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;KACrB,CAAC,CAAC;CACR,CAAA"}
|
package/lib/lint/types.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { Location, PodliteDocument } from '@podlite/schema';
|
|
2
2
|
export type Severity = 'error' | 'warning' | 'info';
|
|
3
3
|
export type FileType = 'md' | 'podlite';
|
|
4
|
-
export type
|
|
4
|
+
export type RuleSetting = 'off' | Severity;
|
|
5
|
+
export type LintConfig = {
|
|
6
|
+
rules?: Record<string, RuleSetting>;
|
|
7
|
+
};
|
|
5
8
|
export type LintContext = {
|
|
6
9
|
filePath: string;
|
|
7
10
|
fileType: FileType;
|
|
8
11
|
config: LintConfig;
|
|
12
|
+
source?: string;
|
|
9
13
|
};
|
|
10
14
|
export type Violation = {
|
|
11
15
|
rule: string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const worker_threads_1 = require("worker_threads");
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
if (worker_threads_1.parentPort) {
|
|
6
|
+
const port = worker_threads_1.parentPort;
|
|
7
|
+
// the first message back says the parser is loaded and the thread can be fed
|
|
8
|
+
port.postMessage('ready');
|
|
9
|
+
port.on('message', (batch) => {
|
|
10
|
+
const done = batch.jobs.map(job => ({
|
|
11
|
+
index: job.index,
|
|
12
|
+
report: (0, index_1.lintFile)(job.filePath, batch.config),
|
|
13
|
+
}));
|
|
14
|
+
port.postMessage(done);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/lint/worker.ts"],"names":[],"mappings":";;AAAA,mDAA2C;AAE3C,mCAAkC;AAOlC,IAAI,2BAAU,EAAE,CAAC;IACf,MAAM,IAAI,GAAG,2BAAU,CAAA;IACvB,6EAA6E;IAC7E,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IACzB,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,KAAY,EAAE,EAAE;QAClC,MAAM,IAAI,GAAmB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAClD,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,MAAM,EAAE,IAAA,gBAAQ,EAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC;SAC7C,CAAC,CAAC,CAAA;QACH,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/lib/query.js
CHANGED
|
@@ -57,7 +57,10 @@ const renderViaRoot = (block, serializer) => {
|
|
|
57
57
|
};
|
|
58
58
|
const formatBlocks = (format, matches) => {
|
|
59
59
|
if (format === 'json') {
|
|
60
|
-
|
|
60
|
+
// without the source, a query over several files answers "here are the
|
|
61
|
+
// blocks" and drops "from where", which leaves the caller no way back to
|
|
62
|
+
// the document
|
|
63
|
+
return JSON.stringify(matches.map(m => ({ file: m.source.file, ...m.block })), null, 2);
|
|
61
64
|
}
|
|
62
65
|
if (format === 'podlite') {
|
|
63
66
|
return matches
|
package/lib/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAwB;AACxB,4CAA6G;AAe7G,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE;IAC1C,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC3C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAA,cAAK,EAAC,IAAI,CAAC,EAAE,CAAA;AAC1C,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,KAAU,EAAU,EAAE;IACtD,MAAM,GAAG,GAAG,KAAK,EAAE,QAAQ,CAAA;IAC3B,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,QAAQ,EAAE,CAAC;QACzF,OAAO,EAAE,CAAA;IACX,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACrD,CAAC,CAAA;AAED,wEAAwE;AACx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IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;IAClD,CAAC;IAED,oFAAoF;IACpF,MAAM,OAAO,GAA8C,EAAE,CAAA;IAC7D,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAkB,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;QAChE,MAAM,MAAM,GAAG,IAAA,oBAAW,EAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QAC/C,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAC1B,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAK,IAAe,CAAC,EAAE,CAAC;gBACtE,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAe,EAAE,CAAC,CAAA;YACvD,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACjE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAA;AACzD,CAAC,CAAA;AAjCY,QAAA,QAAQ,YAiCpB"}
|
package/lib/resolve-includes.js
CHANGED
|
@@ -38,6 +38,45 @@ const fs = __importStar(require("fs"));
|
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const schema_1 = require("@podlite/schema");
|
|
40
40
|
const isIncludeBlock = (node) => node && typeof node === 'object' && node.type === 'block' && node.name === 'include';
|
|
41
|
+
const hasMask = (target) => /[*?]/.test(target);
|
|
42
|
+
const reachesSubdirs = (target) => target.includes('**');
|
|
43
|
+
// A mask that crosses directories could otherwise walk a whole disk from a
|
|
44
|
+
// short prefix.
|
|
45
|
+
const maxDepth = 32;
|
|
46
|
+
// Everything up to the last separator that carries no mask; the rest is matched
|
|
47
|
+
// by the selector itself, which already knows the pattern language.
|
|
48
|
+
const fixedPrefix = (target) => {
|
|
49
|
+
const parts = target.split('/');
|
|
50
|
+
const upto = parts.findIndex(hasMask);
|
|
51
|
+
return parts.slice(0, upto === -1 ? parts.length : upto).join('/');
|
|
52
|
+
};
|
|
53
|
+
const listDir = (dir, deep, depth = 0) => {
|
|
54
|
+
let entries;
|
|
55
|
+
try {
|
|
56
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
const named = entries.filter(e => !e.name.startsWith('.')).sort((a, b) => (a.name < b.name ? -1 : 1));
|
|
62
|
+
const files = named.filter(e => e.isFile()).map(e => e.name);
|
|
63
|
+
if (!deep || depth >= maxDepth)
|
|
64
|
+
return files;
|
|
65
|
+
const nested = named
|
|
66
|
+
.filter(e => e.isDirectory())
|
|
67
|
+
.flatMap(e => listDir(path.join(dir, e.name), deep, depth + 1).map(inner => `${e.name}/${inner}`));
|
|
68
|
+
return [...files, ...nested];
|
|
69
|
+
};
|
|
70
|
+
// Candidate paths for a masked target, written the way the target is written so
|
|
71
|
+
// the selector matches them back. Matching runs before the file is read: the
|
|
72
|
+
// directory may hold anything, and a mask that does not name it must not send
|
|
73
|
+
// it through the parser.
|
|
74
|
+
const expandMask = (target, baseDir) => {
|
|
75
|
+
const prefix = fixedPrefix(target);
|
|
76
|
+
return listDir(path.resolve(baseDir, prefix), reachesSubdirs(target))
|
|
77
|
+
.map(name => (prefix ? `${prefix}/${name}` : name))
|
|
78
|
+
.filter(file => (0, schema_1.filePathMatches)(file, target));
|
|
79
|
+
};
|
|
41
80
|
const keepBlocks = (items) => items.filter(item => item && typeof item === 'object' && !('file' in item));
|
|
42
81
|
const unwrapRoot = (blocks) => blocks.flatMap((b) => b && b.type === 'block' && b.name === 'root' && Array.isArray(b.content) ? b.content : [b]);
|
|
43
82
|
const resolveIncludes = (tree, opts) => {
|
|
@@ -50,14 +89,24 @@ const resolveIncludes = (tree, opts) => {
|
|
|
50
89
|
const parsed = selector ? (0, schema_1.parseSelector)(selector) : undefined;
|
|
51
90
|
if (!selector || !parsed || parsed.scheme !== 'file' || !parsed.document)
|
|
52
91
|
return node;
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!fs.existsSync(target)) {
|
|
92
|
+
const masked = hasMask(parsed.document);
|
|
93
|
+
const written = masked ? expandMask(parsed.document, baseDir) : [parsed.document];
|
|
94
|
+
if (!masked && !fs.existsSync(path.resolve(baseDir, parsed.document))) {
|
|
57
95
|
throw new Error(`include target not found: ${parsed.document}`);
|
|
58
96
|
}
|
|
59
|
-
const
|
|
60
|
-
|
|
97
|
+
const docs = [];
|
|
98
|
+
for (const file of written) {
|
|
99
|
+
const target = path.resolve(baseDir, file);
|
|
100
|
+
if (stack.includes(target))
|
|
101
|
+
continue;
|
|
102
|
+
docs.push({
|
|
103
|
+
file,
|
|
104
|
+
node: walkNode(opts.parse(fs.readFileSync(target, 'utf-8')), path.dirname(target), [...stack, target]),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (docs.length === 0)
|
|
108
|
+
return [];
|
|
109
|
+
return unwrapRoot(keepBlocks((0, schema_1.runSelector)(selector, docs)));
|
|
61
110
|
}
|
|
62
111
|
if (Array.isArray(node.content))
|
|
63
112
|
return { ...node, content: walkList(node.content, baseDir, stack) };
|