podlite 0.0.79 → 0.0.81

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.
Files changed (112) hide show
  1. package/CHANGELOG.podlite +34 -0
  2. package/esm/cli.js +79 -11
  3. package/esm/cli.js.map +1 -1
  4. package/esm/lint/config.d.ts +2 -0
  5. package/esm/lint/config.js +46 -0
  6. package/esm/lint/config.js.map +1 -1
  7. package/esm/lint/grammar/lint.js +7 -4
  8. package/esm/lint/grammar/lint.js.map +1 -1
  9. package/esm/lint/grammar/scan.d.ts +1 -1
  10. package/esm/lint/grammar/scan.js +15 -2
  11. package/esm/lint/grammar/scan.js.map +1 -1
  12. package/esm/lint/index.d.ts +11 -1
  13. package/esm/lint/index.js +30 -18
  14. package/esm/lint/index.js.map +1 -1
  15. package/esm/lint/parallel.d.ts +4 -0
  16. package/esm/lint/parallel.js +57 -0
  17. package/esm/lint/parallel.js.map +1 -0
  18. package/esm/lint/rules/abbreviated-attrs.d.ts +4 -0
  19. package/esm/lint/rules/abbreviated-attrs.js +67 -0
  20. package/esm/lint/rules/abbreviated-attrs.js.map +1 -0
  21. package/esm/lint/rules/dead-definitions.d.ts +3 -0
  22. package/esm/lint/rules/dead-definitions.js +80 -0
  23. package/esm/lint/rules/dead-definitions.js.map +1 -0
  24. package/esm/lint/rules/index.js +6 -0
  25. package/esm/lint/rules/index.js.map +1 -1
  26. package/esm/lint/rules/link-file-resolves.d.ts +3 -0
  27. package/esm/lint/rules/link-file-resolves.js +58 -0
  28. package/esm/lint/rules/link-file-resolves.js.map +1 -0
  29. package/esm/lint/rules/link-not-empty.d.ts +3 -0
  30. package/esm/lint/rules/link-not-empty.js +15 -0
  31. package/esm/lint/rules/link-not-empty.js.map +1 -0
  32. package/esm/lint/rules/link-target-resolves.js +10 -28
  33. package/esm/lint/rules/link-target-resolves.js.map +1 -1
  34. package/esm/lint/rules/link-targets.d.ts +11 -0
  35. package/esm/lint/rules/link-targets.js +42 -0
  36. package/esm/lint/rules/link-targets.js.map +1 -0
  37. package/esm/lint/rules/markdown-in-pod.d.ts +4 -0
  38. package/esm/lint/rules/markdown-in-pod.js +67 -0
  39. package/esm/lint/rules/markdown-in-pod.js.map +1 -0
  40. package/esm/lint/rules/table-column-width.js +10 -6
  41. package/esm/lint/rules/table-column-width.js.map +1 -1
  42. package/esm/lint/rules/unclosed-markup-code.d.ts +4 -0
  43. package/esm/lint/rules/unclosed-markup-code.js +105 -0
  44. package/esm/lint/rules/unclosed-markup-code.js.map +1 -0
  45. package/esm/lint/types.d.ts +2 -0
  46. package/esm/lint/types.js +3 -1
  47. package/esm/lint/types.js.map +1 -1
  48. package/esm/lint/worker.d.ts +5 -0
  49. package/esm/lint/worker.js +15 -0
  50. package/esm/lint/worker.js.map +1 -0
  51. package/esm/query.js +4 -1
  52. package/esm/query.js.map +1 -1
  53. package/esm/resolve-includes.js +56 -7
  54. package/esm/resolve-includes.js.map +1 -1
  55. package/esm/version.d.ts +1 -1
  56. package/esm/version.js +1 -1
  57. package/lib/cli.js +78 -10
  58. package/lib/cli.js.map +1 -1
  59. package/lib/lint/config.d.ts +2 -0
  60. package/lib/lint/config.js +48 -0
  61. package/lib/lint/config.js.map +1 -1
  62. package/lib/lint/grammar/lint.js +7 -4
  63. package/lib/lint/grammar/lint.js.map +1 -1
  64. package/lib/lint/grammar/scan.d.ts +1 -1
  65. package/lib/lint/grammar/scan.js +14 -1
  66. package/lib/lint/grammar/scan.js.map +1 -1
  67. package/lib/lint/index.d.ts +11 -1
  68. package/lib/lint/index.js +69 -17
  69. package/lib/lint/index.js.map +1 -1
  70. package/lib/lint/parallel.d.ts +4 -0
  71. package/lib/lint/parallel.js +95 -0
  72. package/lib/lint/parallel.js.map +1 -0
  73. package/lib/lint/rules/abbreviated-attrs.d.ts +4 -0
  74. package/lib/lint/rules/abbreviated-attrs.js +71 -0
  75. package/lib/lint/rules/abbreviated-attrs.js.map +1 -0
  76. package/lib/lint/rules/dead-definitions.d.ts +3 -0
  77. package/lib/lint/rules/dead-definitions.js +83 -0
  78. package/lib/lint/rules/dead-definitions.js.map +1 -0
  79. package/lib/lint/rules/index.js +6 -0
  80. package/lib/lint/rules/index.js.map +1 -1
  81. package/lib/lint/rules/link-file-resolves.d.ts +3 -0
  82. package/lib/lint/rules/link-file-resolves.js +61 -0
  83. package/lib/lint/rules/link-file-resolves.js.map +1 -0
  84. package/lib/lint/rules/link-not-empty.d.ts +3 -0
  85. package/lib/lint/rules/link-not-empty.js +18 -0
  86. package/lib/lint/rules/link-not-empty.js.map +1 -0
  87. package/lib/lint/rules/link-target-resolves.js +9 -27
  88. package/lib/lint/rules/link-target-resolves.js.map +1 -1
  89. package/lib/lint/rules/link-targets.d.ts +11 -0
  90. package/lib/lint/rules/link-targets.js +47 -0
  91. package/lib/lint/rules/link-targets.js.map +1 -0
  92. package/lib/lint/rules/markdown-in-pod.d.ts +4 -0
  93. package/lib/lint/rules/markdown-in-pod.js +71 -0
  94. package/lib/lint/rules/markdown-in-pod.js.map +1 -0
  95. package/lib/lint/rules/table-column-width.js +9 -5
  96. package/lib/lint/rules/table-column-width.js.map +1 -1
  97. package/lib/lint/rules/unclosed-markup-code.d.ts +4 -0
  98. package/lib/lint/rules/unclosed-markup-code.js +109 -0
  99. package/lib/lint/rules/unclosed-markup-code.js.map +1 -0
  100. package/lib/lint/types.d.ts +2 -0
  101. package/lib/lint/types.js +4 -0
  102. package/lib/lint/types.js.map +1 -1
  103. package/lib/lint/worker.d.ts +5 -0
  104. package/lib/lint/worker.js +17 -0
  105. package/lib/lint/worker.js.map +1 -0
  106. package/lib/query.js +4 -1
  107. package/lib/query.js.map +1 -1
  108. package/lib/resolve-includes.js +55 -6
  109. package/lib/resolve-includes.js.map +1 -1
  110. package/lib/version.d.ts +1 -1
  111. package/lib/version.js +1 -1
  112. package/package.json +13 -7
