@noego/trust 0.5.0-dev.0 → 0.5.0-dev.1
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 +44 -9
- package/dist/{baseline-B0AplCuF.d.ts → baseline-Bkav9mS0.d.ts} +22 -4
- package/dist/{chunk-V72KWVWP.js → chunk-7PY2Q6OX.js} +212 -16
- package/dist/chunk-7PY2Q6OX.js.map +1 -0
- package/dist/{chunk-NG4KYWVW.js → chunk-UG6D3V4M.js} +877 -41
- package/dist/chunk-UG6D3V4M.js.map +1 -0
- package/dist/{chunk-OSSITT3R.js → chunk-XXLWC5DB.js} +17 -61
- package/dist/chunk-XXLWC5DB.js.map +1 -0
- package/dist/cli/index.js +341 -92
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/wasm-worker.js +257 -0
- package/dist/cli/wasm-worker.js.map +1 -0
- package/dist/core/index.d.ts +5 -3
- package/dist/core/index.js +7 -7
- package/dist/eslint/index.d.ts +6 -2
- package/dist/eslint/index.js +2 -2
- package/dist/licenses/@jridgewell__resolve-uri/LICENSE +19 -0
- package/dist/licenses/@jridgewell__sourcemap-codec/LICENSE +19 -0
- package/dist/licenses/@jridgewell__trace-mapping/LICENSE +19 -0
- package/dist/licenses/JS-DEPENDENCIES.json +83 -0
- package/dist/licenses/balanced-match/LICENSE.md +23 -0
- package/dist/licenses/brace-expansion/LICENSE +23 -0
- package/dist/licenses/dedent-js/LICENSE +19 -0
- package/dist/licenses/minimatch/LICENSE.md +55 -0
- package/dist/licenses/scule/LICENSE +21 -0
- package/dist/licenses/svelte2tsx/LICENSE +21 -0
- package/dist/native/licenses/CARGO-DEPENDENCIES.json +479 -0
- package/dist/native/licenses/LICENSE-trust.txt +15 -0
- package/dist/native/licenses/cargo/adler2-2.0.1/LICENSE-0BSD +12 -0
- package/dist/native/licenses/cargo/adler2-2.0.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/adler2-2.0.1/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/aho-corasick-1.1.5/COPYING +3 -0
- package/dist/native/licenses/cargo/aho-corasick-1.1.5/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/autocfg-1.5.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/autocfg-1.5.1/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/bitflags-1.3.2/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/bitflags-1.3.2/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/bstr-1.13.1/COPYING +8 -0
- package/dist/native/licenses/cargo/bstr-1.13.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/bstr-1.13.1/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/bumpalo-3.20.3/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/bumpalo-3.20.3/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/cfg-if-1.0.5/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/cfg-if-1.0.5/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/crc32fast-1.5.2/LICENSE-APACHE +202 -0
- package/dist/native/licenses/cargo/crc32fast-1.5.2/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/defmt-1.1.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/defmt-1.1.1/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/defmt-macros-1.1.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/defmt-macros-1.1.1/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/equivalent-1.0.2/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/equivalent-1.0.2/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/flate2-1.1.10/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/flate2-1.1.10/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/globset-0.4.20/COPYING +3 -0
- package/dist/native/licenses/cargo/globset-0.4.20/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/hashbrown-0.17.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/hashbrown-0.17.1/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/indexmap-2.14.0/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/indexmap-2.14.0/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/itoa-1.0.18/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/itoa-1.0.18/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/jiff-0.2.37/COPYING +3 -0
- package/dist/native/licenses/cargo/jiff-0.2.37/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/jiff-core-0.1.1/COPYING +3 -0
- package/dist/native/licenses/cargo/jiff-core-0.1.1/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/jiff-tzdb-0.1.9/COPYING +3 -0
- package/dist/native/licenses/cargo/jiff-tzdb-0.1.9/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/jiff-tzdb-platform-0.1.3/COPYING +3 -0
- package/dist/native/licenses/cargo/jiff-tzdb-platform-0.1.3/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/log-0.4.34/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/log-0.4.34/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/lzma-rust2-0.21.0/LICENSE +201 -0
- package/dist/native/licenses/cargo/memchr-2.8.2/COPYING +3 -0
- package/dist/native/licenses/cargo/memchr-2.8.2/LICENSE-MIT +21 -0
- package/dist/native/licenses/cargo/miniz_oxide-0.9.1/LICENSE +25 -0
- package/dist/native/licenses/cargo/miniz_oxide-0.9.1/LICENSE-APACHE.md +177 -0
- package/dist/native/licenses/cargo/miniz_oxide-0.9.1/LICENSE-MIT.md +24 -0
- package/dist/native/licenses/cargo/miniz_oxide-0.9.1/LICENSE-ZLIB.md +14 -0
- package/dist/native/licenses/cargo/num-bigint-0.4.6/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/num-bigint-0.4.6/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/num-integer-0.1.47/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/num-integer-0.1.47/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/num-traits-0.2.19/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/num-traits-0.2.19/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/proc-macro2-1.0.107/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/proc-macro2-1.0.107/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/quote-1.0.47/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/quote-1.0.47/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/regex-automata-0.4.18/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/regex-automata-0.4.18/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/regex-syntax-0.8.11/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/regex-syntax-0.8.11/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/rustc-hash-2.1.2/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/rustc-hash-2.1.2/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/ryu-js-1.0.2/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/ryu-js-1.0.2/LICENSE-BOOST +23 -0
- package/dist/native/licenses/cargo/serde-1.0.229/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/serde-1.0.229/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/serde_core-1.0.229/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/serde_core-1.0.229/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/serde_derive-1.0.229/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/serde_derive-1.0.229/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/serde_json-1.0.152/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/serde_json-1.0.152/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/simd-adler32-0.3.10/LICENSE.md +21 -0
- package/dist/native/licenses/cargo/smallvec-1.15.1/LICENSE-APACHE +201 -0
- package/dist/native/licenses/cargo/smallvec-1.15.1/LICENSE-MIT +25 -0
- package/dist/native/licenses/cargo/syn-2.0.119/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/syn-2.0.119/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/syn-3.0.7/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/syn-3.0.7/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/thiserror-2.0.21/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/thiserror-2.0.21/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/thiserror-impl-2.0.21/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/thiserror-impl-2.0.21/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/unicode-ident-1.0.26/LICENSE-APACHE +176 -0
- package/dist/native/licenses/cargo/unicode-ident-1.0.26/LICENSE-MIT +23 -0
- package/dist/native/licenses/cargo/unicode-ident-1.0.26/LICENSE-UNICODE +39 -0
- package/dist/native/licenses/cargo/xxhash-rust-0.8.15/LICENSE +23 -0
- package/dist/native/licenses/cargo/zlib-rs-0.6.8/LICENSE +19 -0
- package/dist/native/licenses/cargo/zmij-1.0.23/LICENSE-MIT +23 -0
- package/dist/native/licenses/ts-rust/LICENSE +21 -0
- package/dist/native/licenses/ts-rust/NOTICE.md +53 -0
- package/dist/native/licenses/ts-rust/licenses/Go-LICENSE.txt +27 -0
- package/dist/native/licenses/ts-rust/licenses/TypeScript-LICENSE.txt +55 -0
- package/dist/native/licenses/ts-rust/licenses/TypeScript-NOTICE.txt +405 -0
- package/dist/native/licenses/ts-rust/licenses/Unicode-LICENSE.txt +39 -0
- package/dist/native/licenses/ts-rust/licenses/vscode-languageserver-node-LICENSE.txt +18 -0
- package/dist/native/licenses/typescript/LICENSE.txt +55 -0
- package/dist/native/licenses/typescript/ThirdPartyNoticeText.txt +193 -0
- package/dist/native/licenses/typescript/manifest.json +105 -0
- package/dist/native/trust_native_wasm.wasm +0 -0
- package/dist/svelte2tsx/index.cjs +7064 -0
- package/dist/svelte2tsx/svelte-jsx-v4.d.ts +230 -0
- package/dist/svelte2tsx/svelte-jsx.d.ts +1492 -0
- package/dist/svelte2tsx/svelte-shims-v4.d.ts +290 -0
- package/dist/svelte2tsx/svelte-shims.d.ts +305 -0
- package/package.json +25 -5
- package/dist/chunk-NG4KYWVW.js.map +0 -1
- package/dist/chunk-OSSITT3R.js.map +0 -1
- package/dist/chunk-V72KWVWP.js.map +0 -1
package/README.md
CHANGED
|
@@ -446,7 +446,11 @@ export default [
|
|
|
446
446
|
file's directory. `--tsconfig` overrides it, and files no entry matches use the nearest `tsconfig.json`. A file
|
|
447
447
|
that maps to a missing tsconfig stops the run (exit 2) with the entry named. ESLint ignores this key.
|
|
448
448
|
- Globs use ESLint flat-config semantics (minimatch, `dot: true`, `!negation`, last match wins), relative to the
|
|
449
|
-
config file's directory, matched on realpaths. A glob matching no file is
|
|
449
|
+
config file's directory, matched on realpaths. A glob matching no file is reported, not fatal: the CLIs print
|
|
450
|
+
`trust <command>: warning: … glob "…" matches no files` and run, and `loadTrustConfig` (the ESLint route) loads
|
|
451
|
+
and lists it in `unmatchedGlobs`, so every entry point treats the same config the same way (a glob can match
|
|
452
|
+
nothing for a legitimate moment, e.g. generated files absent in a fresh worktree). Pass
|
|
453
|
+
`loadTrustConfig(file, { validateGlobs: true })` to make it a load error, or `false` not to check.
|
|
450
454
|
|
|
451
455
|
A call is also trusted when its declared return type is `Result` / `Promise<Result>` from `@noego/trust`,
|
|
452
456
|
unless its origin is explicitly distrusted. `Result.err`, `Trust.try` and `Trust.tryAsync` are recognised
|
|
@@ -527,12 +531,28 @@ trust refactor server # the order to fix the files with
|
|
|
527
531
|
trust refactor server ui --json # the same plan as JSON: { "waves": [["a.ts", ["b.ts", "c.ts"]], ["d.ts"]], ... }
|
|
528
532
|
```
|
|
529
533
|
|
|
530
|
-
`trust check`
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
534
|
+
`trust check` uses the Rust engine automatically, with the bundled Wasm engine as fallback.
|
|
535
|
+
It needs neither ESLint nor an installed TypeScript package. TypeScript 5.9.3 standard-library declarations
|
|
536
|
+
are copied and embedded when the engine is built; they are not chosen from the checked project at runtime.
|
|
537
|
+
The experimental `--rs` and `--go` flags have been removed.
|
|
538
|
+
|
|
539
|
+
Every rule, including the opt-in `type-claim`, `untrusted-value`, `dropped-result` and `redundant-guard`,
|
|
540
|
+
runs in the engine. The TypeScript implementation in `src/core` stays the reference: differential tests
|
|
541
|
+
(`test/native-check.test.ts`, `test/native-opt-in.test.ts`) run the fixtures and the shared rule-case corpus
|
|
542
|
+
through both and compare whole findings (file, position, rule, message, severity). Two things keep the
|
|
543
|
+
output independent of the compiler: type text in messages is printed in a canonical member order
|
|
544
|
+
(`src/core/type-text.ts`), and when a receiver or member is a union the declaration with the smallest
|
|
545
|
+
origin is the one reported, on both sides. See [native/RELEASE.md](native/RELEASE.md) for the release process.
|
|
546
|
+
|
|
547
|
+
The check walks the given files and directories for `.ts`/`.tsx` (skipping `node_modules`, `dist`,
|
|
548
|
+
`.d.ts`) and skips the config's `ignore` zone. Exit codes are 0 for clean or warnings only,
|
|
549
|
+
1 for trust violations, and 2 when setup, parsing or the engine fails. `--perf` adds three optional
|
|
550
|
+
warnings: `perf-delete-property`, `perf-object-as-map`, and `perf-prototype-mutation`. It does not
|
|
551
|
+
include a sparse-array rule. Warnings teach the tradeoff and never change the exit code.
|
|
552
|
+
`--json` emits one object with `findings` (each has `severity: "error" | "warning"`), setup `errors`,
|
|
553
|
+
configuration `warnings`, and a `summary` on success.
|
|
554
|
+
|
|
555
|
+
Each file is type-checked with `--tsconfig`
|
|
536
556
|
when given, else the tsconfig of the first matching `tsconfig` entry in the trust config, else the nearest
|
|
537
557
|
`tsconfig.json` above it (one program per tsconfig, rooted at the checked files plus the tsconfig's `.d.ts`
|
|
538
558
|
files). Map files whose ESLint tsconfig is not the nearest one (e.g. `ui/**` linted with `tsconfig.web.json`)
|
|
@@ -540,7 +560,8 @@ in the config, and `trust check server ui` needs no flags. `trust explain` resol
|
|
|
540
560
|
`--root <dir>` (all three commands) resolves the config's globs, `tsconfig` paths and baseline keys against
|
|
541
561
|
`<dir>` instead of the config file's directory. `trust refactor` takes `--tsconfig` and `--root` the same way.
|
|
542
562
|
|
|
543
|
-
`trust baseline`
|
|
563
|
+
`trust baseline` still uses the TypeScript package (no ESLint, no env flag), as do `trust explain`,
|
|
564
|
+
`trust refactor` and the public core API. It finds files exactly as `trust check`
|
|
544
565
|
does, takes `--tsconfig <path>` the same way, and compares the core's findings with `trust-baseline.json`.
|
|
545
566
|
With paths (`trust baseline ui`), the run speaks only for the files it checked: only their entries are reported
|
|
546
567
|
as having fewer findings, and `--update` rewrites only their entries, keeping every other file's entries as they
|
|
@@ -596,7 +617,21 @@ server/users.ts:73 (zone: checked)
|
|
|
596
617
|
why: Type assertion claims "unknown" is "T", but "unknown" is not assignable to "T": nothing proves it. Narrow or validate the value instead.
|
|
597
618
|
```
|
|
598
619
|
|
|
599
|
-
|
|
620
|
+
The CLI commands (`check`, `baseline`, `explain`, `refactor`) always check `.svelte` components,
|
|
621
|
+
including script and template expressions, using in-memory conversion and original source positions.
|
|
622
|
+
Svelte is optional: `@noego/trust` declares no dependencies, so a TypeScript-only project never installs
|
|
623
|
+
`svelte`. When `.svelte` files are checked, `svelte` (and `typescript`) must be installed in the project;
|
|
624
|
+
trust converts components with its own bundled `svelte2tsx`, which is loaded only then. A missing `svelte`,
|
|
625
|
+
conversion errors and collisions with a real adjacent `.svelte.ts` fail the run; components are never skipped.
|
|
626
|
+
Preprocessors are not run. Real `.svelte.ts` rune modules remain ordinary TypeScript files.
|
|
627
|
+
|
|
628
|
+
Add `"extend": ["web", "svelte"]` (or `["default", "svelte"]`) to trust Svelte APIs;
|
|
629
|
+
conversion does **not** automatically apply the preset. Only generated snippet-render wrappers are trusted,
|
|
630
|
+
not their argument expressions or snippet bodies. `createContext` remains untrusted, including its setter
|
|
631
|
+
(the same declaration origin): use `setContext` or a justified `//trust:accept` directive.
|
|
632
|
+
|
|
633
|
+
Not covered: the ESLint `.svelte` integration, lifecycle cleanup guards, and TypeScript's own unsound
|
|
634
|
+
corners (method bivariance, array covariance).
|
|
600
635
|
|
|
601
636
|
#### Validators: `//trust:validator_function`
|
|
602
637
|
|
|
@@ -29,10 +29,11 @@ declare class Zones {
|
|
|
29
29
|
readonly rootDir: string;
|
|
30
30
|
private readonly passthrough;
|
|
31
31
|
private readonly ignore;
|
|
32
|
+
readonly virtualPaths: ReadonlyMap<string, string>;
|
|
32
33
|
private readonly cache;
|
|
33
34
|
constructor(
|
|
34
35
|
/** Realpath of the project root (directory of the leaf trust config). */
|
|
35
|
-
rootDir: string, passthrough: readonly ZoneGroup[], ignore: readonly ZoneGroup[]);
|
|
36
|
+
rootDir: string, passthrough: readonly ZoneGroup[], ignore: readonly ZoneGroup[], virtualPaths?: ReadonlyMap<string, string>);
|
|
36
37
|
/** Zone of a file. Ignore wins over passthrough; files outside the root or in node_modules are external. */
|
|
37
38
|
zoneOf(fileName: string): Zone;
|
|
38
39
|
/** Project-relative posix path (for `local:` origins and baselines), or the absolute path when outside. */
|
|
@@ -69,6 +70,11 @@ interface TrustConfig {
|
|
|
69
70
|
readonly tsconfig: readonly TsconfigMapping[];
|
|
70
71
|
/** Per-rule settings (`rules`), each resolved along the chain; unset keys take DEFAULT_RULE_SETTINGS. */
|
|
71
72
|
readonly rules: TrustRuleSettings;
|
|
73
|
+
/**
|
|
74
|
+
* Globs that matched no file when the config loaded, as `trust config <source>: <message>` lines.
|
|
75
|
+
* Filled under `validateGlobs: 'report'` (the default); empty when globs are not checked or throw.
|
|
76
|
+
*/
|
|
77
|
+
readonly unmatchedGlobs: readonly string[];
|
|
72
78
|
}
|
|
73
79
|
/** An opt-in rule's switch. */
|
|
74
80
|
type RuleSwitch = 'on' | 'off';
|
|
@@ -94,9 +100,18 @@ interface TsconfigMapping extends ZoneGroup {
|
|
|
94
100
|
/** Absolute tsconfig path. Its existence is checked when a file maps to it, not at load. */
|
|
95
101
|
readonly tsconfig: string;
|
|
96
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* What to do with a glob that matches no file: `'report'` lists it in `TrustConfig.unmatchedGlobs`
|
|
105
|
+
* and loads anyway, `true` makes it a load error (TrustConfigError), `false` does not check.
|
|
106
|
+
*/
|
|
107
|
+
type GlobValidation = boolean | 'report';
|
|
97
108
|
interface LoadTrustConfigOptions {
|
|
98
|
-
/**
|
|
99
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Check that every glob matches at least one file (default `'report'`). A glob can match nothing for
|
|
111
|
+
* a legitimate moment (generated files absent in a fresh worktree), so by default every entry point
|
|
112
|
+
* (ESLint and the CLIs alike) loads and reports it rather than refusing to run; pass `true` to fail.
|
|
113
|
+
*/
|
|
114
|
+
readonly validateGlobs?: GlobValidation;
|
|
100
115
|
/**
|
|
101
116
|
* Directory the leaf config's globs, `tsconfig` paths, baseline keys and `local:` origins resolve
|
|
102
117
|
* against, instead of the config file's own directory (a config kept outside the project).
|
|
@@ -114,7 +129,10 @@ declare class TrustConfigError extends Error {
|
|
|
114
129
|
* zod.object, @scope/pkg.fn npm packages (bare package name)
|
|
115
130
|
*/
|
|
116
131
|
declare function normalizeOrigin(origin: string): string;
|
|
117
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Loads and validates a trust config file and its `extend` chain. Throws TrustConfigError for a malformed
|
|
134
|
+
* config; a glob matching no file is reported in `unmatchedGlobs` unless `validateGlobs` says otherwise.
|
|
135
|
+
*/
|
|
118
136
|
declare function loadTrustConfig(configFile: string, options?: LoadTrustConfigOptions): TrustConfig;
|
|
119
137
|
/** Union of every trust entry in the chain (for tooling and tests). */
|
|
120
138
|
declare function effectiveTrustList(config: TrustConfig): string[];
|
|
@@ -38,8 +38,9 @@ import {
|
|
|
38
38
|
isTrustPackageFile,
|
|
39
39
|
nodeBelow,
|
|
40
40
|
realpathOrSelf,
|
|
41
|
+
svelteFor,
|
|
41
42
|
trustDirectivesIn
|
|
42
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-UG6D3V4M.js";
|
|
43
44
|
|
|
44
45
|
// src/core/guard.ts
|
|
45
46
|
function unparen(ts, node) {
|
|
@@ -174,7 +175,7 @@ var TrustPolicy = class {
|
|
|
174
175
|
constructor(ts, checker, config, extraTrust = []) {
|
|
175
176
|
this.ts = ts;
|
|
176
177
|
this.checker = checker;
|
|
177
|
-
this.zones = new Zones(config.rootDir, config.passthrough, config.ignore);
|
|
178
|
+
this.zones = new Zones(config.rootDir, config.passthrough, config.ignore, svelteFor(checker)?.paths);
|
|
178
179
|
this.origins = new OriginResolver(ts, this.zones);
|
|
179
180
|
this.rules = config.rules;
|
|
180
181
|
const fromOptions = { source: "rule options", trust: extraTrust, distrust: [], typeTrust: [], typeDistrust: [] };
|
|
@@ -230,15 +231,61 @@ var TrustPolicy = class {
|
|
|
230
231
|
if (decision.trusted) return { kind: "trusted", origin, by: decision.by };
|
|
231
232
|
return { kind: "untrusted", origin };
|
|
232
233
|
}
|
|
234
|
+
/** Pick by origin, never compiler-internal union order (JavaScript compares UTF-16 units). */
|
|
235
|
+
choose_origin_declaration(candidates) {
|
|
236
|
+
let best;
|
|
237
|
+
let bestOrigin;
|
|
238
|
+
for (const declaration of candidates) {
|
|
239
|
+
const origin = this.origins.originOf(declaration).origin;
|
|
240
|
+
if (bestOrigin === void 0 || origin < bestOrigin) {
|
|
241
|
+
best = declaration;
|
|
242
|
+
bestOrigin = origin;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return best;
|
|
246
|
+
}
|
|
247
|
+
/** Equal-origin overloads keep the existing declaration; distinct origins select the minimum. */
|
|
248
|
+
symbol_declaration(symbol, fallback = symbol?.valueDeclaration ?? symbol?.declarations?.[0]) {
|
|
249
|
+
const candidates = symbol?.declarations ?? [];
|
|
250
|
+
if (candidates.length > 1) {
|
|
251
|
+
const firstOrigin = this.origins.originOf(candidates[0]).origin;
|
|
252
|
+
if (candidates.some((declaration) => this.origins.originOf(declaration).origin !== firstOrigin)) {
|
|
253
|
+
return this.choose_origin_declaration(candidates);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return fallback;
|
|
257
|
+
}
|
|
233
258
|
calleeDeclaration(node) {
|
|
234
259
|
const ts = this.ts;
|
|
235
260
|
const signature = this.checker.getResolvedSignature(node);
|
|
236
261
|
const fromSignature = signature?.declaration && !ts.isJSDocSignature(signature.declaration) ? signature.declaration : void 0;
|
|
262
|
+
const callee = node.expression;
|
|
263
|
+
if (ts.isPropertyAccessExpression(callee)) {
|
|
264
|
+
const receiver = this.checker.getApparentType(this.checker.getTypeAtLocation(callee.expression));
|
|
265
|
+
if (receiver.isUnion()) {
|
|
266
|
+
const candidates = receiver.types.flatMap((member) => this.checker.getPropertyOfType(member, callee.name.text)?.declarations ?? []);
|
|
267
|
+
const declaration2 = this.choose_origin_declaration(candidates);
|
|
268
|
+
if (declaration2) {
|
|
269
|
+
const chosen = fromSignature && this.origins.originOf(fromSignature).origin === this.origins.originOf(declaration2).origin ? fromSignature : declaration2;
|
|
270
|
+
return { declaration: chosen, signature };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const calleeType = this.checker.getApparentType(this.checker.getTypeAtLocation(callee));
|
|
275
|
+
if (calleeType.isUnion()) {
|
|
276
|
+
const kind = ts.isNewExpression(node) ? ts.SignatureKind.Construct : ts.SignatureKind.Call;
|
|
277
|
+
const candidates = calleeType.types.flatMap((member) => this.checker.getSignaturesOfType(member, kind).flatMap((candidate) => candidate.declaration && !ts.isJSDocSignature(candidate.declaration) ? [candidate.declaration] : []));
|
|
278
|
+
const declaration2 = this.choose_origin_declaration(candidates);
|
|
279
|
+
if (declaration2) {
|
|
280
|
+
const chosen = fromSignature && this.origins.originOf(fromSignature).origin === this.origins.originOf(declaration2).origin ? fromSignature : declaration2;
|
|
281
|
+
return { declaration: chosen, signature };
|
|
282
|
+
}
|
|
283
|
+
}
|
|
237
284
|
const anonymous = !fromSignature || ts.isCallSignatureDeclaration(fromSignature) || ts.isConstructSignatureDeclaration(fromSignature) || ts.isFunctionTypeNode(fromSignature);
|
|
238
285
|
if (fromSignature && !anonymous) return { declaration: fromSignature, signature };
|
|
239
286
|
let symbol = this.checker.getSymbolAtLocation(node.expression);
|
|
240
287
|
if (symbol && symbol.flags & ts.SymbolFlags.Alias) symbol = this.checker.getAliasedSymbol(symbol);
|
|
241
|
-
const fromSymbol = symbol?.declarations?.[0];
|
|
288
|
+
const fromSymbol = this.symbol_declaration(symbol, symbol?.declarations?.[0]);
|
|
242
289
|
const sameFile = fromSymbol && fromSignature && fromSymbol.getSourceFile() === fromSignature.getSourceFile();
|
|
243
290
|
const declaration = !fromSignature || sameFile ? fromSymbol : fromSignature;
|
|
244
291
|
return declaration ? { declaration, signature } : null;
|
|
@@ -261,7 +308,7 @@ var TrustPolicy = class {
|
|
|
261
308
|
/** 'ok' | 'err' when the type is @noego/trust's Ok/Err (by the declaration of its `ok` property). */
|
|
262
309
|
resultVariant(type) {
|
|
263
310
|
const property = type.getProperty("ok");
|
|
264
|
-
const declaration = property
|
|
311
|
+
const declaration = this.symbol_declaration(property);
|
|
265
312
|
if (!property || !declaration || !isTrustPackageFile(declaration.getSourceFile().fileName)) return null;
|
|
266
313
|
const discriminant = this.checker.typeToString(this.checker.getTypeOfSymbol(property));
|
|
267
314
|
if (discriminant === "true") return "ok";
|
|
@@ -1567,6 +1614,146 @@ function redundantGuardsIn(sourceFile, context) {
|
|
|
1567
1614
|
return found;
|
|
1568
1615
|
}
|
|
1569
1616
|
|
|
1617
|
+
// src/core/type-text.ts
|
|
1618
|
+
var OPEN = /* @__PURE__ */ new Set(["(", "[", "{", "<"]);
|
|
1619
|
+
var CLOSE = { ")": "(", "]": "[", "}": "{", ">": "<" };
|
|
1620
|
+
function canonicalTypeText(text) {
|
|
1621
|
+
return canonical(text.trim());
|
|
1622
|
+
}
|
|
1623
|
+
function canonical(text) {
|
|
1624
|
+
const colon = memberTypeStart(text);
|
|
1625
|
+
if (colon >= 0) return `${text.slice(0, colon + 1)} ${canonical(text.slice(colon + 1).trim())}`;
|
|
1626
|
+
const union2 = splitTop(text, " | ");
|
|
1627
|
+
if (union2.length > 1) return union2.map(canonical).sort(compare).join(" | ");
|
|
1628
|
+
const intersection = splitTop(text, " & ");
|
|
1629
|
+
if (intersection.length > 1) return intersection.map(canonical).sort(compare).join(" & ");
|
|
1630
|
+
return canonicalGroups(text);
|
|
1631
|
+
}
|
|
1632
|
+
function canonicalGroups(text) {
|
|
1633
|
+
let out = "";
|
|
1634
|
+
let i = 0;
|
|
1635
|
+
while (i < text.length) {
|
|
1636
|
+
const ch = text[i];
|
|
1637
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
1638
|
+
const end = stringEnd(text, i);
|
|
1639
|
+
out += text.slice(i, end);
|
|
1640
|
+
i = end;
|
|
1641
|
+
continue;
|
|
1642
|
+
}
|
|
1643
|
+
if (ch === "=" && text[i + 1] === ">") {
|
|
1644
|
+
out += "=>";
|
|
1645
|
+
i += 2;
|
|
1646
|
+
continue;
|
|
1647
|
+
}
|
|
1648
|
+
if (OPEN.has(ch)) {
|
|
1649
|
+
const end = groupEnd(text, i);
|
|
1650
|
+
if (end < 0) {
|
|
1651
|
+
out += text.slice(i);
|
|
1652
|
+
break;
|
|
1653
|
+
}
|
|
1654
|
+
const inner = text.slice(i + 1, end);
|
|
1655
|
+
out += ch + (ch === "{" ? canonicalMembers(inner) : splitTop(inner, ", ").map(canonical).join(", ")) + text[end];
|
|
1656
|
+
i = end + 1;
|
|
1657
|
+
continue;
|
|
1658
|
+
}
|
|
1659
|
+
out += ch;
|
|
1660
|
+
i += 1;
|
|
1661
|
+
}
|
|
1662
|
+
return out;
|
|
1663
|
+
}
|
|
1664
|
+
function canonicalMembers(inner) {
|
|
1665
|
+
const body = inner.trim();
|
|
1666
|
+
if (body === "") return inner;
|
|
1667
|
+
const members2 = splitTop(body, ";").map((member) => member.trim()).filter((member) => member !== "");
|
|
1668
|
+
const canonicalised = members2.map(canonical);
|
|
1669
|
+
canonicalised.sort(compare);
|
|
1670
|
+
return ` ${canonicalised.join("; ")}; `;
|
|
1671
|
+
}
|
|
1672
|
+
function memberTypeStart(member) {
|
|
1673
|
+
let depth = 0;
|
|
1674
|
+
let i = 0;
|
|
1675
|
+
while (i < member.length) {
|
|
1676
|
+
const ch = member[i];
|
|
1677
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
1678
|
+
i = stringEnd(member, i);
|
|
1679
|
+
continue;
|
|
1680
|
+
}
|
|
1681
|
+
if (ch === "=" && member[i + 1] === ">") {
|
|
1682
|
+
i += 2;
|
|
1683
|
+
continue;
|
|
1684
|
+
}
|
|
1685
|
+
if (OPEN.has(ch)) depth += 1;
|
|
1686
|
+
else if (CLOSE[ch] !== void 0) depth -= 1;
|
|
1687
|
+
else if (ch === ":" && depth === 0) return i;
|
|
1688
|
+
i += 1;
|
|
1689
|
+
}
|
|
1690
|
+
return -1;
|
|
1691
|
+
}
|
|
1692
|
+
function splitTop(text, separator) {
|
|
1693
|
+
const parts = [];
|
|
1694
|
+
let depth = 0;
|
|
1695
|
+
let start = 0;
|
|
1696
|
+
let i = 0;
|
|
1697
|
+
while (i < text.length) {
|
|
1698
|
+
const ch = text[i];
|
|
1699
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
1700
|
+
i = stringEnd(text, i);
|
|
1701
|
+
continue;
|
|
1702
|
+
}
|
|
1703
|
+
if (ch === "=" && text[i + 1] === ">") {
|
|
1704
|
+
i += 2;
|
|
1705
|
+
continue;
|
|
1706
|
+
}
|
|
1707
|
+
if (OPEN.has(ch)) depth += 1;
|
|
1708
|
+
else if (CLOSE[ch] !== void 0) depth -= 1;
|
|
1709
|
+
else if (depth === 0 && text.startsWith(separator, i)) {
|
|
1710
|
+
parts.push(text.slice(start, i));
|
|
1711
|
+
i += separator.length;
|
|
1712
|
+
start = i;
|
|
1713
|
+
continue;
|
|
1714
|
+
}
|
|
1715
|
+
i += 1;
|
|
1716
|
+
}
|
|
1717
|
+
parts.push(text.slice(start));
|
|
1718
|
+
return parts;
|
|
1719
|
+
}
|
|
1720
|
+
function stringEnd(text, start) {
|
|
1721
|
+
const quote = text[start];
|
|
1722
|
+
let i = start + 1;
|
|
1723
|
+
while (i < text.length) {
|
|
1724
|
+
if (text[i] === "\\") i += 2;
|
|
1725
|
+
else if (text[i] === quote) return i + 1;
|
|
1726
|
+
else i += 1;
|
|
1727
|
+
}
|
|
1728
|
+
return text.length;
|
|
1729
|
+
}
|
|
1730
|
+
function groupEnd(text, start) {
|
|
1731
|
+
const open = text[start];
|
|
1732
|
+
let depth = 0;
|
|
1733
|
+
let i = start;
|
|
1734
|
+
while (i < text.length) {
|
|
1735
|
+
const ch = text[i];
|
|
1736
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
1737
|
+
i = stringEnd(text, i);
|
|
1738
|
+
continue;
|
|
1739
|
+
}
|
|
1740
|
+
if (ch === "=" && text[i + 1] === ">") {
|
|
1741
|
+
i += 2;
|
|
1742
|
+
continue;
|
|
1743
|
+
}
|
|
1744
|
+
if (OPEN.has(ch)) depth += 1;
|
|
1745
|
+
else if (CLOSE[ch] !== void 0) {
|
|
1746
|
+
depth -= 1;
|
|
1747
|
+
if (depth === 0) return CLOSE[ch] === open ? i : -1;
|
|
1748
|
+
}
|
|
1749
|
+
i += 1;
|
|
1750
|
+
}
|
|
1751
|
+
return -1;
|
|
1752
|
+
}
|
|
1753
|
+
function compare(a, b) {
|
|
1754
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1570
1757
|
// src/core/type-claims.ts
|
|
1571
1758
|
function claimSpan(claim2, sourceFile) {
|
|
1572
1759
|
return claim2.at ?? { start: claim2.node.getStart(sourceFile), end: claim2.node.getEnd() };
|
|
@@ -1597,7 +1784,10 @@ function clip2(text, max = MAX_TEXT) {
|
|
|
1597
1784
|
return flat.length > max ? `${flat.slice(0, max - 3)}...` : flat;
|
|
1598
1785
|
}
|
|
1599
1786
|
function typeText(context, type) {
|
|
1600
|
-
return clip2(context.checker.typeToString(type));
|
|
1787
|
+
return clip2(canonicalTypeText(context.checker.typeToString(type, void 0, typeTextFlags(context.ts))));
|
|
1788
|
+
}
|
|
1789
|
+
function typeTextFlags(ts) {
|
|
1790
|
+
return ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType | ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
|
1601
1791
|
}
|
|
1602
1792
|
function claim(node, origin, data) {
|
|
1603
1793
|
return { node, origin, data };
|
|
@@ -2021,7 +2211,7 @@ function clip3(text, max = MAX_TEXT2) {
|
|
|
2021
2211
|
return flat.length > max ? `${flat.slice(0, max - 3)}...` : flat;
|
|
2022
2212
|
}
|
|
2023
2213
|
function typeText2(context, type) {
|
|
2024
|
-
return clip3(context.checker.typeToString(type));
|
|
2214
|
+
return clip3(canonicalTypeText(context.checker.typeToString(type, void 0, typeTextFlags(context.ts))));
|
|
2025
2215
|
}
|
|
2026
2216
|
function isOpaque(ts, type) {
|
|
2027
2217
|
return (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !== 0;
|
|
@@ -2048,9 +2238,9 @@ function isDiscarded(ts, type) {
|
|
|
2048
2238
|
const members2 = type.isUnion() ? type.types : [type];
|
|
2049
2239
|
return members2.some((member) => (member.flags & ts.TypeFlags.Void) !== 0);
|
|
2050
2240
|
}
|
|
2051
|
-
function declarationOf(ts, checker, symbol) {
|
|
2241
|
+
function declarationOf(ts, checker, symbol, policy) {
|
|
2052
2242
|
const target = symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
2053
|
-
return target
|
|
2243
|
+
return policy.symbol_declaration(target);
|
|
2054
2244
|
}
|
|
2055
2245
|
function callTypeVerdict(node, context) {
|
|
2056
2246
|
const { ts, policy } = context;
|
|
@@ -2168,16 +2358,16 @@ function assignmentsIn(file, context) {
|
|
|
2168
2358
|
return assigned;
|
|
2169
2359
|
}
|
|
2170
2360
|
function identifierSource(node, context) {
|
|
2171
|
-
const { ts, checker } = context;
|
|
2361
|
+
const { ts, checker, policy } = context;
|
|
2172
2362
|
const symbol = ts.isShorthandPropertyAssignment(node.parent) ? checker.getShorthandAssignmentValueSymbol(node.parent) : checker.getSymbolAtLocation(node);
|
|
2173
|
-
const declaration = declarationOf(ts, checker, symbol);
|
|
2363
|
+
const declaration = declarationOf(ts, checker, symbol, policy);
|
|
2174
2364
|
return declaration ? declaredNameSource(declaration, context) : null;
|
|
2175
2365
|
}
|
|
2176
2366
|
function accessSource(node, context) {
|
|
2177
2367
|
const { ts, checker, policy } = context;
|
|
2178
2368
|
const name = ts.isPropertyAccessExpression(node) ? node.name : node.argumentExpression;
|
|
2179
2369
|
const named = ts.isPropertyAccessExpression(node) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name);
|
|
2180
|
-
const declaration = named ? declarationOf(ts, checker, checker.getSymbolAtLocation(name)) : void 0;
|
|
2370
|
+
const declaration = named ? declarationOf(ts, checker, checker.getSymbolAtLocation(name), policy) : void 0;
|
|
2181
2371
|
if (!declaration) return carriedSource(node.expression, context);
|
|
2182
2372
|
if (isFixedByDeclaration(declaration, context)) return null;
|
|
2183
2373
|
const verdict = policy.typeVerdictOf(declaration);
|
|
@@ -2346,7 +2536,7 @@ function isOutsideBinding(node, context) {
|
|
|
2346
2536
|
let inner = node;
|
|
2347
2537
|
while (isTransparent(ts, inner)) inner = inner.expression;
|
|
2348
2538
|
if (!ts.isIdentifier(inner)) return false;
|
|
2349
|
-
const declaration = declarationOf(ts, checker, checker.getSymbolAtLocation(inner));
|
|
2539
|
+
const declaration = declarationOf(ts, checker, checker.getSymbolAtLocation(inner), policy);
|
|
2350
2540
|
if (!declaration || !ts.isVariableDeclaration(declaration) || ts.isCatchClause(declaration.parent)) return false;
|
|
2351
2541
|
return policy.zones.zoneOf(declaration.getSourceFile().fileName) !== "checked";
|
|
2352
2542
|
}
|
|
@@ -2653,7 +2843,7 @@ function implementsHandoffs(declaration, context) {
|
|
|
2653
2843
|
return clauses.flatMap(
|
|
2654
2844
|
(clause) => clause.types.flatMap(
|
|
2655
2845
|
(implemented) => checker.getPropertiesOfType(checker.getTypeAtLocation(implemented)).flatMap((property) => {
|
|
2656
|
-
const member =
|
|
2846
|
+
const member = policy.symbol_declaration(property);
|
|
2657
2847
|
const signature = member ? memberSignature(property, implemented, context) : void 0;
|
|
2658
2848
|
if (!member || !signature) return [];
|
|
2659
2849
|
const verdict = policy.typeVerdictOf(member);
|
|
@@ -2702,7 +2892,7 @@ var emptyConfigs = /* @__PURE__ */ new Map();
|
|
|
2702
2892
|
function emptyTrustConfig(cwd) {
|
|
2703
2893
|
let config = emptyConfigs.get(cwd);
|
|
2704
2894
|
if (!config) {
|
|
2705
|
-
config = { file: "", rootDir: realpathOrSelf(cwd), levels: [], passthrough: [], ignore: [], strict: [], tsconfig: [], rules: DEFAULT_RULE_SETTINGS };
|
|
2895
|
+
config = { file: "", rootDir: realpathOrSelf(cwd), levels: [], passthrough: [], ignore: [], strict: [], tsconfig: [], rules: DEFAULT_RULE_SETTINGS, unmatchedGlobs: [] };
|
|
2706
2896
|
emptyConfigs.set(cwd, config);
|
|
2707
2897
|
}
|
|
2708
2898
|
return config;
|
|
@@ -2777,7 +2967,12 @@ function checkSourceFileWithAccepted(options) {
|
|
|
2777
2967
|
reportAt(guard.start, REDUNDANT_GUARD_RULE, REDUNDANT_GUARD_ORIGIN, redundantGuardMessage(guard));
|
|
2778
2968
|
}
|
|
2779
2969
|
}
|
|
2780
|
-
|
|
2970
|
+
const svelte = svelteFor(checker);
|
|
2971
|
+
const snippetTrusted = policy.lookup("svelte.__renderSnippet", "svelte").trusted && !("distrustedBy" in policy.lookup("svelte.Snippet", "svelte"));
|
|
2972
|
+
return { findings: svelte ? findings.flatMap((finding) => {
|
|
2973
|
+
const mapped = svelte.finding(sourceFile.fileName, finding, snippetTrusted);
|
|
2974
|
+
return mapped ? [mapped] : [];
|
|
2975
|
+
}) : findings, accepted };
|
|
2781
2976
|
}
|
|
2782
2977
|
|
|
2783
2978
|
export {
|
|
@@ -2788,6 +2983,7 @@ export {
|
|
|
2788
2983
|
droppedResultData,
|
|
2789
2984
|
droppedResultsIn,
|
|
2790
2985
|
entryMatches,
|
|
2986
|
+
decide,
|
|
2791
2987
|
TrustPolicy,
|
|
2792
2988
|
typedGuardContext,
|
|
2793
2989
|
nameBasedGuardContext,
|
|
@@ -2817,4 +3013,4 @@ export {
|
|
|
2817
3013
|
checkSourceFile,
|
|
2818
3014
|
checkSourceFileWithAccepted
|
|
2819
3015
|
};
|
|
2820
|
-
//# sourceMappingURL=chunk-
|
|
3016
|
+
//# sourceMappingURL=chunk-7PY2Q6OX.js.map
|