@descent-vtt/spec-guard 0.3.0 → 0.5.0
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 +125 -0
- package/README.md +292 -49
- package/dist/cli.d.ts +9 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +46 -7
- package/dist/cli.js.map +1 -1
- package/dist/comments.d.ts +23 -4
- package/dist/comments.d.ts.map +1 -1
- package/dist/comments.js +40 -14
- package/dist/comments.js.map +1 -1
- package/dist/engine.d.ts +52 -49
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +185 -259
- package/dist/engine.js.map +1 -1
- package/dist/glob.d.ts +19 -6
- package/dist/glob.d.ts.map +1 -1
- package/dist/glob.js +14 -28
- package/dist/glob.js.map +1 -1
- package/dist/imports.d.ts +28 -4
- package/dist/imports.d.ts.map +1 -1
- package/dist/imports.js +36 -4
- package/dist/imports.js.map +1 -1
- package/dist/index.d.ts +15 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +28 -23
- package/dist/parser.js.map +1 -1
- package/dist/polyglot.d.ts +129 -0
- package/dist/polyglot.d.ts.map +1 -0
- package/dist/polyglot.js +544 -0
- package/dist/polyglot.js.map +1 -0
- package/dist/reporter.d.ts +41 -0
- package/dist/reporter.d.ts.map +1 -1
- package/dist/reporter.js +187 -4
- package/dist/reporter.js.map +1 -1
- package/dist/runner.d.ts +47 -3
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +371 -105
- package/dist/runner.js.map +1 -1
- package/dist/scope.d.ts +108 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +115 -0
- package/dist/scope.js.map +1 -0
- package/dist/text.d.ts +26 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +69 -0
- package/dist/text.js.map +1 -0
- package/dist/types.d.ts +87 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { createRequire } from 'node:module';
|
|
10
10
|
import path from 'node:path';
|
|
11
|
-
import { formatJson, formatReport, shouldUseAscii, shouldUseColor } from './reporter.js';
|
|
11
|
+
import { formatBaselines, formatJson, formatReport, formatSarif, shouldUseAscii, shouldUseColor } from './reporter.js';
|
|
12
12
|
import { DEFAULT_CONCURRENCY, DEFAULT_MAX_SNIPPETS, runSpecGuard } from './runner.js';
|
|
13
13
|
export const EXIT_OK = 0;
|
|
14
14
|
export const EXIT_FAILED = 1;
|
|
15
15
|
export const EXIT_ERROR = 2;
|
|
16
16
|
export class UsageError extends Error {
|
|
17
17
|
}
|
|
18
|
-
function version() {
|
|
18
|
+
export function version() {
|
|
19
19
|
try {
|
|
20
20
|
const require = createRequire(import.meta.url);
|
|
21
21
|
const pkg = require('../package.json');
|
|
@@ -39,15 +39,19 @@ Options
|
|
|
39
39
|
-r, --root <path> Codebase root that assertions are resolved against (default: cwd)
|
|
40
40
|
-v, --verbose Print passing assertions too
|
|
41
41
|
--fail-fast Stop at the first failing assertion
|
|
42
|
-
--json Emit a machine-readable JSON report
|
|
42
|
+
--json Emit a machine-readable JSON report (same as --format json)
|
|
43
|
+
--format <name> human | json | sarif (sarif uploads to GitHub code scanning)
|
|
43
44
|
--engine <name> auto | rg | js (default: auto - scanner for small trees, ripgrep for big ones)
|
|
44
45
|
--strict Treat analysis that could not be completed as a failure
|
|
45
46
|
--allow-missing-targets
|
|
46
47
|
Tolerate target paths that do not exist (they fail by default)
|
|
48
|
+
--allow-empty-scope Tolerate assertions whose scope holds no files (they fail by default)
|
|
49
|
+
--print-baseline Print the baseline="..." that would exempt today's violations, and exit
|
|
50
|
+
--no-default-skips Search .git, .hg, .svn and node_modules too
|
|
47
51
|
--include-specs Also count matches inside the spec files themselves
|
|
48
52
|
--max-snippets <n> Failure snippets per assertion (default: ${DEFAULT_MAX_SNIPPETS})
|
|
49
53
|
--concurrency <n> Assertions executed in parallel (default: ${DEFAULT_CONCURRENCY})
|
|
50
|
-
--allow-empty Exit 0 when no spec files matched
|
|
54
|
+
--allow-empty Exit 0 when no spec files matched (about the run, not an assertion)
|
|
51
55
|
--color/--no-color Force colour on or off (NO_COLOR is honoured)
|
|
52
56
|
-h, --help Show this help
|
|
53
57
|
--version Print the version
|
|
@@ -58,6 +62,7 @@ Directives
|
|
|
58
62
|
<!-- @assert-present file="SECURITY.md" -->
|
|
59
63
|
|
|
60
64
|
Matches inside comments do not count; add comments="include" to count them.
|
|
65
|
+
An assertion whose scope holds no files fails; add allow-empty="true" to allow it.
|
|
61
66
|
|
|
62
67
|
Exit codes
|
|
63
68
|
0 all assertions passed 1 an assertion failed 2 spec-guard could not run`;
|
|
@@ -96,10 +101,14 @@ export function parseArgs(argv, cwd) {
|
|
|
96
101
|
root: cwd,
|
|
97
102
|
verbose: false,
|
|
98
103
|
failFast: false,
|
|
104
|
+
format: 'human',
|
|
99
105
|
json: false,
|
|
100
106
|
engine: 'auto',
|
|
101
107
|
allowMissingTargets: false,
|
|
108
|
+
defaultSkips: true,
|
|
102
109
|
strictTargets: false,
|
|
110
|
+
allowEmptyScope: false,
|
|
111
|
+
printBaseline: false,
|
|
103
112
|
includeSpecs: false,
|
|
104
113
|
allowEmpty: false,
|
|
105
114
|
maxSnippets: DEFAULT_MAX_SNIPPETS,
|
|
@@ -144,13 +153,32 @@ export function parseArgs(argv, cwd) {
|
|
|
144
153
|
break;
|
|
145
154
|
case '--json':
|
|
146
155
|
options.json = true;
|
|
156
|
+
options.format = 'json';
|
|
147
157
|
break;
|
|
158
|
+
case '--format': {
|
|
159
|
+
const value = nextValue().toLowerCase();
|
|
160
|
+
if (value !== 'human' && value !== 'json' && value !== 'sarif') {
|
|
161
|
+
throw new UsageError(`Unknown format "${value}". Expected human, json or sarif.`);
|
|
162
|
+
}
|
|
163
|
+
options.format = value;
|
|
164
|
+
options.json = value === 'json';
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
148
167
|
case '--strict':
|
|
149
168
|
options.strictTargets = true;
|
|
150
169
|
break;
|
|
151
170
|
case '--allow-missing-targets':
|
|
152
171
|
options.allowMissingTargets = true;
|
|
153
172
|
break;
|
|
173
|
+
case '--allow-empty-scope':
|
|
174
|
+
options.allowEmptyScope = true;
|
|
175
|
+
break;
|
|
176
|
+
case '--print-baseline':
|
|
177
|
+
options.printBaseline = true;
|
|
178
|
+
break;
|
|
179
|
+
case '--no-default-skips':
|
|
180
|
+
options.defaultSkips = false;
|
|
181
|
+
break;
|
|
154
182
|
case '--include-specs':
|
|
155
183
|
options.includeSpecs = true;
|
|
156
184
|
break;
|
|
@@ -227,6 +255,8 @@ export async function main(argv = process.argv.slice(2), io = defaultIO()) {
|
|
|
227
255
|
engine: options.engine,
|
|
228
256
|
failFast: options.failFast,
|
|
229
257
|
allowMissingTargets: options.allowMissingTargets,
|
|
258
|
+
allowEmptyScope: options.allowEmptyScope,
|
|
259
|
+
defaultSkips: options.defaultSkips,
|
|
230
260
|
strictTargets: options.strictTargets,
|
|
231
261
|
includeSpecs: options.includeSpecs,
|
|
232
262
|
concurrency: options.concurrency,
|
|
@@ -238,15 +268,24 @@ export async function main(argv = process.argv.slice(2), io = defaultIO()) {
|
|
|
238
268
|
return EXIT_ERROR;
|
|
239
269
|
}
|
|
240
270
|
if (report.summary.specs === 0) {
|
|
241
|
-
if (options.
|
|
242
|
-
io.stdout(formatJson(report));
|
|
271
|
+
if (options.format !== 'human') {
|
|
272
|
+
io.stdout(options.format === 'sarif' ? formatSarif(report, { version: version() }) : formatJson(report));
|
|
243
273
|
}
|
|
244
274
|
else {
|
|
245
275
|
io.stderr(`spec-guard: no spec files matched ${options.patterns.map((p) => `"${p}"`).join(', ')}`);
|
|
246
276
|
}
|
|
247
277
|
return options.allowEmpty ? EXIT_OK : EXIT_ERROR;
|
|
248
278
|
}
|
|
249
|
-
if (options.
|
|
279
|
+
if (options.printBaseline) {
|
|
280
|
+
// Printed, never written. See formatBaselines for why that distinction is
|
|
281
|
+
// the whole design and not a missing feature.
|
|
282
|
+
io.stdout(formatBaselines(report));
|
|
283
|
+
return report.ok ? EXIT_OK : EXIT_FAILED;
|
|
284
|
+
}
|
|
285
|
+
if (options.format === 'sarif') {
|
|
286
|
+
io.stdout(formatSarif(report, { version: version() }));
|
|
287
|
+
}
|
|
288
|
+
else if (options.format === 'json') {
|
|
250
289
|
io.stdout(formatJson(report));
|
|
251
290
|
}
|
|
252
291
|
else {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACvH,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGtF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAoC5B,MAAM,OAAO,UAAW,SAAQ,KAAK;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AK,EAAE,cAAc,CAAC,EAAE,CAAC,GAAG,CAAC;SAC9B,EACD,OAAO,CAAC,WAAW,CACpB,CACF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC;AAC3C,CAAC"}
|
package/dist/comments.d.ts
CHANGED
|
@@ -45,14 +45,31 @@ export interface CommentSyntax {
|
|
|
45
45
|
}
|
|
46
46
|
/** The comment syntax for a path, or null when the language is unknown. */
|
|
47
47
|
export declare function syntaxFor(filePath: string): CommentSyntax | null;
|
|
48
|
+
export declare function syntaxNamed(name: string): CommentSyntax | null;
|
|
48
49
|
/** Half-open [start, end) offsets that are comment text. */
|
|
49
50
|
export type CommentRange = readonly [number, number];
|
|
51
|
+
/** Everything one pass over a source file knows about its comments and literals. */
|
|
52
|
+
export interface LexResult {
|
|
53
|
+
/** Half-open ranges of comment text, in ascending order. */
|
|
54
|
+
comments: CommentRange[];
|
|
55
|
+
/** Half-open ranges of string literals, delimiters included. */
|
|
56
|
+
strings: CommentRange[];
|
|
57
|
+
/**
|
|
58
|
+
* True when a string or block comment ran off the end of the file.
|
|
59
|
+
*
|
|
60
|
+
* The ranges are still returned - reading an unterminated literal to EOF is
|
|
61
|
+
* what a compiler does - but everything after the opening delimiter was
|
|
62
|
+
* swallowed by it, so anything derived from this scan is missing whatever
|
|
63
|
+
* lived in there. Callers that draw conclusions from absence must say so.
|
|
64
|
+
*/
|
|
65
|
+
unterminated: boolean;
|
|
66
|
+
}
|
|
50
67
|
/**
|
|
51
|
-
* Finds every comment in the source.
|
|
68
|
+
* Finds every comment and string literal in the source.
|
|
52
69
|
*
|
|
53
|
-
* One pass,
|
|
54
|
-
*
|
|
55
|
-
*
|
|
70
|
+
* One pass, because the two questions are the same question: a comment marker
|
|
71
|
+
* inside a literal is not a comment, and a quote inside a comment does not open
|
|
72
|
+
* one. Two passes would need to answer each other's question to be right.
|
|
56
73
|
*
|
|
57
74
|
* The scan is written so that it cannot stand still: whatever the branches
|
|
58
75
|
* below decide, the loop advances by at least one character. That guarantee is
|
|
@@ -60,6 +77,8 @@ export type CommentRange = readonly [number, number];
|
|
|
60
77
|
* goes - standing still here would not spin, it would eat memory until the
|
|
61
78
|
* process died, on somebody's file, in somebody's CI.
|
|
62
79
|
*/
|
|
80
|
+
export declare function lexRanges(source: string, syntax: CommentSyntax): LexResult;
|
|
81
|
+
/** The comment ranges alone, for callers that only need to mask them. */
|
|
63
82
|
export declare function commentRanges(source: string, syntax: CommentSyntax): CommentRange[];
|
|
64
83
|
/**
|
|
65
84
|
* Decides whether a byte offset falls inside a comment.
|
package/dist/comments.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../src/comments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,0CAA0C;IAC1C,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,uCAAuC;IACvC,MAAM,EAAE,OAAO,CAAC;IAChB,2DAA2D;IAC3D,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;CAChC;AAuHD,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAEhE;AAED,4DAA4D;AAC5D,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"comments.d.ts","sourceRoot":"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B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC;AAQD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,WAAW,CAqB/E"}
|
package/dist/comments.js
CHANGED
|
@@ -127,6 +127,17 @@ const BY_EXTENSION = new Map([
|
|
|
127
127
|
export function syntaxFor(filePath) {
|
|
128
128
|
return BY_EXTENSION.get(path.extname(filePath).toLowerCase()) ?? null;
|
|
129
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* The same profiles, addressed by name instead of by extension.
|
|
132
|
+
*
|
|
133
|
+
* For callers that already know what language they are looking at and must not
|
|
134
|
+
* re-derive it from the path. Two ways of answering "which language is this"
|
|
135
|
+
* is one more than the number that can be right.
|
|
136
|
+
*/
|
|
137
|
+
const BY_NAME = new Map([...BY_EXTENSION.values()].map((syntax) => [syntax.name, syntax]));
|
|
138
|
+
export function syntaxNamed(name) {
|
|
139
|
+
return BY_NAME.get(name) ?? null;
|
|
140
|
+
}
|
|
130
141
|
/** Where the literal opened at `at` ends, or the end of the file. */
|
|
131
142
|
function endOfString(source, at, rule) {
|
|
132
143
|
let index = at + rule.open.length;
|
|
@@ -136,10 +147,10 @@ function endOfString(source, at, rule) {
|
|
|
136
147
|
continue;
|
|
137
148
|
}
|
|
138
149
|
if (source.startsWith(rule.close, index))
|
|
139
|
-
return index + rule.close.length;
|
|
150
|
+
return { end: index + rule.close.length, closed: true };
|
|
140
151
|
index += 1;
|
|
141
152
|
}
|
|
142
|
-
return source.length;
|
|
153
|
+
return { end: source.length, closed: false };
|
|
143
154
|
}
|
|
144
155
|
/** Where the block comment opened at `at` ends, or the end of the file. */
|
|
145
156
|
function endOfBlock(source, at, pair, nested) {
|
|
@@ -159,14 +170,14 @@ function endOfBlock(source, at, pair, nested) {
|
|
|
159
170
|
}
|
|
160
171
|
index += 1;
|
|
161
172
|
}
|
|
162
|
-
return index;
|
|
173
|
+
return { end: index, closed: depth === 0 };
|
|
163
174
|
}
|
|
164
175
|
/**
|
|
165
|
-
* Finds every comment in the source.
|
|
176
|
+
* Finds every comment and string literal in the source.
|
|
166
177
|
*
|
|
167
|
-
* One pass,
|
|
168
|
-
*
|
|
169
|
-
*
|
|
178
|
+
* One pass, because the two questions are the same question: a comment marker
|
|
179
|
+
* inside a literal is not a comment, and a quote inside a comment does not open
|
|
180
|
+
* one. Two passes would need to answer each other's question to be right.
|
|
170
181
|
*
|
|
171
182
|
* The scan is written so that it cannot stand still: whatever the branches
|
|
172
183
|
* below decide, the loop advances by at least one character. That guarantee is
|
|
@@ -174,8 +185,10 @@ function endOfBlock(source, at, pair, nested) {
|
|
|
174
185
|
* goes - standing still here would not spin, it would eat memory until the
|
|
175
186
|
* process died, on somebody's file, in somebody's CI.
|
|
176
187
|
*/
|
|
177
|
-
export function
|
|
178
|
-
const
|
|
188
|
+
export function lexRanges(source, syntax) {
|
|
189
|
+
const comments = [];
|
|
190
|
+
const strings = [];
|
|
191
|
+
let unterminated = false;
|
|
179
192
|
let index = 0;
|
|
180
193
|
while (index < source.length) {
|
|
181
194
|
const start = index;
|
|
@@ -185,20 +198,29 @@ export function commentRanges(source, syntax) {
|
|
|
185
198
|
// sits in the branch that needs it, so none of them runs speculatively.
|
|
186
199
|
const stringRule = syntax.strings.find((rule) => startsWith(rule.open));
|
|
187
200
|
if (stringRule) {
|
|
188
|
-
|
|
201
|
+
const span = endOfString(source, start, stringRule);
|
|
202
|
+
index = span.end;
|
|
203
|
+
strings.push([start, index]);
|
|
204
|
+
if (!span.closed)
|
|
205
|
+
unterminated = true;
|
|
189
206
|
}
|
|
190
207
|
else {
|
|
191
208
|
const lineToken = syntax.line.find((token) => startsWith(token));
|
|
192
209
|
if (lineToken !== undefined) {
|
|
210
|
+
// A line comment is closed by the end of the file as legitimately as by
|
|
211
|
+
// a newline, so running off the end is not a lost scan.
|
|
193
212
|
const newline = source.indexOf('\n', start);
|
|
194
213
|
index = newline === -1 ? source.length : newline;
|
|
195
|
-
|
|
214
|
+
comments.push([start, index]);
|
|
196
215
|
}
|
|
197
216
|
else {
|
|
198
217
|
const blockPair = syntax.block.find(([open]) => startsWith(open));
|
|
199
218
|
if (blockPair) {
|
|
200
|
-
|
|
201
|
-
|
|
219
|
+
const span = endOfBlock(source, start, blockPair, syntax.nested);
|
|
220
|
+
index = span.end;
|
|
221
|
+
comments.push([start, index]);
|
|
222
|
+
if (!span.closed)
|
|
223
|
+
unterminated = true;
|
|
202
224
|
}
|
|
203
225
|
}
|
|
204
226
|
}
|
|
@@ -206,7 +228,11 @@ export function commentRanges(source, syntax) {
|
|
|
206
228
|
if (index <= start)
|
|
207
229
|
index = start + 1;
|
|
208
230
|
}
|
|
209
|
-
return
|
|
231
|
+
return { comments, strings, unterminated };
|
|
232
|
+
}
|
|
233
|
+
/** The comment ranges alone, for callers that only need to mask them. */
|
|
234
|
+
export function commentRanges(source, syntax) {
|
|
235
|
+
return lexRanges(source, syntax).comments;
|
|
210
236
|
}
|
|
211
237
|
const UNCLASSIFIED = {
|
|
212
238
|
classified: false,
|
package/dist/comments.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments.js","sourceRoot":"","sources":["../src/comments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAqB7B,MAAM,MAAM,GAA0B;IACpC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IACvC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;CACxC,CAAC;AAEF,MAAM,MAAM,GAAkB;IAC5B,IAAI,EAAE,QAAQ;IACd,IAAI,EA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AI,GAAG;oBAAE,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;;oBACjC,OAAO,IAAI,CAAC;YACnB,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Search engines.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* There is one set of semantics here, not two. The scanner reads files, counts
|
|
5
|
+
* matches, classifies comments, decides what is binary and keeps the ledger of
|
|
6
|
+
* what it could not inspect. ripgrep answers one question - which files under
|
|
7
|
+
* these targets contain this text at all - and everything downstream of that is
|
|
8
|
+
* the scanner's work, for both engines.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* It was not always so, and the reason for the rewrite is worth keeping: the
|
|
11
|
+
* two used to be independent implementations, and they drifted. On a tree with
|
|
12
|
+
* eight copies of one symbol the scanner found two and ripgrep found four,
|
|
13
|
+
* because one honoured .gitignore and the other did not, one skipped a
|
|
14
|
+
* hardcoded list of directory names and the other did not, and they disagreed
|
|
15
|
+
* about binary files. Nothing in the output said so. See ADR-0007.
|
|
11
16
|
*
|
|
12
17
|
* Both engines expose a batch API. Scanning a tree costs the same whether you
|
|
13
18
|
* look for one symbol or twenty, so assertions that share a target set and
|
|
14
|
-
* flags are answered by a single pass.
|
|
15
|
-
* eight assertions cost ~280ms as eight ripgrep passes and ~90ms as one.
|
|
19
|
+
* flags are answered by a single pass.
|
|
16
20
|
*/
|
|
17
21
|
import { type CommentMask } from './comments.js';
|
|
22
|
+
import { type SkippedPath } from './scope.js';
|
|
18
23
|
import type { EngineName, MatchLocation, SearchOptions, SearchResult } from './types.js';
|
|
19
24
|
/** Files larger than this are skipped by both engines, keeping them in sync. */
|
|
20
25
|
export declare const MAX_FILE_SIZE: number;
|
|
@@ -38,16 +43,6 @@ export interface Engine {
|
|
|
38
43
|
}
|
|
39
44
|
export type EnginePreference = 'auto' | 'ripgrep' | 'javascript';
|
|
40
45
|
export declare function escapeRegExp(value: string): string;
|
|
41
|
-
/**
|
|
42
|
-
* Converts ripgrep's byte column into a character column.
|
|
43
|
-
*
|
|
44
|
-
* ripgrep counts bytes; the scanner counts characters, and so does every editor
|
|
45
|
-
* that a reader will paste the location into. On an ASCII line the two agree,
|
|
46
|
-
* which is why the difference went unnoticed - it only appears once a line
|
|
47
|
-
* holds a non-ASCII character before the match, and then the two engines report
|
|
48
|
-
* different columns for the same match.
|
|
49
|
-
*/
|
|
50
|
-
export declare function byteColumnToCharacter(line: string, byteOffset: number): number;
|
|
51
46
|
/**
|
|
52
47
|
* Orders matches by path, then by line. ripgrep searches in parallel and emits
|
|
53
48
|
* files in no fixed order, so this is what makes snippet output stable.
|
|
@@ -60,47 +55,44 @@ interface Tally {
|
|
|
60
55
|
/** Matches skipped because they were inside a comment. */
|
|
61
56
|
commentCount: number;
|
|
62
57
|
}
|
|
63
|
-
/**
|
|
64
|
-
* True when no two of these literals can ever match overlapping text, which is
|
|
65
|
-
* exactly when merging them into one ripgrep alternation is safe.
|
|
66
|
-
*
|
|
67
|
-
* Two ways an alternation loses a match that separate passes would find:
|
|
68
|
-
* containment - ["Primary", "PrimaryButton"] on "PrimaryButton"; and
|
|
69
|
-
* dovetailing - ["abc", "cd"] on "abcd", where the scan resumes past "cd".
|
|
70
|
-
* Rejecting both leaves batching indistinguishable from separate passes.
|
|
71
|
-
*/
|
|
72
|
-
export declare function canBatchLiterals(patterns: readonly string[]): boolean;
|
|
73
58
|
/** Runs requests through the batch API when the engine has one. */
|
|
74
59
|
export declare function runSearches(engine: Engine, requests: SearchRequest[]): Promise<SearchResult[]>;
|
|
75
60
|
export declare function resetRipgrepProbe(): void;
|
|
76
61
|
/** Locates a usable `rg` binary. `SPEC_GUARD_RG` overrides PATH lookup. */
|
|
77
62
|
export declare function findRipgrep(): Promise<string | null>;
|
|
78
|
-
/** Builds the argv for one ripgrep pass over `patterns`. */
|
|
79
|
-
export declare function buildRipgrepArgs(request: SearchRequest, patterns?: readonly string[]): string[];
|
|
80
63
|
/**
|
|
81
|
-
*
|
|
64
|
+
* Builds the argv that makes ripgrep walk exactly what the scanner walks.
|
|
65
|
+
*
|
|
66
|
+
* Almost every flag here switches off an opinion. ripgrep's defaults are
|
|
67
|
+
* excellent for a developer grepping their own checkout and wrong for a rule
|
|
68
|
+
* about a repository:
|
|
82
69
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
70
|
+
* --hidden `.github`, `.husky` and `.claude-rules` hold real code, and
|
|
71
|
+
* leaving them out let an absence assertion pass while the
|
|
72
|
+
* forbidden thing sat in a workflow file.
|
|
73
|
+
* --no-ignore .gitignore says what git should carry, not what a rule
|
|
74
|
+
* covers - and it applies only inside a git repository, so the
|
|
75
|
+
* same tree answered differently depending on whether a .git
|
|
76
|
+
* directory happened to exist above it.
|
|
77
|
+
*
|
|
78
|
+
* What remains is spec-guard's own scope policy, passed as exclusions so that
|
|
79
|
+
* both engines skip the same four names for the same reasons. Those come last
|
|
80
|
+
* because ripgrep lets a later glob override an earlier one, and a policy skip
|
|
81
|
+
* must not be undone by a user's `glob="*.ts"`.
|
|
87
82
|
*/
|
|
88
|
-
export declare function
|
|
89
|
-
export interface RipgrepSink {
|
|
90
|
-
/** Feeds one line of ripgrep --json output. */
|
|
91
|
-
line(text: string): void;
|
|
92
|
-
readonly tallies: Map<string, Tally>;
|
|
93
|
-
readonly failure: Error | null;
|
|
94
|
-
}
|
|
83
|
+
export declare function buildRipgrepArgs(request: SearchRequest, patterns?: readonly string[]): string[];
|
|
95
84
|
/**
|
|
96
|
-
*
|
|
85
|
+
* Pulls the paths out of ripgrep's stderr.
|
|
86
|
+
*
|
|
87
|
+
* `--no-messages` used to be passed, which threw these away: a file ripgrep
|
|
88
|
+
* could not open produced no match, no error and no difference from a file that
|
|
89
|
+
* was searched and found clean. ripgrep writes one line per failure, as
|
|
90
|
+
* `path: reason`, and the path is what the report needs.
|
|
97
91
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* unattributable match - is trivial to exercise as data and nearly impossible
|
|
101
|
-
* to provoke from a real ripgrep on demand.
|
|
92
|
+
* Anything that does not parse is returned as-is rather than dropped, on the
|
|
93
|
+
* principle that an unexplained line from a subprocess is still information.
|
|
102
94
|
*/
|
|
103
|
-
export declare function
|
|
95
|
+
export declare function parseRipgrepErrors(stderr: string): string[];
|
|
104
96
|
/** Builds the matching RegExp shared by the JS engine. */
|
|
105
97
|
export declare function buildJsRegExp(symbol: string, options: SearchOptions): RegExp;
|
|
106
98
|
interface CandidateFile {
|
|
@@ -112,11 +104,22 @@ export interface Enumeration {
|
|
|
112
104
|
/** True when the walk stopped early because the budget was reached. */
|
|
113
105
|
exceeded: boolean;
|
|
114
106
|
bytes: number;
|
|
107
|
+
/** Paths the walk declined to inspect, with the reason for each. */
|
|
108
|
+
skipped: SkippedPath[];
|
|
115
109
|
}
|
|
116
110
|
export interface EnumerationBudget {
|
|
117
111
|
maxFiles: number;
|
|
118
112
|
maxBytes: number;
|
|
119
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* A budget that abandons the walk at the first file it finds.
|
|
116
|
+
*
|
|
117
|
+
* Used to answer one question - "is there anything here at all?" - without
|
|
118
|
+
* walking a tree to count files nobody asked about. The answer is the same
|
|
119
|
+
* whichever engine will do the searching, which is the point: an assertion that
|
|
120
|
+
* covers nothing has to be recognised identically by both.
|
|
121
|
+
*/
|
|
122
|
+
export declare const ANY_FILE_PROBE: EnumerationBudget;
|
|
120
123
|
/**
|
|
121
124
|
* Lists the files a request would search, sorted by relative path.
|
|
122
125
|
*
|
|
@@ -138,7 +141,7 @@ getMask?: () => CommentMask): Tally;
|
|
|
138
141
|
/** An engine that is guaranteed to implement the batch API. */
|
|
139
142
|
export type BatchEngine = Engine & Required<Pick<Engine, 'searchBatch'>> & {
|
|
140
143
|
/** Scans a file list that the caller already enumerated. */
|
|
141
|
-
searchFiles(files: readonly CandidateFile[], requests: SearchRequest[]): Promise<SearchResult[]>;
|
|
144
|
+
searchFiles(files: readonly CandidateFile[], requests: SearchRequest[], unreadable?: readonly string[], skipped?: readonly SkippedPath[]): Promise<SearchResult[]>;
|
|
142
145
|
};
|
|
143
146
|
export declare const javascriptEngine: BatchEngine;
|
|
144
147
|
/**
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEzF,gFAAgF;AAChF,eAAO,MAAM,aAAa,QAAmB,CAAC;AAQ9C,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,iEAAiE;IACjE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACtD;;;OAGG;IACH,WAAW,CAAC,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;CAClE;AAED,MAAM,MA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