@@ -1 +1 @@
1
- {"version":3,"file":"scan.js","sourceRoot":"","sources":["../../../src/lint/grammar/scan.ts"],"names":[],"mappings":"AACA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import { FileReport } from './formatters/text';
3
+ export type { Violation, Severity, LintConfig, LintContext, Rule, RuleSetting } from './types';
4
+ export type { FileReport } from './formatters/text';
5
+ export { ConfigError, findConfig, readConfig } from './config';
1
6
  export type LintFormat = 'text' | 'json';
2
7
  export type LintOptions = {
3
8
  strict: boolean;
4
9
  format: LintFormat;
5
10
  configPath?: string;
6
11
  stdinContent?: string;
12
+ enable?: string[];
13
+ disable?: string[];
7
14
  };
8
- export declare const STDIN_NAME = "<stdin>";
15
+ export declare function lintSource(content: string, filePath: string, config: LintConfig): FileReport;
16
+ export declare function lintFile(filePath: string, config: LintConfig): FileReport;
17
+ export declare function resolveConfig(files: string[], options: LintOptions): LintConfig;
18
+ export declare function reportLint(reports: FileReport[], options: LintOptions): number;
9
19
  export declare function runLint(files: string[], options: LintOptions): number;
package/esm/lint/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as path from 'path';
1
2
  import { makeSyntaxViolation } from './rules/syntax-valid';
2
3
  import { DEFAULT_RULES } from './rules';
3
4
  import { runRules } from './engine';
@@ -5,16 +6,17 @@ import { detectFileType, readFile, parseContent } from './loader';
5
6
  import { formatText } from './formatters/text';
6
7
  import { formatJson } from './formatters/json';
7
8
  import { scanSourceRules } from './grammar/scan';
8
- import { applyConfig, ConfigError, readConfig } from './config';
9
+ import { applyConfig, applyRuleFlags, ConfigError, findConfig, readConfig } from './config';
10
+ import { STDIN_NAME } from './types';
9
11
  import { applyMutes } from './mute';
12
+ export { ConfigError, findConfig, readConfig } from './config';
10
13
  // text handed to the command instead of a path is reported under this name
11
- export const STDIN_NAME = '<stdin>';
12
- function lintSource(content, filePath, config) {
13
- const violations = [...applyConfig(scanSourceRules(content), config)];
14
+ export function lintSource(content, filePath, config) {
14
15
  const fileType = detectFileType(filePath);
16
+ const violations = [...applyConfig(scanSourceRules(content, fileType), config)];
15
17
  try {
16
18
  const ast = parseContent(content, fileType);
17
- const ctx = { filePath, fileType, config };
19
+ const ctx = { filePath, fileType, config, source: content };
18
20
  violations.push(...runRules(ast, DEFAULT_RULES, ctx));
19
21
  const muted = applyMutes(violations, ast);
20
22
  return { filePath, violations: applyConfig(muted.kept, config), silenced: muted.silenced };
@@ -24,7 +26,7 @@ function lintSource(content, filePath, config) {
24
26
  }
25
27
  return { filePath, violations };
26
28
  }
27
- function lintFile(filePath, config) {
29
+ export function lintFile(filePath, config) {
28
30
  let content;
29
31
  try {
30
32
  content = readFile(filePath);
@@ -43,10 +45,30 @@ function lintFile(filePath, config) {
43
45
  }
44
46
  return lintSource(content, filePath, config);
45
47
  }
48
+ // Thrown out of resolveConfig so a caller can turn it into exit code 2 wherever
49
+ // the run is scheduled from.
50
+ export function resolveConfig(files, options) {
51
+ const searchFrom = files.length > 0 ? path.dirname(path.resolve(files[0])) : process.cwd();
52
+ const configPath = options.configPath || findConfig(searchFrom);
53
+ return applyRuleFlags(readConfig(configPath), options.enable || [], options.disable || []);
54
+ }
55
+ export function reportLint(reports, options) {
56
+ const output = options.format === 'json' ? formatJson(reports) : formatText(reports, { color: process.stdout.isTTY === true });
57
+ if (output)
58
+ process.stdout.write(output);
59
+ const totals = reports.flatMap(r => r.violations);
60
+ const hasError = totals.some(v => v.severity === 'error');
61
+ const hasWarning = totals.some(v => v.severity === 'warning');
62
+ if (hasError)
63
+ return 1;
64
+ if (options.strict && hasWarning)
65
+ return 1;
66
+ return 0;
67
+ }
46
68
  export function runLint(files, options) {
47
69
  let config;
48
70
  try {
49
- config = readConfig(options.configPath);
71
+ config = resolveConfig(files, options);
50
72
  }
51
73
  catch (e) {
52
74
  if (!(e instanceof ConfigError))
@@ -58,16 +80,6 @@ export function runLint(files, options) {
58
80
  if (options.stdinContent !== undefined) {
59
81
  reports.push(lintSource(options.stdinContent, STDIN_NAME, config));
60
82
  }
61
- const output = options.format === 'json' ? formatJson(reports) : formatText(reports, { color: process.stdout.isTTY === true });
62
- if (output)
63
- process.stdout.write(output);
64
- const totals = reports.flatMap(r => r.violations);
65
- const hasError = totals.some(v => v.severity === 'error');
66
- const hasWarning = totals.some(v => v.severity === 'warning');
67
- if (hasError)
68
- return 1;
69
- if (options.strict && hasWarning)
70
- return 1;
71
- return 0;
83
+ return reportLint(reports, options);
72
84
  }
73
85
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lint/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACjE,OAAO,EAAE,UAAU,EAAc,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAWnC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAA;AAEnC,SAAS,UAAU,CAAC,OAAe,EAAE,QAAgB,EAAE,MAAkB;IACvE,MAAM,UAAU,GAAgB,CAAC,GAAG,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;IAClF,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAA;IACzC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QAC3C,MAAM,GAAG,GAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;QACvD,UAAU,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,GAA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AO,CAAC,CAAA;IACV,CAAC;IAED,MAAM,OAAO,GAAiB,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;IAC/E,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,CAAA;IACpE,CAAC;IAED,OAAO,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACrC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { LintConfig } from './types';
2
+ import type { FileReport } from './formatters/text';
3
+ export declare const worthThreads: (files: string[]) => boolean;
4
+ export declare function lintFilesInParallel(files: string[], config: LintConfig): Promise<FileReport[]>;
@@ -0,0 +1,57 @@
1
+ import * as fs from 'fs';
2
+ import * as os from 'os';
3
+ import * as path from 'path';
4
+ import { Worker } from 'worker_threads';
5
+ import { lintFile } from './index';
6
+ // Measured on a 126-file corpus: reading takes 5 ms and parsing 1032 ms, so the
7
+ // work is bound by the processor and threads are what buys anything. Eight of
8
+ // them start in 80 ms together, which pays for itself only on a longer list.
9
+ const MIN_FILES = 12;
10
+ const threadCount = (files) => Math.max(2, Math.min(os.cpus().length - 2, 8, Math.floor(files / 4)));
11
+ const workerFile = () => {
12
+ const candidate = path.join(__dirname, 'worker.js');
13
+ return fs.existsSync(candidate) ? candidate : undefined;
14
+ };
15
+ export const worthThreads = (files) => files.length >= MIN_FILES && workerFile() !== undefined;
16
+ // Reports come back in the order the files were given, whichever thread got
17
+ // there first: the report is read by a person and by a snapshot test, and both
18
+ // expect the order they asked for.
19
+ export function lintFilesInParallel(files, config) {
20
+ const script = workerFile();
21
+ if (!script)
22
+ return Promise.resolve(files.map(f => lintFile(f, config)));
23
+ const threads = threadCount(files.length);
24
+ const jobs = files.map((filePath, index) => ({ index, filePath }));
25
+ const chunks = Array.from({ length: threads }, () => []);
26
+ jobs.forEach(job => chunks[job.index % threads].push(job));
27
+ return new Promise((resolve, reject) => {
28
+ const collected = new Array(files.length);
29
+ const workers = [];
30
+ let finished = 0;
31
+ let failed = false;
32
+ const stop = () => workers.forEach(w => void w.terminate());
33
+ for (let i = 0; i < threads; i++) {
34
+ const worker = new Worker(script);
35
+ workers.push(worker);
36
+ worker.on('message', (message) => {
37
+ if (message === 'ready') {
38
+ worker.postMessage({ config, jobs: chunks[i] });
39
+ return;
40
+ }
41
+ for (const item of message)
42
+ collected[item.index] = item.report;
43
+ void worker.terminate();
44
+ if (++finished === threads && !failed)
45
+ resolve(collected);
46
+ });
47
+ worker.on('error', err => {
48
+ if (failed)
49
+ return;
50
+ failed = true;
51
+ stop();
52
+ reject(err);
53
+ });
54
+ }
55
+ });
56
+ }
57
+ //# sourceMappingURL=parallel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parallel.js","sourceRoot":"","sources":["../../src/lint/parallel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGvC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGlC,gFAAgF;AAChF,8EAA8E;AAC9E,6EAA6E;AAC7E,MAAM,SAAS,GAAG,EAAE,CAAA;AAEpB,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AAEpH,MAAM,UAAU,GAAG,GAAuB,EAA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AAC"}
@@ -0,0 +1,4 @@
1
+ import type { Violation, SourceRule } from '../types';
2
+ export declare const ABBREVIATED_ATTRS_RULE_ID = "abbreviated-attrs";
3
+ export declare const abbreviatedAttrsRule: SourceRule;
4
+ export declare function scanAbbreviatedAttrs(content: string): Violation[];
@@ -0,0 +1,67 @@
1
+ import { isVerbatimBlock } from '@podlite/schema';
2
+ export const ABBREVIATED_ATTRS_RULE_ID = 'abbreviated-attrs';
3
+ export const abbreviatedAttrsRule = {
4
+ id: ABBREVIATED_ATTRS_RULE_ID,
5
+ severity: 'warning',
6
+ };
7
+ // The specification is plain about it: the rest of an abbreviated block's line
8
+ // is block data, not configuration. What the author wrote as an attribute
9
+ // arrives as text, the markup stays legal, and nothing says the mechanism did
10
+ // not run.
11
+ const ABBREVIATED = /^\s*=([A-Za-z][\w-]*)[ \t]+(\S.*)$/;
12
+ const DELIMITED = /^\s*=(?:begin|end|for)[ \t]+([\w-]+)/;
13
+ // Only a line made of attributes and nothing else is reported. A line where
14
+ // attributes stand next to real text is the author writing prose that happens
15
+ // to hold a colon, and calling that a fault would bury the rule in noise.
16
+ const ONLY_ATTRIBUTES = /^(:[A-Za-z][\w-]*(<[^>]*>|\([^)]*\)|\{[^}]*\}|\[[^\]]*\])?[ \t]*)+$/;
17
+ // An attribute written with nothing inside documents the attribute itself,
18
+ // which is how the registries and the specifications spell one out.
19
+ const EMPTY_VALUE = /^:[A-Za-z][\w-]*<>$/;
20
+ const allEmpty = (rest) => rest
21
+ .trim()
22
+ .split(/[ \t]+/)
23
+ .every(part => EMPTY_VALUE.test(part));
24
+ export function scanAbbreviatedAttrs(content) {
25
+ const lines = content.split(/\r?\n/);
26
+ const open = [];
27
+ const violations = [];
28
+ for (let i = 0; i < lines.length; i++) {
29
+ const line = lines[i];
30
+ const delimited = line.match(DELIMITED);
31
+ if (delimited) {
32
+ if (/^\s*=end\b/.test(line))
33
+ open.pop();
34
+ else if (/^\s*=begin\b/.test(line))
35
+ open.push(delimited[1]);
36
+ continue;
37
+ }
38
+ if (open.some(isVerbatimBlock))
39
+ continue;
40
+ const abbreviated = line.match(ABBREVIATED);
41
+ if (!abbreviated)
42
+ continue;
43
+ const [, name, rest] = abbreviated;
44
+ if (isVerbatimBlock(name))
45
+ continue;
46
+ if (!ONLY_ATTRIBUTES.test(rest.trim()))
47
+ continue;
48
+ if (allEmpty(rest))
49
+ continue;
50
+ // content has to follow, otherwise the line is the whole block and the
51
+ // author wrote no data at all — a different mistake, if it is one
52
+ const next = lines[i + 1];
53
+ if (next === undefined || next.trim() === '' || /^\s*=/.test(next))
54
+ continue;
55
+ violations.push({
56
+ rule: ABBREVIATED_ATTRS_RULE_ID,
57
+ severity: 'warning',
58
+ message: `=${name} takes the rest of its line as data, so ${rest.trim()} arrives as text; write =for ${name} to pass configuration`,
59
+ location: {
60
+ start: { line: i + 1, column: 1, offset: 0 },
61
+ end: { line: i + 1, column: 1, offset: 0 },
62
+ },
63
+ });
64
+ }
65
+ return violations;
66
+ }
67
+ //# 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":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAGjD,MAAM,CAAC,MAAM,yBAAyB,GAAG,mBAAmB,CAAA;AAE5D,MAAM,CAAC,MAAM,oBAAoB,GAAe;IAC9C,EAAE,EAAE,yBAAyB;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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YAAE,SAAQ;QAChD,IAAI,QAAQ,CAAC,IAAI,CAAC;YAAE,SAAQ;QAE5B,uEAAuE;QACvE,kEAAkE;QAClE,MAAM,IAAI,GAAG,KAAK,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,yBAAyB;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"}
@@ -0,0 +1,3 @@
1
+ import type { Rule } from '../types';
2
+ export declare const DEAD_DEFINITIONS_RULE_ID = "dead-definitions";
3
+ export declare const deadDefinitionsRule: Rule;
@@ -0,0 +1,80 @@
1
+ import { getFromTree, getTextContentFromNode } from '@podlite/schema';
2
+ export const DEAD_DEFINITIONS_RULE_ID = 'dead-definitions';
3
+ const attr = (node, name) => {
4
+ const item = (Array.isArray(node.config) ? node.config : []).find(c => c && c.name === name);
5
+ return item && item.value !== undefined && item.value !== null ? String(item.value) : undefined;
6
+ };
7
+ // An alias node carries no location, so the line is read back from the source;
8
+ // a warning that cannot say where is a warning the author cannot act on.
9
+ const aliasLine = (source, name) => {
10
+ const lines = source.split(/\r?\n/);
11
+ const at = lines.findIndex(line => new RegExp(`^\\s*=alias\\s+${name}(\\s|$)`).test(line));
12
+ if (at === -1)
13
+ return undefined;
14
+ return { start: { line: at + 1, column: 1, offset: 0 }, end: { line: at + 1, column: 1, offset: 0 } };
15
+ };
16
+ const definitions = (ast) => {
17
+ const nodes = getFromTree(ast, () => true);
18
+ const found = [];
19
+ for (const node of nodes) {
20
+ if (node.type === 'alias' && node.name) {
21
+ found.push({ kind: 'alias', name: node.name, location: node.location });
22
+ continue;
23
+ }
24
+ if (node.name === 'data') {
25
+ const key = attr(node, 'key');
26
+ if (key)
27
+ found.push({ kind: 'data', name: key, location: node.location });
28
+ }
29
+ }
30
+ return found;
31
+ };
32
+ const aliasUses = (ast) => {
33
+ const nodes = getFromTree(ast, () => true);
34
+ const used = new Set();
35
+ for (const node of nodes) {
36
+ if (node.type !== 'fcode' || node.name !== 'A')
37
+ continue;
38
+ const name = getTextContentFromNode(node)
39
+ ?.toString()
40
+ .trim();
41
+ if (name)
42
+ used.add(name);
43
+ }
44
+ return used;
45
+ };
46
+ // A data reference is read from the source rather than from the tree: the block
47
+ // that consumes it resolves the reference while the tree is built, so by the
48
+ // time a rule sees the tree the mention is already gone.
49
+ const dataUses = (source) => {
50
+ const used = new Set();
51
+ const reference = /data:([A-Za-z0-9_-]+)/g;
52
+ let match;
53
+ while ((match = reference.exec(source)) !== null)
54
+ used.add(match[1]);
55
+ return used;
56
+ };
57
+ export const deadDefinitionsRule = {
58
+ id: DEAD_DEFINITIONS_RULE_ID,
59
+ severity: 'warning',
60
+ check: (ast, ctx) => {
61
+ // without the source a data reference cannot be found at all, and reporting
62
+ // every keyed block as dead would be worse than saying nothing
63
+ const declared = definitions(ast).filter(item => item.kind === 'alias' || ctx.source !== undefined);
64
+ if (declared.length === 0)
65
+ return [];
66
+ const aliases = aliasUses(ast);
67
+ const keys = dataUses(ctx.source || '');
68
+ return declared
69
+ .filter(item => !(item.kind === 'alias' ? aliases.has(item.name) : keys.has(item.name)))
70
+ .map(item => ({
71
+ rule: DEAD_DEFINITIONS_RULE_ID,
72
+ severity: 'warning',
73
+ message: item.kind === 'alias'
74
+ ? `=alias ${item.name} is never used; A<${item.name}> appears nowhere in the document`
75
+ : `=data :key<${item.name}> is never used; data:${item.name} appears nowhere in the document`,
76
+ location: item.location || (item.kind === 'alias' ? aliasLine(ctx.source || '', item.name) : undefined),
77
+ }));
78
+ },
79
+ };
80
+ //# 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,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAmB,MAAM,iBAAiB,CAAA;AAGtF,MAAM,CAAC,MAAM,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,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;IAC5F,OAAO,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACjG,CAAC,CAAA;AAED,+EAA+E;AAC/E,yEAAyE;AACzE,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,IAAY,EAAqC,EAAE;IACpF,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACnC,MAAM,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,MAAM,CA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AAK,SAAS,CAAC,CAAA;QACnG,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAA;QAEpC,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;QAC9B,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;QAEvC,OAAO,QAAQ;aACZ,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;aACvF,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACZ,IAAI,EAAE,wBAAwB;YAC9B,QAAQ,EAAE,SAAkB;YAC5B,OAAO,EACL,IAAI,CAAC,IAAI,KAAK,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"}
@@ -3,15 +3,21 @@ import { headingHierarchyRule } from './heading-hierarchy';
3
3
  import { idUniqueRule } from './id-unique';
4
4
  import { mediaAbsoluteFileRule } from './media-absolute-file';
5
5
  import { linkTargetResolvesRule } from './link-target-resolves';
6
+ import { linkFileResolvesRule } from './link-file-resolves';
7
+ import { linkNotEmptyRule } from './link-not-empty';
6
8
  import { attrValueDroppedRule } from './attr-value-dropped';
7
9
  import { tableShapeRule } from './table-shape';
10
+ import { deadDefinitionsRule } from './dead-definitions';
8
11
  export const DEFAULT_RULES = [
9
12
  syntaxValidRule,
10
13
  headingHierarchyRule,
11
14
  idUniqueRule,
12
15
  mediaAbsoluteFileRule,
13
16
  linkTargetResolvesRule,
17
+ linkFileResolvesRule,
18
+ linkNotEmptyRule,
14
19
  attrValueDroppedRule,
15
20
  tableShapeRule,
21
+ deadDefinitionsRule,
16
22
  ];
17
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lint/rules/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,eAAe;IACf,oBAAoB;IACpB,YAAY;IACZ,qBAAqB;IACrB,sBAAsB;IACtB,oBAAoB;IACpB,cAAc;CACf,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lint/rules/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,eAAe;IACf,oBAAoB;IACpB,YAAY;IACZ,qBAAqB;IACrB,sBAAsB;IACtB,oBAAoB;IACpB,gBAAgB;IAChB,oBAAoB;IACpB,cAAc;IACd,mBAAmB;CACpB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Rule } from '../types';
2
+ export declare const LINK_FILE_RESOLVES_RULE_ID = "link-file-resolves";
3
+ export declare const linkFileResolvesRule: Rule;
@@ -0,0 +1,58 @@
1
+ import { existsSync, statSync } from 'fs';
2
+ import { dirname, isAbsolute, resolve } from 'path';
3
+ import { STDIN_NAME } from '../types';
4
+ import { collectLinks, readAddress } from './link-targets';
5
+ export const LINK_FILE_RESOLVES_RULE_ID = 'link-file-resolves';
6
+ // Written with `./` or `../`, the author has declared a path as plainly as a
7
+ // scheme would. A bare word declares nothing in a Podlite document, though in a
8
+ // markdown one it is the ordinary way to write a relative link. A leading slash
9
+ // reads as the root of a site far more often than the root of a disk, so it is
10
+ // left to the author to say `file:` when a disk is what was meant.
11
+ const looksLikePath = (path) => path.startsWith('./') || path.startsWith('../');
12
+ // Relative targets are answered from the directory of the document, so a caller
13
+ // that passed a name rather than a path gets no answer at all: resolving it
14
+ // would silently measure whatever sits in the working directory instead.
15
+ const documentDirectory = (filePath) => {
16
+ if (filePath === STDIN_NAME)
17
+ return null;
18
+ const full = resolve(filePath);
19
+ if (!existsSync(full) || !statSync(full).isFile())
20
+ return null;
21
+ return dirname(full);
22
+ };
23
+ // A home-relative path answers differently on every machine, so a check of it
24
+ // would make the run depend on who is running it.
25
+ const isHomeRelative = (path) => path === '~' || path.startsWith('~/');
26
+ const candidatePath = (target, fileType) => {
27
+ if (!target || target.startsWith('#'))
28
+ return null;
29
+ const { scheme, path } = readAddress(target);
30
+ if (scheme !== null && scheme !== 'file')
31
+ return null;
32
+ if (!path || isHomeRelative(path))
33
+ return null;
34
+ if (scheme === 'file')
35
+ return path;
36
+ if (path.startsWith('/'))
37
+ return null;
38
+ return fileType === 'md' || looksLikePath(path) ? path : null;
39
+ };
40
+ export const linkFileResolvesRule = {
41
+ id: LINK_FILE_RESOLVES_RULE_ID,
42
+ severity: 'warning',
43
+ check: (ast, ctx) => {
44
+ const base = documentDirectory(ctx.filePath);
45
+ if (base === null)
46
+ return [];
47
+ return collectLinks(ast)
48
+ .map(site => ({ site, path: candidatePath(site.target, ctx.fileType) }))
49
+ .filter(({ path }) => path !== null && !existsSync(isAbsolute(path) ? path : resolve(base, path)))
50
+ .map(({ site }) => ({
51
+ rule: LINK_FILE_RESOLVES_RULE_ID,
52
+ severity: 'warning',
53
+ message: `Link target ${site.target} is not there`,
54
+ location: site.at,
55
+ }));
56
+ },
57
+ };
58
+ //# sourceMappingURL=link-file-resolves.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link-file-resolves.js","sourceRoot":"","sources":["../../../src/lint/rules/link-file-resolves.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE1D,MAAM,CAAC,MAAM,0BAA0B,GAAG,oBAAoB,CAAA;AAE9D,6EAA6E;AAC7E,gF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collectLinks } from './link-targets';
2
+ export const LINK_NOT_EMPTY_RULE_ID = 'link-not-empty';
3
+ export const linkNotEmptyRule = {
4
+ id: LINK_NOT_EMPTY_RULE_ID,
5
+ severity: 'error',
6
+ check: (ast, _ctx) => collectLinks(ast)
7
+ .filter(({ target }) => target === '')
8
+ .map(({ at }) => ({
9
+ rule: LINK_NOT_EMPTY_RULE_ID,
10
+ severity: 'error',
11
+ message: 'Link has no address to go to',
12
+ location: at,
13
+ })),
14
+ };
15
+ //# sourceMappingURL=link-not-empty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link-not-empty.js","sourceRoot":"","sources":["../../../src/lint/rules/link-not-empty.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAA;AAEtD,MAAM,CAAC,MAAM,gBAAgB,GAAS;IACpC,EAAE,EAAE,sBAAsB;IAC1B,QAAQ,EAAE,OAAO;IACjB,KAAK,EAAE,CAAC,GAAoB,EAAE,IAAiB,EAAe,EAAE,CAC9D,YAAY,CAAC,GAAG,CAAC;SACd,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,KAAK,EAAE,CAAC;SACrC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAChB,IAAI,EAAE,sBAAsB;QAC5B,QAAQ,EAAE,OAAgB;QAC1B,OAAO,EAAE,8BAA8B;QACvC,QAAQ,EAAE,EAAE;KACb,CAAC,CAAC;CACR,CAAA"}
@@ -1,40 +1,22 @@
1
- import { findAnchor, indexAnchors, toFragment } from '@podlite/schema';
2
- import { collectExplicitIds } from './id-unique';
1
+ import { bindTarget, buildBindingIndex } from '@podlite/schema';
2
+ import { collectLinks } from './link-targets';
3
3
  export const LINK_TARGET_RESOLVES_RULE_ID = 'link-target-resolves';
4
- // A link without display text carries the target in its content instead of meta.
5
- const linkTarget = (node) => {
6
- if (typeof node.meta === 'string')
7
- return node.meta.trim();
8
- const content = Array.isArray(node.content) ? node.content : [];
9
- const first = content[0];
10
- return typeof first === 'string' ? first.trim() : '';
11
- };
12
- // Inline nodes carry no location, so the nearest enclosing block supplies one.
13
- const collectAnchors = (node, at) => {
14
- if (Array.isArray(node))
15
- return node.flatMap(child => collectAnchors(child, at));
16
- if (!node || typeof node !== 'object')
17
- return [];
18
- const n = node;
19
- const here = n.location || at;
20
- const found = n.type === 'fcode' && (n.name === 'L' || n.name === 'W') ? [{ target: linkTarget(n), at: here }] : [];
21
- return [...found, ...collectAnchors(n.content, here)];
22
- };
23
4
  export const linkTargetResolvesRule = {
24
5
  id: LINK_TARGET_RESOLVES_RULE_ID,
25
6
  severity: 'error',
26
7
  check: (ast, _ctx) => {
27
- const anchors = collectAnchors(ast).filter(({ target }) => target.startsWith('#'));
8
+ // A bare # is left alone by the export — it is not a target and not a mistake —
9
+ // so the rule has nothing to say about it either.
10
+ const anchors = collectLinks(ast).filter(({ target }) => target.startsWith('#') && target !== '#');
28
11
  if (anchors.length === 0)
29
12
  return [];
30
13
  // Both ways an anchor can exist: written by the author as :id, or carried by a
31
14
  // heading under its own name. Matched the way the exporter matches them.
32
- const written = new Set(collectExplicitIds(ast).map(entry => toFragment(entry.value)));
33
- const headings = indexAnchors(ast);
34
- const resolves = (target) => {
35
- const name = target.slice(1);
36
- return written.has(toFragment(name)) || findAnchor(name, headings) !== undefined;
37
- };
15
+ // Asked of the same binding the exporters ask, rather than worked out again here.
16
+ // Two answers to one question is how this rule came to call a link sound that the
17
+ // export could not resolve: it shaped both sides itself, and the export did not.
18
+ const index = buildBindingIndex(ast);
19
+ const resolves = (target) => bindTarget(target.slice(1), index).found;
38
20
  return anchors
39
21
  .filter(({ target }) => !resolves(target))
40
22
  .map(({ target, at }) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"link-target-resolves.js","sourceRoot":"","sources":["../../../src/lint/rules/link-target-resolves.ts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AAO;aACX,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;aACzC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YACxB,IAAI,EAAE,4BAA4B;YAClC,QAAQ,EAAE,OAAgB;YAC1B,OAAO,EAAE,eAAe,MAAM,gCAAgC;YAC9D,QAAQ,EAAE,EAAE;SACb,CAAC,CAAC,CAAA;IACP,CAAC;CACF,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { Violation } from '../types';
2
+ export type LinkSite = {
3
+ target: string;
4
+ at?: Violation['location'];
5
+ };
6
+ export declare const collectLinks: (node: unknown, at?: Violation["location"]) => LinkSite[];
7
+ export type LinkAddress = {
8
+ scheme: string | null;
9
+ path: string;
10
+ };
11
+ export declare const readAddress: (target: string) => LinkAddress;