@noego/trust 0.3.0 → 0.5.0-dev.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/README.md +954 -30
- package/dist/baseline-B0AplCuF.d.ts +362 -0
- package/dist/chunk-NG4KYWVW.js +6154 -0
- package/dist/chunk-NG4KYWVW.js.map +1 -0
- package/dist/chunk-OSSITT3R.js +156 -0
- package/dist/chunk-OSSITT3R.js.map +1 -0
- package/dist/chunk-V72KWVWP.js +2820 -0
- package/dist/chunk-V72KWVWP.js.map +1 -0
- package/dist/cli/index.js +1141 -64
- package/dist/cli/index.js.map +1 -1
- package/dist/core/index.d.ts +127 -0
- package/dist/core/index.js +115 -0
- package/dist/core/index.js.map +1 -0
- package/dist/eslint/index.d.ts +74 -168
- package/dist/eslint/index.js +320 -32
- package/dist/eslint/index.js.map +1 -1
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -15
- package/dist/index.d.ts +42 -15
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/dist/chunk-APNT6ZSM.js +0 -2168
- package/dist/chunk-APNT6ZSM.js.map +0 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compareFindings,
|
|
3
|
+
createPrograms,
|
|
4
|
+
forEachSourceFile,
|
|
5
|
+
formatFinding,
|
|
6
|
+
formatWalkFailure,
|
|
7
|
+
groupByTsconfig,
|
|
8
|
+
readTsconfig,
|
|
9
|
+
relativeTo,
|
|
10
|
+
resolveFiles,
|
|
11
|
+
sourceFileOf
|
|
12
|
+
} from "../chunk-OSSITT3R.js";
|
|
13
|
+
import {
|
|
14
|
+
WHOLE_BASELINE,
|
|
15
|
+
Zones,
|
|
16
|
+
compareToBaseline,
|
|
17
|
+
countFindings,
|
|
18
|
+
describeBaselineDelta,
|
|
19
|
+
directiveDirectlyAbove,
|
|
20
|
+
directiveReason,
|
|
21
|
+
groupMatches,
|
|
22
|
+
isNamedDirective,
|
|
23
|
+
lineDirectivesIn,
|
|
24
|
+
loadTypeScript,
|
|
25
|
+
matchesPatterns,
|
|
26
|
+
nearestPackageName,
|
|
27
|
+
nodeBelow,
|
|
28
|
+
normalizePattern,
|
|
29
|
+
parseBaseline,
|
|
30
|
+
readBaseline,
|
|
31
|
+
readZoneSettings,
|
|
32
|
+
realpathOrSelf,
|
|
33
|
+
relativeInside,
|
|
34
|
+
serializeBaseline,
|
|
35
|
+
toPosix,
|
|
36
|
+
updateBaseline
|
|
37
|
+
} from "../chunk-NG4KYWVW.js";
|
|
38
|
+
|
|
39
|
+
// src/core/tool-config.ts
|
|
40
|
+
import { existsSync, readFileSync } from "fs";
|
|
41
|
+
import { dirname, resolve } from "path";
|
|
42
|
+
var SHARED_KEYS = ["$comment", "ignore", "tsconfig"];
|
|
43
|
+
function emptyToolConfig(rootDir) {
|
|
44
|
+
return { file: void 0, rootDir: realpathOrSelf(resolve(rootDir)), ignore: [], tsconfig: [], settings: {} };
|
|
45
|
+
}
|
|
46
|
+
var ToolConfigProblem = class extends Error {
|
|
47
|
+
};
|
|
48
|
+
function isRecord(value) {
|
|
49
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
50
|
+
}
|
|
51
|
+
function loadToolConfig(configFile, options) {
|
|
52
|
+
const file = resolve(configFile);
|
|
53
|
+
const failWith = (source, message) => {
|
|
54
|
+
throw new ToolConfigProblem(`${options.tool} config ${source}: ${message}`);
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
if (!existsSync(file)) return { kind: "failed", message: `${options.tool} config not found: ${file}` };
|
|
58
|
+
let raw;
|
|
59
|
+
try {
|
|
60
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return failWith(file, `invalid JSON (${error instanceof Error ? error.message : String(error)})`);
|
|
63
|
+
}
|
|
64
|
+
if (!isRecord(raw)) return failWith(file, "expected an object");
|
|
65
|
+
const record = raw;
|
|
66
|
+
const allowed = /* @__PURE__ */ new Set([...SHARED_KEYS, ...options.keys]);
|
|
67
|
+
for (const key of Object.keys(record)) {
|
|
68
|
+
if (!allowed.has(key)) failWith(file, `unknown key "${key}" (known: ${[...allowed].map((name) => `"${name}"`).join(", ")})`);
|
|
69
|
+
}
|
|
70
|
+
const rootDir = realpathOrSelf(options.rootDir === void 0 ? dirname(file) : resolve(options.rootDir));
|
|
71
|
+
const zones = readZoneSettings(file, record, rootDir, options.validateGlobs ?? false, failWith);
|
|
72
|
+
const settings = Object.fromEntries(options.keys.filter((key) => key in record).map((key) => [key, record[key]]));
|
|
73
|
+
return { kind: "loaded", config: { file, rootDir, ignore: zones.ignore, tsconfig: zones.tsconfig, settings } };
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error instanceof ToolConfigProblem) return { kind: "failed", message: error.message };
|
|
76
|
+
return { kind: "failed", message: `${options.tool} config ${file}: ${error instanceof Error ? error.message : String(error)}` };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
WHOLE_BASELINE,
|
|
81
|
+
Zones,
|
|
82
|
+
compareFindings,
|
|
83
|
+
compareToBaseline,
|
|
84
|
+
countFindings,
|
|
85
|
+
createPrograms,
|
|
86
|
+
describeBaselineDelta,
|
|
87
|
+
directiveDirectlyAbove,
|
|
88
|
+
directiveReason,
|
|
89
|
+
emptyToolConfig,
|
|
90
|
+
forEachSourceFile,
|
|
91
|
+
formatFinding,
|
|
92
|
+
formatWalkFailure,
|
|
93
|
+
groupByTsconfig,
|
|
94
|
+
groupMatches,
|
|
95
|
+
isNamedDirective,
|
|
96
|
+
lineDirectivesIn,
|
|
97
|
+
loadToolConfig,
|
|
98
|
+
loadTypeScript,
|
|
99
|
+
matchesPatterns,
|
|
100
|
+
nearestPackageName,
|
|
101
|
+
nodeBelow,
|
|
102
|
+
normalizePattern,
|
|
103
|
+
parseBaseline,
|
|
104
|
+
readBaseline,
|
|
105
|
+
readTsconfig,
|
|
106
|
+
realpathOrSelf,
|
|
107
|
+
relativeInside,
|
|
108
|
+
relativeTo,
|
|
109
|
+
resolveFiles,
|
|
110
|
+
serializeBaseline,
|
|
111
|
+
sourceFileOf,
|
|
112
|
+
toPosix,
|
|
113
|
+
updateBaseline
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/tool-config.ts"],"sourcesContent":["// The config file of a sibling checker built on `@noego/trust/core` (`ioc-check.config.json`): one JSON\n// object, no `extend` chain, with trust's own `ignore` and `tsconfig` keys read exactly as trust reads\n// them (eslint/config.ts readZoneSettings: same glob semantics, paths relative to the config file's\n// directory or to `rootDir`) plus whatever keys the tool declares, handed back unread for the tool to\n// validate. Problems come back as a value naming the tool's config, never as a throw.\nimport { existsSync, readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { readZoneSettings, type ConfigFail, type TsconfigMapping } from '../eslint/config.js';\nimport { realpathOrSelf, type ZoneGroup } from '../eslint/zones.js';\n\nexport interface ToolConfig {\n /** Absolute path of the config file, or undefined when the tool runs without one. */\n readonly file: string | undefined;\n /** Realpath of the directory globs, `tsconfig` paths and baseline keys resolve against. */\n readonly rootDir: string;\n readonly ignore: readonly ZoneGroup[];\n readonly tsconfig: readonly TsconfigMapping[];\n /** The tool's own keys as written (only the ones declared in `keys`). */\n readonly settings: Readonly<Record<string, unknown>>;\n}\n\nexport interface LoadToolConfigOptions {\n /** Names the config in messages: `ioc check config /path/x.json: …`. */\n readonly tool: string;\n /** The tool's own top-level keys besides `$comment`, `ignore` and `tsconfig`; any other key is an error. */\n readonly keys: readonly string[];\n /** Directory paths resolve against, instead of the config file's own directory. */\n readonly rootDir?: string;\n /** Check that every glob matches at least one file (default false, as `trust check`). */\n readonly validateGlobs?: boolean;\n}\n\nexport type ToolConfigLoad = { readonly kind: 'loaded'; readonly config: ToolConfig } | { readonly kind: 'failed'; readonly message: string };\n\nconst SHARED_KEYS = ['$comment', 'ignore', 'tsconfig'];\n\n/** A config with nothing set, rooted at `rootDir` (a tool run without a config file). */\nexport function emptyToolConfig(rootDir: string): ToolConfig {\n return { file: undefined, rootDir: realpathOrSelf(resolve(rootDir)), ignore: [], tsconfig: [], settings: {} };\n}\n\nclass ToolConfigProblem extends Error {}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** Loads and validates `configFile`; a missing or invalid file is a `failed` result naming the tool's config. */\nexport function loadToolConfig(configFile: string, options: LoadToolConfigOptions): ToolConfigLoad {\n const file = resolve(configFile);\n const failWith: ConfigFail = (source, message) => {\n throw new ToolConfigProblem(`${options.tool} config ${source}: ${message}`);\n };\n try {\n if (!existsSync(file)) return { kind: 'failed', message: `${options.tool} config not found: ${file}` };\n let raw: unknown;\n try {\n raw = JSON.parse(readFileSync(file, 'utf8'));\n } catch (error) {\n return failWith(file, `invalid JSON (${error instanceof Error ? error.message : String(error)})`);\n }\n if (!isRecord(raw)) return failWith(file, 'expected an object');\n const record = raw;\n const allowed = new Set([...SHARED_KEYS, ...options.keys]);\n for (const key of Object.keys(record)) {\n if (!allowed.has(key)) failWith(file, `unknown key \"${key}\" (known: ${[...allowed].map((name) => `\"${name}\"`).join(', ')})`);\n }\n const rootDir = realpathOrSelf(options.rootDir === undefined ? dirname(file) : resolve(options.rootDir));\n const zones = readZoneSettings(file, record, rootDir, options.validateGlobs ?? false, failWith);\n const settings = Object.fromEntries(options.keys.filter((key) => key in record).map((key) => [key, record[key]]));\n return { kind: 'loaded', config: { file, rootDir, ignore: zones.ignore, tsconfig: zones.tsconfig, settings } };\n } catch (error) {\n if (error instanceof ToolConfigProblem) return { kind: 'failed', message: error.message };\n return { kind: 'failed', message: `${options.tool} config ${file}: ${error instanceof Error ? error.message : String(error)}` };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,SAAS,YAAY,oBAAoB;AACzC,SAAS,SAAS,eAAe;AA4BjC,IAAM,cAAc,CAAC,YAAY,UAAU,UAAU;AAG9C,SAAS,gBAAgB,SAA6B;AAC3D,SAAO,EAAE,MAAM,QAAW,SAAS,eAAe,QAAQ,OAAO,CAAC,GAAG,QAAQ,CAAC,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC,EAAE;AAC9G;AAEA,IAAM,oBAAN,cAAgC,MAAM;AAAC;AAEvC,SAAS,SAAS,OAAkD;AAClE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAGO,SAAS,eAAe,YAAoB,SAAgD;AACjG,QAAM,OAAO,QAAQ,UAAU;AAC/B,QAAM,WAAuB,CAAC,QAAQ,YAAY;AAChD,UAAM,IAAI,kBAAkB,GAAG,QAAQ,IAAI,WAAW,MAAM,KAAK,OAAO,EAAE;AAAA,EAC5E;AACA,MAAI;AACF,QAAI,CAAC,WAAW,IAAI,EAAG,QAAO,EAAE,MAAM,UAAU,SAAS,GAAG,QAAQ,IAAI,sBAAsB,IAAI,GAAG;AACrG,QAAI;AACJ,QAAI;AACF,YAAM,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC;AAAA,IAC7C,SAAS,OAAO;AACd,aAAO,SAAS,MAAM,iBAAiB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,GAAG;AAAA,IAClG;AACA,QAAI,CAAC,SAAS,GAAG,EAAG,QAAO,SAAS,MAAM,oBAAoB;AAC9D,UAAM,SAAS;AACf,UAAM,UAAU,oBAAI,IAAI,CAAC,GAAG,aAAa,GAAG,QAAQ,IAAI,CAAC;AACzD,eAAW,OAAO,OAAO,KAAK,MAAM,GAAG;AACrC,UAAI,CAAC,QAAQ,IAAI,GAAG,EAAG,UAAS,MAAM,gBAAgB,GAAG,aAAa,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG;AAAA,IAC7H;AACA,UAAM,UAAU,eAAe,QAAQ,YAAY,SAAY,QAAQ,IAAI,IAAI,QAAQ,QAAQ,OAAO,CAAC;AACvG,UAAM,QAAQ,iBAAiB,MAAM,QAAQ,SAAS,QAAQ,iBAAiB,OAAO,QAAQ;AAC9F,UAAM,WAAW,OAAO,YAAY,QAAQ,KAAK,OAAO,CAAC,QAAQ,OAAO,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,OAAO,GAAG,CAAC,CAAC,CAAC;AAChH,WAAO,EAAE,MAAM,UAAU,QAAQ,EAAE,MAAM,SAAS,QAAQ,MAAM,QAAQ,UAAU,MAAM,UAAU,SAAS,EAAE;AAAA,EAC/G,SAAS,OAAO;AACd,QAAI,iBAAiB,kBAAmB,QAAO,EAAE,MAAM,UAAU,SAAS,MAAM,QAAQ;AACxF,WAAO,EAAE,MAAM,UAAU,SAAS,GAAG,QAAQ,IAAI,WAAW,IAAI,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,GAAG;AAAA,EAChI;AACF;","names":[]}
|
package/dist/eslint/index.d.ts
CHANGED
|
@@ -1,103 +1,20 @@
|
|
|
1
1
|
import * as eslint from 'eslint';
|
|
2
|
-
import {
|
|
2
|
+
import { Linter, ESLint } from 'eslint';
|
|
3
|
+
import { g as Zones, O as OriginResolver, C as TrustRuleSettings, T as TypeScript, D as TrustConfig, E as OriginInfo, G as CatchProblem } from '../baseline-B0AplCuF.js';
|
|
4
|
+
export { H as ACCEPT_DIRECTIVE, I as ACCEPT_DIRECTIVE_MESSAGES, B as BaselineCounts, b as BaselineDelta, d as BaselineScope, J as CATCH_ORIGIN, K as DEFAULT_RULE_SETTINGS, L as DIRECTIVE_ORIGIN, M as DROPPED_RESULT_MESSAGES, N as DROPPED_RESULT_RULE, P as DroppedResultOrigin, F as Finding, Q as LoadTrustConfigOptions, R as OptInRule, S as REDUNDANT_GUARD_MESSAGES, U as REDUNDANT_GUARD_ORIGIN, V as REDUNDANT_GUARD_RULE, X as RuleSwitch, Y as THROW_MESSAGES, _ as THROW_RULE, $ as TYPE_CLAIM_KINDS, a0 as TYPE_CLAIM_MESSAGES, a1 as TYPE_CLAIM_RULE, a2 as TrustConfigError, a3 as TrustEntry, a4 as TrustLevel, a as TsconfigMapping, a5 as TypeClaimOrigin, a6 as UNANALYZABLE_ORIGIN, a7 as UNTRUSTED_CALL_MESSAGES, a8 as UNTRUSTED_CALL_RULE, a9 as UNTRUSTED_VALUE_MESSAGES, aa as UNTRUSTED_VALUE_RULE, ab as UntrustedCallbacks, ac as UntrustedEntry, ad as VALIDATOR_DIRECTIVE, W as WHOLE_BASELINE, f as Zone, Z as ZoneGroup, h as compareToBaseline, i as countFindings, ae as effectiveTrustList, af as effectiveTypeTrustList, ag as isInsideValidator, ah as isMarkedValidator, ai as isRuleEnabled, aj as loadTrustConfig, ak as normalizeOrigin, u as parseBaseline, y as serializeBaseline, A as updateBaseline } from '../baseline-B0AplCuF.js';
|
|
3
5
|
import * as TS from 'typescript';
|
|
4
6
|
|
|
5
|
-
type Zone = 'checked' | 'passthrough' | 'ignore' | 'external';
|
|
6
|
-
interface ZoneGroup {
|
|
7
|
-
/** Config file that declared the patterns (for error messages). */
|
|
8
|
-
readonly source: string;
|
|
9
|
-
/** Realpath of the directory the patterns are relative to. */
|
|
10
|
-
readonly baseDir: string;
|
|
11
|
-
readonly patterns: readonly string[];
|
|
12
|
-
}
|
|
13
|
-
declare class Zones {
|
|
14
|
-
/** Realpath of the project root (directory of the leaf trust config). */
|
|
15
|
-
readonly rootDir: string;
|
|
16
|
-
private readonly passthrough;
|
|
17
|
-
private readonly ignore;
|
|
18
|
-
private readonly cache;
|
|
19
|
-
constructor(
|
|
20
|
-
/** Realpath of the project root (directory of the leaf trust config). */
|
|
21
|
-
rootDir: string, passthrough: readonly ZoneGroup[], ignore: readonly ZoneGroup[]);
|
|
22
|
-
/** Zone of a file. Ignore wins over passthrough; files outside the root or in node_modules are external. */
|
|
23
|
-
zoneOf(fileName: string): Zone;
|
|
24
|
-
/** Project-relative posix path (for `local:` origins and baselines), or the absolute path when outside. */
|
|
25
|
-
relativePath(fileName: string): string;
|
|
26
|
-
private compute;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
type TrustEntry = string | {
|
|
30
|
-
readonly origin: string;
|
|
31
|
-
readonly reason?: string;
|
|
32
|
-
};
|
|
33
|
-
interface TrustLevel {
|
|
34
|
-
/** Config file path or `preset:<name>`. */
|
|
35
|
-
readonly source: string;
|
|
36
|
-
readonly trust: readonly string[];
|
|
37
|
-
readonly distrust: readonly string[];
|
|
38
|
-
}
|
|
39
|
-
interface TrustConfig {
|
|
40
|
-
/** Absolute path of the leaf config file. */
|
|
41
|
-
readonly file: string;
|
|
42
|
-
/** Realpath of the leaf config file's directory: the project root for zones and `local:` origins. */
|
|
43
|
-
readonly rootDir: string;
|
|
44
|
-
/** Leaf first, root preset last. */
|
|
45
|
-
readonly levels: readonly TrustLevel[];
|
|
46
|
-
readonly passthrough: readonly ZoneGroup[];
|
|
47
|
-
readonly ignore: readonly ZoneGroup[];
|
|
48
|
-
}
|
|
49
|
-
interface LoadTrustConfigOptions {
|
|
50
|
-
/** Check that every glob matches at least one file (default true). */
|
|
51
|
-
readonly validateGlobs?: boolean;
|
|
52
|
-
}
|
|
53
|
-
declare class TrustConfigError extends Error {
|
|
54
|
-
readonly name = "TrustConfigError";
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Trust entries are matched exactly as written. Origin namespaces:
|
|
58
|
-
* js:JSON.parse JavaScript built-ins (TypeScript lib)
|
|
59
|
-
* node:fs.existsSync Node built-in modules (the `node:` import specifier)
|
|
60
|
-
* node:global.process.cwd Node globals
|
|
61
|
-
* zod.object, @scope/pkg.fn npm packages (bare package name)
|
|
62
|
-
*/
|
|
63
|
-
declare function normalizeOrigin(origin: string): string;
|
|
64
|
-
/** Loads and validates a trust config file and its `extend` chain. Throws TrustConfigError. */
|
|
65
|
-
declare function loadTrustConfig(configFile: string, options?: LoadTrustConfigOptions): TrustConfig;
|
|
66
|
-
/** Union of every trust entry in the chain (for tooling and tests). */
|
|
67
|
-
declare function effectiveTrustList(config: TrustConfig): string[];
|
|
68
|
-
|
|
69
7
|
interface PresetDefinition {
|
|
70
8
|
readonly $comment?: string;
|
|
71
|
-
|
|
9
|
+
/** A preset name, or preset names applied left to right (a later one overrides an earlier one). */
|
|
10
|
+
readonly extend?: string | readonly string[];
|
|
72
11
|
readonly trust?: readonly string[];
|
|
73
12
|
readonly distrust?: readonly string[];
|
|
13
|
+
readonly trust_type?: readonly string[];
|
|
14
|
+
readonly distrust_type?: readonly string[];
|
|
74
15
|
}
|
|
75
16
|
declare const PRESETS: Readonly<Record<string, PresetDefinition>>;
|
|
76
17
|
|
|
77
|
-
type TypeScript = typeof TS;
|
|
78
|
-
|
|
79
|
-
type OriginInfo = {
|
|
80
|
-
readonly kind: 'external';
|
|
81
|
-
readonly origin: string;
|
|
82
|
-
readonly base: string;
|
|
83
|
-
readonly fileName: string;
|
|
84
|
-
} | {
|
|
85
|
-
readonly kind: 'local';
|
|
86
|
-
readonly zone: Exclude<Zone, 'external'>;
|
|
87
|
-
readonly origin: string;
|
|
88
|
-
readonly fileName: string;
|
|
89
|
-
};
|
|
90
|
-
declare class OriginResolver {
|
|
91
|
-
private readonly ts;
|
|
92
|
-
private readonly zones;
|
|
93
|
-
constructor(ts: TypeScript, zones: Zones);
|
|
94
|
-
originOf(declaration: TS.Node): OriginInfo;
|
|
95
|
-
/** Named containers from the module down to (and including) the declaration. */
|
|
96
|
-
memberPath(declaration: TS.Node): string[];
|
|
97
|
-
private containerName;
|
|
98
|
-
private ambientModuleName;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
18
|
interface MatchedEntry {
|
|
102
19
|
readonly source: string;
|
|
103
20
|
readonly entry: string;
|
|
@@ -123,8 +40,38 @@ type Verdict = {
|
|
|
123
40
|
readonly origin: OriginInfo;
|
|
124
41
|
};
|
|
125
42
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
43
|
+
* Are the types a declaration states true at runtime? Type trust is separate from throw trust (`Verdict`):
|
|
44
|
+
* it is decided by the `trust_type` / `distrust_type` lists only.
|
|
45
|
+
* first-party declared in a checked file: its types are checked themselves
|
|
46
|
+
* trust-package declared by @noego/trust: Result, Trust and friends are this tool's own contract
|
|
47
|
+
* type-trusted a `trust_type` entry covers the origin
|
|
48
|
+
* type-untrusted nothing does, or a `distrust_type` entry removed it
|
|
49
|
+
*/
|
|
50
|
+
type TypeVerdict = {
|
|
51
|
+
readonly kind: 'first-party';
|
|
52
|
+
readonly origin: OriginInfo;
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: 'trust-package';
|
|
55
|
+
readonly origin: OriginInfo;
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: 'type-trusted';
|
|
58
|
+
readonly origin: OriginInfo;
|
|
59
|
+
readonly by: MatchedEntry;
|
|
60
|
+
} | {
|
|
61
|
+
readonly kind: 'type-untrusted';
|
|
62
|
+
readonly origin: OriginInfo;
|
|
63
|
+
readonly distrustedBy?: MatchedEntry;
|
|
64
|
+
};
|
|
65
|
+
type Decision = {
|
|
66
|
+
trusted: true;
|
|
67
|
+
by: MatchedEntry;
|
|
68
|
+
} | {
|
|
69
|
+
trusted: false;
|
|
70
|
+
distrustedBy?: MatchedEntry;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* `entry` covers `origin` itself, its subpaths (`fs` → `fs/promises`) and members (`js:JSON` →
|
|
74
|
+
* `js:JSON.parse`). When the origin's `base` (package/module part) is known, an entry that stops
|
|
128
75
|
* inside the base may only continue with `/`, so `lodash` does not cover the package `lodash.merge`.
|
|
129
76
|
*/
|
|
130
77
|
declare function entryMatches(entry: string, origin: string, base?: string): boolean;
|
|
@@ -133,20 +80,25 @@ declare class TrustPolicy {
|
|
|
133
80
|
private readonly checker;
|
|
134
81
|
readonly zones: Zones;
|
|
135
82
|
readonly origins: OriginResolver;
|
|
83
|
+
/** The config's per-rule settings (`rules`): which opt-in rules run and which callbacks are sources. */
|
|
84
|
+
readonly rules: TrustRuleSettings;
|
|
136
85
|
private readonly levels;
|
|
137
86
|
constructor(ts: TypeScript, checker: TS.TypeChecker, config: TrustConfig, extraTrust?: readonly string[]);
|
|
87
|
+
/** Throw trust of an origin: the `trust` / `distrust` lists of the chain (see `decide`). */
|
|
88
|
+
lookup(origin: string, base?: string): Decision;
|
|
89
|
+
/** Type trust of an origin: the `trust_type` / `distrust_type` lists of the chain, resolved the same way. */
|
|
90
|
+
lookupType(origin: string, base?: string): Decision;
|
|
138
91
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
92
|
+
* The `trust_type` entry of the project's own config files that type-trusts `declaration` (member or
|
|
93
|
+
* package level), else null. Entries of built-in presets (`preset:<name>` levels: js, node, web,
|
|
94
|
+
* web_strict, svelte) never count, and a `distrust_type` that wins along the chain takes it back. Only
|
|
95
|
+
* this unlocks a caller-chosen generic return (`container.get<Foo>('x')`, type-claims.ts): a broad preset
|
|
96
|
+
* entry such as `js:Array` must not silently bless a cast. Checked code is looked up too, so a user entry
|
|
97
|
+
* naming a first-party origin (`local:ui/scope.ts#resolveSyncInScope`) unlocks its generic returns.
|
|
142
98
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
} | {
|
|
147
|
-
trusted: false;
|
|
148
|
-
distrustedBy?: MatchedEntry;
|
|
149
|
-
};
|
|
99
|
+
userTypeTrustOf(declaration: TS.Node): MatchedEntry | null;
|
|
100
|
+
/** Whether the types `declaration` states are trusted (see TypeVerdict). */
|
|
101
|
+
typeVerdictOf(declaration: TS.Node): TypeVerdict;
|
|
150
102
|
classify(node: TS.CallExpression | TS.NewExpression): Verdict;
|
|
151
103
|
calleeDeclaration(node: TS.CallExpression | TS.NewExpression): {
|
|
152
104
|
declaration: TS.Node;
|
|
@@ -163,13 +115,6 @@ declare class TrustPolicy {
|
|
|
163
115
|
trustFunctionName(node: TS.CallExpression): string | null;
|
|
164
116
|
}
|
|
165
117
|
|
|
166
|
-
/** Minimal ESTree node shape (avoids coupling to a specific @types/estree version). */
|
|
167
|
-
interface AstNode {
|
|
168
|
-
readonly type: string;
|
|
169
|
-
parent?: AstNode;
|
|
170
|
-
readonly [key: string]: unknown;
|
|
171
|
-
}
|
|
172
|
-
type CatchProblem = 'rethrow' | 'notResultErr' | 'rawCatchValue' | 'notAllPaths';
|
|
173
118
|
type Guard = {
|
|
174
119
|
readonly status: 'unguarded';
|
|
175
120
|
} | {
|
|
@@ -180,69 +125,20 @@ type Guard = {
|
|
|
180
125
|
readonly problem: CatchProblem;
|
|
181
126
|
};
|
|
182
127
|
interface GuardContext {
|
|
128
|
+
readonly ts: TypeScript;
|
|
183
129
|
/** The returned expression is an `Err` (typed: by declaration; untyped: `Result.err(...)`/`err(...)` by name). */
|
|
184
|
-
isResultErr(expression:
|
|
130
|
+
isResultErr(expression: TS.Expression): boolean;
|
|
185
131
|
/** The call is `Result.err(...)` / `err(...)` itself (for the raw-caught-value check). */
|
|
186
|
-
isErrCall(
|
|
187
|
-
/** 'sync' for
|
|
188
|
-
trustTryKind(call:
|
|
132
|
+
isErrCall(call: TS.CallExpression): boolean;
|
|
133
|
+
/** 'sync' for Trust.try, 'async' for Trust.tryAsync, else null. */
|
|
134
|
+
trustTryKind(call: TS.CallExpression): 'sync' | 'async' | null;
|
|
189
135
|
}
|
|
190
136
|
/** Every path through `statement` ends in return (or throw). */
|
|
191
|
-
declare function alwaysExits(
|
|
137
|
+
declare function alwaysExits(ts: TypeScript, statement: TS.Statement | undefined): boolean;
|
|
192
138
|
/** Null when the catch clause returns Result.err(...) on every path, else the problem. */
|
|
193
|
-
declare function catchProblem(handler:
|
|
139
|
+
declare function catchProblem(handler: TS.CatchClause, context: GuardContext): CatchProblem | null;
|
|
194
140
|
/** Innermost guard of `node` within its own function. */
|
|
195
|
-
declare function guardOf(node:
|
|
196
|
-
|
|
197
|
-
declare const UNTRUSTED_CALL_RULE = "untrusted-call-must-return-result";
|
|
198
|
-
declare const THROW_RULE = "throw-must-return-result";
|
|
199
|
-
interface Finding {
|
|
200
|
-
readonly file: string;
|
|
201
|
-
readonly rule: string;
|
|
202
|
-
readonly origin: string;
|
|
203
|
-
readonly line: number;
|
|
204
|
-
readonly column: number;
|
|
205
|
-
readonly message: string;
|
|
206
|
-
}
|
|
207
|
-
/** file → rule → origin → count */
|
|
208
|
-
type BaselineCounts = Record<string, Record<string, Record<string, number>>>;
|
|
209
|
-
interface BaselineDelta {
|
|
210
|
-
readonly file: string;
|
|
211
|
-
readonly rule: string;
|
|
212
|
-
readonly origin: string;
|
|
213
|
-
readonly allowed: number;
|
|
214
|
-
readonly found: number;
|
|
215
|
-
readonly findings: readonly Finding[];
|
|
216
|
-
}
|
|
217
|
-
/** The origin a baselined rule message is about ("throw" for the throw rule, messageId for promise rules). */
|
|
218
|
-
declare function originFromMessage(rule: string, messageId: string | undefined, message: string): string;
|
|
219
|
-
/** Trust-rule findings from ESLint results, with paths relative to `rootDir`. */
|
|
220
|
-
declare function findingsFromResults(results: readonly ESLint.LintResult[], rootDir: string): Finding[];
|
|
221
|
-
declare function countFindings(findings: readonly Finding[]): BaselineCounts;
|
|
222
|
-
declare function compareToBaseline(findings: readonly Finding[], baseline: BaselineCounts): {
|
|
223
|
-
readonly added: BaselineDelta[];
|
|
224
|
-
readonly stale: BaselineDelta[];
|
|
225
|
-
};
|
|
226
|
-
declare function serializeBaseline(counts: BaselineCounts): string;
|
|
227
|
-
declare function parseBaseline(text: string, source: string): BaselineCounts;
|
|
228
|
-
|
|
229
|
-
declare const THROW_MESSAGES: {
|
|
230
|
-
readonly escapes: "`throw` must be inside a `try` (same function) whose `catch` returns Result.err(...), or inside Result.try/tryAsync.";
|
|
231
|
-
readonly rethrow: string;
|
|
232
|
-
readonly notResultErr: string;
|
|
233
|
-
readonly rawCatchValue: string;
|
|
234
|
-
readonly notAllPaths: string;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
declare const UNTRUSTED_CALL_MESSAGES: {
|
|
238
|
-
readonly unguarded: "Call into untrusted \"{{origin}}\" must be inside a `try` (same function) whose `catch` returns Result.err(...), or inside Result.try/tryAsync. If \"{{origin}}\" cannot fail, trust it in trust.config.json.";
|
|
239
|
-
readonly notAwaited: "Async call into untrusted \"{{origin}}\" must be awaited inside the guard, or its rejection escapes the catch.";
|
|
240
|
-
readonly callsIgnored: "Call into \"{{origin}}\" is trusted only because its file is ignored. List that file under \"passthrough\" instead of \"ignore\" so calls into it must be handled.";
|
|
241
|
-
readonly rethrow: string;
|
|
242
|
-
readonly notResultErr: string;
|
|
243
|
-
readonly rawCatchValue: string;
|
|
244
|
-
readonly notAllPaths: string;
|
|
245
|
-
};
|
|
141
|
+
declare function guardOf(node: TS.Node, context: GuardContext): Guard;
|
|
246
142
|
|
|
247
143
|
interface TrustRuleOptions {
|
|
248
144
|
/** trust.config.json path, relative to the ESLint cwd. */
|
|
@@ -254,6 +150,10 @@ interface TrustRuleOptions {
|
|
|
254
150
|
declare const rules: {
|
|
255
151
|
'untrusted-call-must-return-result': eslint.Rule.RuleModule;
|
|
256
152
|
'throw-must-return-result': eslint.Rule.RuleModule;
|
|
153
|
+
'type-claim': eslint.Rule.RuleModule;
|
|
154
|
+
'untrusted-value': eslint.Rule.RuleModule;
|
|
155
|
+
'dropped-result': eslint.Rule.RuleModule;
|
|
156
|
+
'redundant-guard': eslint.Rule.RuleModule;
|
|
257
157
|
};
|
|
258
158
|
interface TypedConfigOptions {
|
|
259
159
|
/** Files to check (flat-config globs). They must be in a tsconfig the project service can find. */
|
|
@@ -265,7 +165,13 @@ interface TypedConfigOptions {
|
|
|
265
165
|
}
|
|
266
166
|
declare const plugin: ESLint.Plugin;
|
|
267
167
|
|
|
268
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* Flat config that registers the plugin as `trust` and enables its rules (the two trust rules, `type-claim`,
|
|
170
|
+
* `untrusted-value` and `dropped-result`) for `files`. Needs typed linting. `type-claim`, `untrusted-value` and
|
|
171
|
+
* `dropped-result` are opt-in: they report only when the trust config turns them on
|
|
172
|
+
* (`"rules": { "type-claim": "on", "untrusted-value": "on", "dropped-result": "on" }`), the same settings
|
|
173
|
+
* `trust check` / `trust baseline` honour, so ESLint and the CLI always agree.
|
|
174
|
+
*/
|
|
269
175
|
declare function typedConfig(options: TypedConfigOptions): Linter.Config[];
|
|
270
176
|
|
|
271
|
-
export {
|
|
177
|
+
export { CatchProblem, type Guard, type GuardContext, type MatchedEntry, OriginInfo, OriginResolver, PRESETS, type PresetDefinition, TrustConfig, TrustPolicy, type TrustRuleOptions, TrustRuleSettings, type TypeVerdict, type TypedConfigOptions, type Verdict, Zones, alwaysExits, catchProblem, plugin as default, entryMatches, guardOf, rules, typedConfig };
|