@stateward/core 1.2.2 → 1.3.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/dist/analyses.d.ts +37 -0
- package/dist/analyses.js +57 -0
- package/dist/backend/fingerprints.d.ts +3 -1
- package/dist/backend/fingerprints.js +198 -9
- package/dist/backend/program-record.d.ts +7 -0
- package/dist/backend/program-size.d.ts +32 -0
- package/dist/backend/program-size.js +166 -0
- package/dist/backend/typescript6.d.ts +62 -32
- package/dist/backend/typescript6.js +1615 -164
- package/dist/baseline.d.ts +1 -1
- package/dist/baseline.js +14 -10
- package/dist/cache.d.ts +92 -4
- package/dist/cache.js +257 -68
- package/dist/checker.d.ts +28 -3
- package/dist/checker.js +42 -8
- package/dist/class-id.d.ts +34 -0
- package/dist/class-id.js +93 -0
- package/dist/code-text.d.ts +8 -0
- package/dist/code-text.js +66 -0
- package/dist/config-file.js +7 -5
- package/dist/config.d.ts +10 -2
- package/dist/config.js +490 -48
- package/dist/define.d.ts +8 -2
- package/dist/disk-cache.d.ts +34 -2
- package/dist/disk-cache.js +82 -15
- package/dist/engine.d.ts +64 -3
- package/dist/engine.js +474 -59
- package/dist/fact-lines.d.ts +31 -0
- package/dist/fact-lines.js +197 -0
- package/dist/facts-versions.d.ts +27 -0
- package/dist/facts-versions.js +99 -0
- package/dist/fixes.js +4 -1
- package/dist/ignores.d.ts +11 -0
- package/dist/ignores.js +74 -27
- package/dist/implementation.d.ts +0 -6
- package/dist/implementation.js +0 -17
- package/dist/index.d.ts +9 -9
- package/dist/index.js +12 -7
- package/dist/internal.d.ts +13 -6
- package/dist/internal.js +7 -3
- package/dist/journal.d.ts +40 -0
- package/dist/journal.js +197 -0
- package/dist/lazy.d.ts +8 -1
- package/dist/lazy.js +27 -2
- package/dist/ledger.d.ts +2 -2
- package/dist/ledger.js +2 -2
- package/dist/memory-plan.d.ts +121 -0
- package/dist/memory-plan.js +174 -0
- package/dist/off-by-default.d.ts +13 -0
- package/dist/off-by-default.js +15 -0
- package/dist/options.d.ts +21 -5
- package/dist/options.js +22 -7
- package/dist/package-facts.d.ts +211 -17
- package/dist/package-facts.js +520 -38
- package/dist/plan.d.ts +1 -1
- package/dist/plan.js +7 -2
- package/dist/release.d.ts +12 -21
- package/dist/release.js +26 -38
- package/dist/renamed.d.ts +22 -3
- package/dist/renamed.js +50 -16
- package/dist/rollout.js +7 -4
- package/dist/severity.d.ts +1 -1
- package/dist/severity.js +17 -3
- package/dist/test-runner.d.ts +18 -0
- package/dist/test-runner.js +483 -0
- package/dist/testing.d.ts +3 -3
- package/dist/testing.js +5 -5
- package/dist/timing.d.ts +17 -7
- package/dist/timing.js +60 -38
- package/dist/types.d.ts +704 -20
- package/dist/unread.d.ts +90 -0
- package/dist/unread.js +405 -0
- package/dist/vocabulary.d.ts +1 -1
- package/dist/vocabulary.js +1 -1
- package/package.json +4 -2
package/dist/release.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The release trait: a value that must be released once it is no longer used (a subscription, a
|
|
3
3
|
* listener, a connection). Core reads where the trait is stated, in the plainest form first, and
|
|
4
|
-
* knows no library: a standard `Disposable` type,
|
|
5
|
-
*
|
|
4
|
+
* knows no library: a standard `Disposable` type, a `facts` line in the config, or the facts a
|
|
5
|
+
* plugin ships (`Plugin.facts`).
|
|
6
6
|
*/
|
|
7
7
|
import ts from "typescript";
|
|
8
8
|
import { type FactContext } from "./package-facts.js";
|
|
9
9
|
import type { TraitSource } from "./types.js";
|
|
10
|
-
|
|
11
|
-
export declare const RELEASE = "release";
|
|
10
|
+
import type { Unread } from "./unread.js";
|
|
12
11
|
/**
|
|
13
12
|
* How a value with the release trait is released: calling it (`unsubscribe()`), calling a method
|
|
14
13
|
* on it (`subscription.unsubscribe()`), or disposing of it (`using`, `[Symbol.dispose]()`).
|
|
@@ -24,34 +23,26 @@ export type ReleaseWay = {
|
|
|
24
23
|
};
|
|
25
24
|
/** The release trait of a call's result, and where it is stated. */
|
|
26
25
|
export type ReleaseTrait = {
|
|
26
|
+
readonly kind: "trait";
|
|
27
27
|
readonly way: ReleaseWay;
|
|
28
28
|
readonly source: TraitSource;
|
|
29
29
|
/** The function called, as the note names it: `onSnapshot`, `Observable.subscribe`. */
|
|
30
30
|
readonly callee: string;
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* The release trait of what a call returns, from the plainest statement of it: the config's
|
|
34
|
+
* `facts` line for the package function, the facts a plugin ships for it, then a standard
|
|
35
|
+
* `Disposable` or `AsyncDisposable` type. Undefined
|
|
36
|
+
* when nothing states it. A `Disposable` declared outside the project (the platform, a package) is
|
|
37
|
+
* left out, and so is a method that returns its own receiver (`stream.on(…)`).
|
|
36
38
|
*/
|
|
37
|
-
export
|
|
38
|
-
readonly platformPackages?: readonly string[];
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* The release trait of what a call returns, from the plainest statement of it: the project's
|
|
42
|
-
* `Release<T>` marker on the return type, the config's `facts` line for the package function, the
|
|
43
|
-
* facts a plugin ships for it, then a standard `Disposable` or `AsyncDisposable` type. Undefined
|
|
44
|
-
* when nothing states it. A `Disposable` declared in one of `options.platformPackages` is left
|
|
45
|
-
* out, and so is a method that returns its own receiver (`stream.on(…)`).
|
|
46
|
-
*/
|
|
47
|
-
export declare function releaseTraitOf(call: ts.CallExpression | ts.NewExpression, ctx: FactContext, options?: ReleaseOptions): ReleaseTrait | undefined;
|
|
39
|
+
export declare function releaseTraitOf(call: ts.CallExpression | ts.NewExpression, ctx: FactContext): ReleaseTrait | Unread | undefined;
|
|
48
40
|
/** A call `releaseCandidates` keeps or drops. */
|
|
49
41
|
export type ReleaseCandidate = (call: ts.CallExpression | ts.NewExpression) => boolean;
|
|
50
42
|
/**
|
|
51
43
|
* A test, from the syntax alone, of whether `releaseTraitOf` can find the trait for a call of the
|
|
52
|
-
* file, so a rule asks no type question about the others. When
|
|
53
|
-
*
|
|
54
|
-
* every call is kept. Otherwise only a `facts` line with `returns` can state the trait, and a call
|
|
44
|
+
* file, so a rule asks no type question about the others. When a project file declares a
|
|
45
|
+
* `[Symbol.dispose]` or `[Symbol.asyncDispose]` member, every call is kept. Otherwise only a `facts` line with `returns` can state the trait, and a call
|
|
55
46
|
* is kept when its callee's name (`onSnapshot`, `store.subscribe`) is the last part of such a
|
|
56
47
|
* line's name or a name the project gives it with `as`, or when the call is made through a name
|
|
57
48
|
* imported from a package such a line is listed under. Built once per file.
|
package/dist/release.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The release trait: a value that must be released once it is no longer used (a subscription, a
|
|
3
3
|
* listener, a connection). Core reads where the trait is stated, in the plainest form first, and
|
|
4
|
-
* knows no library: a standard `Disposable` type,
|
|
5
|
-
*
|
|
4
|
+
* knows no library: a standard `Disposable` type, a `facts` line in the config, or the facts a
|
|
5
|
+
* plugin ships (`Plugin.facts`).
|
|
6
6
|
*/
|
|
7
7
|
import ts from "typescript";
|
|
8
|
-
import { calleeName, importedFrom, packageFactOf, packageFunctionOf, pathOf, rootName, } from "./package-facts.js";
|
|
9
|
-
/** The trait name the `Release<T>` marker states: `"__guarantee:release"?: true`. */
|
|
10
|
-
export const RELEASE = "release";
|
|
8
|
+
import { calleeName, importedFrom, withReceiverOf, packageFactOf, packageFunctionOf, pathOf, rootName, } from "./package-facts.js";
|
|
11
9
|
function unwrapped(expression) {
|
|
12
10
|
let node = expression;
|
|
13
11
|
while (ts.isParenthesizedExpression(node) || ts.isNonNullExpression(node)) {
|
|
@@ -19,41 +17,36 @@ function wayOf(fact) {
|
|
|
19
17
|
return fact === "release" ? { kind: "call" } : { kind: "method", name: fact.release };
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
22
|
-
* The release trait of what a call returns, from the plainest statement of it: the
|
|
23
|
-
* `
|
|
24
|
-
*
|
|
25
|
-
* when nothing states it. A `Disposable` declared
|
|
26
|
-
* out, and so is a method that returns its own receiver (`stream.on(…)`).
|
|
20
|
+
* The release trait of what a call returns, from the plainest statement of it: the config's
|
|
21
|
+
* `facts` line for the package function, the facts a plugin ships for it, then a standard
|
|
22
|
+
* `Disposable` or `AsyncDisposable` type. Undefined
|
|
23
|
+
* when nothing states it. A `Disposable` declared outside the project (the platform, a package) is
|
|
24
|
+
* left out, and so is a method that returns its own receiver (`stream.on(…)`).
|
|
27
25
|
*/
|
|
28
|
-
export function releaseTraitOf(call, ctx
|
|
26
|
+
export function releaseTraitOf(call, ctx) {
|
|
29
27
|
const { types } = ctx;
|
|
30
28
|
const name = calleeName(call);
|
|
31
29
|
const symbol = name === undefined ? undefined : types.symbolAt(name);
|
|
32
30
|
const declared = symbol === undefined ? undefined : types.declarationOf(symbol);
|
|
33
31
|
const path = declared === undefined ? [] : pathOf(declared.node);
|
|
34
32
|
const calleeText = path.length > 0 ? path.join(".") : (name?.text ?? "the call");
|
|
35
|
-
if (types.guaranteesOf(call).includes(RELEASE)) {
|
|
36
|
-
const kind = types.disposeOf(call)?.kind;
|
|
37
|
-
const way = types.isCallable(call)
|
|
38
|
-
? { kind: "call" }
|
|
39
|
-
: kind === undefined
|
|
40
|
-
? undefined
|
|
41
|
-
: { kind: "dispose", async: kind === "async" };
|
|
42
|
-
if (way !== undefined)
|
|
43
|
-
return { way, source: { kind: "marker" }, callee: calleeText };
|
|
44
|
-
}
|
|
45
33
|
// A name the project gives a package function (`const listen = onSnapshot`) is followed to it.
|
|
46
34
|
const aliased = declared !== undefined && types.isOwnFile(declared.file) && ts.isIdentifier(call.expression)
|
|
47
35
|
? packageFunctionOf(call.expression, ctx)
|
|
48
36
|
: undefined;
|
|
49
37
|
const found = aliased !== undefined
|
|
50
|
-
? packageFactOf(aliased.declared,
|
|
38
|
+
? packageFactOf(aliased.declared, ctx, "returns")
|
|
51
39
|
: declared === undefined
|
|
52
40
|
? undefined
|
|
53
|
-
: packageFactOf(declared,
|
|
54
|
-
|
|
41
|
+
: packageFactOf(name === undefined ? declared : withReceiverOf(declared, name), ctx, "returns");
|
|
42
|
+
// A `returns` line left out for the version the project runs: not checked, never a pass.
|
|
43
|
+
if (found?.kind === "unread")
|
|
44
|
+
return found;
|
|
45
|
+
const returns = found?.fact.returns;
|
|
46
|
+
if (found !== undefined && returns !== undefined) {
|
|
55
47
|
return {
|
|
56
|
-
|
|
48
|
+
kind: "trait",
|
|
49
|
+
way: wayOf(returns),
|
|
57
50
|
source: { kind: found.source, package: found.package },
|
|
58
51
|
callee: calleeText,
|
|
59
52
|
};
|
|
@@ -66,10 +59,6 @@ export function releaseTraitOf(call, ctx, options = {}) {
|
|
|
66
59
|
// test mocks, Node's timers and streams): a package's value has the trait only through `facts`.
|
|
67
60
|
if (!types.isOwnFile(disposed.file))
|
|
68
61
|
return undefined;
|
|
69
|
-
const platform = types.packageOf(disposed.file);
|
|
70
|
-
if (platform !== undefined && (options.platformPackages ?? []).includes(platform)) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
62
|
// `stream.on(…)`, `hash.update(…)`: a method that returns its receiver starts nothing new.
|
|
74
63
|
const callee = unwrapped(call.expression);
|
|
75
64
|
if (ts.isPropertyAccessExpression(callee) &&
|
|
@@ -78,6 +67,7 @@ export function releaseTraitOf(call, ctx, options = {}) {
|
|
|
78
67
|
}
|
|
79
68
|
const kind = disposed.kind;
|
|
80
69
|
return {
|
|
70
|
+
kind: "trait",
|
|
81
71
|
way: { kind: "dispose", async: kind === "async" },
|
|
82
72
|
source: { kind: "type", name: kind === "async" ? "AsyncDisposable" : "Disposable" },
|
|
83
73
|
callee: calleeText,
|
|
@@ -85,20 +75,21 @@ export function releaseTraitOf(call, ctx, options = {}) {
|
|
|
85
75
|
}
|
|
86
76
|
/**
|
|
87
77
|
* A test, from the syntax alone, of whether `releaseTraitOf` can find the trait for a call of the
|
|
88
|
-
* file, so a rule asks no type question about the others. When
|
|
89
|
-
*
|
|
90
|
-
* every call is kept. Otherwise only a `facts` line with `returns` can state the trait, and a call
|
|
78
|
+
* file, so a rule asks no type question about the others. When a project file declares a
|
|
79
|
+
* `[Symbol.dispose]` or `[Symbol.asyncDispose]` member, every call is kept. Otherwise only a `facts` line with `returns` can state the trait, and a call
|
|
91
80
|
* is kept when its callee's name (`onSnapshot`, `store.subscribe`) is the last part of such a
|
|
92
81
|
* line's name or a name the project gives it with `as`, or when the call is made through a name
|
|
93
82
|
* imported from a package such a line is listed under. Built once per file.
|
|
94
83
|
*/
|
|
95
84
|
export function releaseCandidates(ctx) {
|
|
96
85
|
const { types } = ctx;
|
|
97
|
-
if (types.
|
|
86
|
+
if (types.declaresDispose())
|
|
98
87
|
return () => true;
|
|
99
88
|
const names = new Set();
|
|
100
89
|
const packages = new Set();
|
|
101
|
-
for
|
|
90
|
+
// A line left out for the project's version is a candidate too: its call is "not checked".
|
|
91
|
+
const withheld = Object.fromEntries(ctx.withheldFacts.map((one) => [one.package, one.functions]));
|
|
92
|
+
for (const facts of [ctx.facts, ctx.shippedFacts, withheld]) {
|
|
102
93
|
for (const [name, functions] of Object.entries(facts)) {
|
|
103
94
|
for (const [key, fact] of Object.entries(functions)) {
|
|
104
95
|
if (fact.returns === undefined)
|
|
@@ -166,9 +157,6 @@ export function describeRelease(trait) {
|
|
|
166
157
|
: trait.way.async
|
|
167
158
|
? "a value released with `await using` or `[Symbol.asyncDispose]()`"
|
|
168
159
|
: "a value released with `using` or `[Symbol.dispose]()`";
|
|
169
|
-
|
|
170
|
-
? "its return type is stated `Release`"
|
|
171
|
-
: describeTraitSource(trait.source);
|
|
172
|
-
return `\`${trait.callee}\` returns ${what} (${stated})`;
|
|
160
|
+
return `\`${trait.callee}\` returns ${what} (${describeTraitSource(trait.source)})`;
|
|
173
161
|
}
|
|
174
162
|
//# sourceMappingURL=release.js.map
|
package/dist/renamed.d.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Rule ids a release renamed, so that a rule's name says what is wrong. The old id keeps working:
|
|
3
3
|
* a config, an ignore comment, the rollout file and the baseline that still use one are read under
|
|
4
|
-
* the new id, with a warning that says what to rename.
|
|
4
|
+
* the new id, with a warning that says what to rename. A rule a release removed is skipped the same
|
|
5
|
+
* way, with a warning that says to delete it. Each pack declares its own (`Plugin.renamed`,
|
|
6
|
+
* `Plugin.removed`): core keeps no rule id of a pack.
|
|
5
7
|
*/
|
|
8
|
+
import type { Plugin } from "./types.js";
|
|
9
|
+
/** Old rule ids to the ids the rules have now, from the loaded packs. */
|
|
10
|
+
export type Renames = ReadonlyMap<string, string>;
|
|
11
|
+
/** The renamed rule ids the packs declare (`Plugin.renamed`), in plugin order; the first wins. */
|
|
12
|
+
export declare function renamesOf(plugins: readonly Plugin[]): Renames;
|
|
6
13
|
/** The id a renamed rule has now, or undefined when `ruleId` was not renamed. */
|
|
7
|
-
export declare function renamedRule(ruleId: string): string | undefined;
|
|
14
|
+
export declare function renamedRule(renames: Renames, ruleId: string): string | undefined;
|
|
15
|
+
/** Rule ids a release removed, with their add-ons of the same id (`Plugin.removed`), from the loaded packs. */
|
|
16
|
+
export declare function removedOf(plugins: readonly Plugin[]): ReadonlySet<string>;
|
|
17
|
+
/** What a config that names a removed rule or add-on is told: the entry has no effect; delete it. */
|
|
18
|
+
export declare function removedNotice(id: string, where: string): string;
|
|
8
19
|
/** What a config that names an old id is told: `a` is now `b`; rename it in `where`. */
|
|
9
20
|
export declare function renameNotice(before: string, now: string, where: string): string;
|
|
10
21
|
/**
|
|
@@ -25,5 +36,13 @@ export type RenamedIdPlace = {
|
|
|
25
36
|
* config file has to rename, and where. Only whole quoted ids count, so a longer id or a comment
|
|
26
37
|
* that mentions one in other words is left alone.
|
|
27
38
|
*/
|
|
28
|
-
export declare function renamedIdsIn(text: string): RenamedIdPlace[];
|
|
39
|
+
export declare function renamedIdsIn(renames: Renames, text: string): RenamedIdPlace[];
|
|
40
|
+
/** The line of the first place a text names `id` in quotes, for a notice that says where it is. */
|
|
41
|
+
export declare function quotedIdLine(text: string, id: string): number | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The 1-based line of `text` where the key `entry` is written after the key `name` (quoted or
|
|
44
|
+
* not): the line of a `facts` entry, `facts: { "@scope/pkg": { JwtGuard: … } }`. Undefined when
|
|
45
|
+
* the text does not write them so.
|
|
46
|
+
*/
|
|
47
|
+
export declare function keyLine(text: string, name: string, entry: string): number | undefined;
|
|
29
48
|
//# sourceMappingURL=renamed.d.ts.map
|
package/dist/renamed.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}));
|
|
1
|
+
/** The renamed rule ids the packs declare (`Plugin.renamed`), in plugin order; the first wins. */
|
|
2
|
+
export function renamesOf(plugins) {
|
|
3
|
+
const found = new Map();
|
|
4
|
+
for (const plugin of plugins) {
|
|
5
|
+
for (const [before, now] of Object.entries(plugin.renamed ?? {})) {
|
|
6
|
+
if (!found.has(before))
|
|
7
|
+
found.set(before, now);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return found;
|
|
11
|
+
}
|
|
13
12
|
/** The id a renamed rule has now, or undefined when `ruleId` was not renamed. */
|
|
14
|
-
export function renamedRule(ruleId) {
|
|
15
|
-
return
|
|
13
|
+
export function renamedRule(renames, ruleId) {
|
|
14
|
+
return renames.get(ruleId);
|
|
15
|
+
}
|
|
16
|
+
/** Rule ids a release removed, with their add-ons of the same id (`Plugin.removed`), from the loaded packs. */
|
|
17
|
+
export function removedOf(plugins) {
|
|
18
|
+
return new Set(plugins.flatMap((plugin) => plugin.removed ?? []));
|
|
19
|
+
}
|
|
20
|
+
/** What a config that names a removed rule or add-on is told: the entry has no effect; delete it. */
|
|
21
|
+
export function removedNotice(id, where) {
|
|
22
|
+
return `\`${id}\` was removed from stateward and has no effect; delete it from ${where}`;
|
|
16
23
|
}
|
|
17
24
|
/** What a config that names an old id is told: `a` is now `b`; rename it in `where`. */
|
|
18
25
|
export function renameNotice(before, now, where) {
|
|
@@ -31,12 +38,12 @@ export function movedNotice(before, now, where) {
|
|
|
31
38
|
* config file has to rename, and where. Only whole quoted ids count, so a longer id or a comment
|
|
32
39
|
* that mentions one in other words is left alone.
|
|
33
40
|
*/
|
|
34
|
-
export function renamedIdsIn(text) {
|
|
41
|
+
export function renamedIdsIn(renames, text) {
|
|
35
42
|
const places = [];
|
|
36
43
|
const quoted = /(["'`])([^"'`\n]+)\1/g;
|
|
37
44
|
for (const match of text.matchAll(quoted)) {
|
|
38
45
|
const id = match[2];
|
|
39
|
-
const now = id === undefined ? undefined :
|
|
46
|
+
const now = id === undefined ? undefined : renames.get(id);
|
|
40
47
|
if (id === undefined || now === undefined)
|
|
41
48
|
continue;
|
|
42
49
|
const start = match.index + 1;
|
|
@@ -45,4 +52,31 @@ export function renamedIdsIn(text) {
|
|
|
45
52
|
}
|
|
46
53
|
return places;
|
|
47
54
|
}
|
|
55
|
+
/** The line of the first place a text names `id` in quotes, for a notice that says where it is. */
|
|
56
|
+
export function quotedIdLine(text, id) {
|
|
57
|
+
const quoted = /(["'`])([^"'`\n]+)\1/g;
|
|
58
|
+
for (const match of text.matchAll(quoted)) {
|
|
59
|
+
if (match[2] === id)
|
|
60
|
+
return text.slice(0, match.index + 1).split("\n").length;
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
function escaped(text) {
|
|
65
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The 1-based line of `text` where the key `entry` is written after the key `name` (quoted or
|
|
69
|
+
* not): the line of a `facts` entry, `facts: { "@scope/pkg": { JwtGuard: … } }`. Undefined when
|
|
70
|
+
* the text does not write them so.
|
|
71
|
+
*/
|
|
72
|
+
export function keyLine(text, name, entry) {
|
|
73
|
+
const key = (word) => new RegExp(`(?<![\\w$])(["'\`]?)${escaped(word)}\\1\\s*:`, "g");
|
|
74
|
+
const outer = key(name).exec(text);
|
|
75
|
+
if (outer === null)
|
|
76
|
+
return undefined;
|
|
77
|
+
const inner = key(entry);
|
|
78
|
+
inner.lastIndex = outer.index + outer[0].length;
|
|
79
|
+
const found = inner.exec(text);
|
|
80
|
+
return found === null ? undefined : text.slice(0, found.index + 1).split("\n").length;
|
|
81
|
+
}
|
|
48
82
|
//# sourceMappingURL=renamed.js.map
|
package/dist/rollout.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { ruleIds } from "./severity.js";
|
|
4
|
-
import { renamedRule } from "./renamed.js";
|
|
4
|
+
import { removedOf, renamedRule, renamesOf } from "./renamed.js";
|
|
5
5
|
export const ROLLOUT_FILE = "stateward.rollout.json";
|
|
6
6
|
const ROLLOUT_VERSION = 1;
|
|
7
7
|
/**
|
|
@@ -35,7 +35,7 @@ function broken(file, why, fix) {
|
|
|
35
35
|
return new RolloutError(`${path.basename(file)} ${why}; ${fix}`);
|
|
36
36
|
}
|
|
37
37
|
const REPAIR = "fix it, or delete it to start again with `stateward next`";
|
|
38
|
-
function parseEnabled(text, file, known) {
|
|
38
|
+
function parseEnabled(text, file, known, renames, removed) {
|
|
39
39
|
let parsed;
|
|
40
40
|
try {
|
|
41
41
|
parsed = JSON.parse(text);
|
|
@@ -59,8 +59,11 @@ function parseEnabled(text, file, known) {
|
|
|
59
59
|
const seen = new Set();
|
|
60
60
|
const kept = [];
|
|
61
61
|
for (const listed of enabled) {
|
|
62
|
+
// A removed rule turns nothing on; the next write leaves it out.
|
|
63
|
+
if (!known.has(listed) && removed.has(listed))
|
|
64
|
+
continue;
|
|
62
65
|
// A renamed rule is read under its new id; the next write saves that one.
|
|
63
|
-
const id = known.has(listed) ? listed : (renamedRule(listed) ?? listed);
|
|
66
|
+
const id = known.has(listed) ? listed : (renamedRule(renames, listed) ?? listed);
|
|
64
67
|
if (!known.has(id)) {
|
|
65
68
|
throw broken(file, `lists "${id}", which is not a rule of your packs`, `remove "${id}" from its "enabled" list; the other rules stay on`);
|
|
66
69
|
}
|
|
@@ -86,7 +89,7 @@ export function readRollout(config) {
|
|
|
86
89
|
return [];
|
|
87
90
|
throw new RolloutError(`${path.basename(file)} cannot be read (${reasonOf(error)}); fix the file or its permissions, then run again`, { cause: error });
|
|
88
91
|
}
|
|
89
|
-
return parseEnabled(text, file, new Set(ruleIds(config.plugins)));
|
|
92
|
+
return parseEnabled(text, file, new Set(ruleIds(config.plugins)), renamesOf(config.plugins), removedOf(config.plugins));
|
|
90
93
|
}
|
|
91
94
|
/**
|
|
92
95
|
* Saves the rules turned on. Atomic: the text goes to a temp file beside the target, then one
|
package/dist/severity.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Config, ConfigOverride, Plugin, RuleInfo, RuleSetting } from "./types.js";
|
|
2
|
-
type Settings = Pick<Config, "preset" | "addons" | "rules" | "groups"> & Partial<Pick<Config, "overrides" | "configDir">>;
|
|
2
|
+
type Settings = Pick<Config, "preset" | "addons" | "rules" | "groups"> & Partial<Pick<Config, "overrides" | "configDir" | "conventions">>;
|
|
3
3
|
/**
|
|
4
4
|
* What the config says, then each of `applied` in order; the last layer that speaks wins. A
|
|
5
5
|
* default (an override's preset or add-on) does not undo a setting some layer named: a folder
|
package/dist/severity.js
CHANGED
|
@@ -4,11 +4,17 @@ import { matchingOverrides } from "./overrides.js";
|
|
|
4
4
|
* the one below: the preset's tier default, then the add-ons the
|
|
5
5
|
* layer turns on, then `groups`, then `rules` (the last one that speaks wins). The config itself
|
|
6
6
|
* always speaks: an add-on that is not listed is off. An override speaks only about what it names.
|
|
7
|
+
* A convention rule is on only by its id or with `conventions` (the config's): no preset or group
|
|
8
|
+
* alone turns it on. One marked `whenStated` is on like a core rule: it reports only what the
|
|
9
|
+
* project states.
|
|
7
10
|
*/
|
|
8
|
-
function layerSetting(layer, base, pluginName, key, meta) {
|
|
11
|
+
function layerSetting(layer, base, conventions, pluginName, key, meta) {
|
|
9
12
|
const explicit = layer.rules[`${pluginName}/${key}`];
|
|
10
13
|
if (explicit !== undefined)
|
|
11
14
|
return { setting: explicit, named: true };
|
|
15
|
+
if (meta.tier === "convention" && !conventions && meta.whenStated !== true) {
|
|
16
|
+
return base ? { setting: "off", named: false } : undefined;
|
|
17
|
+
}
|
|
12
18
|
const grouped = layer.groups[`${pluginName}/${meta.group}`];
|
|
13
19
|
if (grouped !== undefined)
|
|
14
20
|
return { setting: grouped, named: true };
|
|
@@ -18,6 +24,9 @@ function layerSetting(layer, base, pluginName, key, meta) {
|
|
|
18
24
|
}
|
|
19
25
|
return { setting: heuristicCap(meta.defaultSeverity, meta), named: false };
|
|
20
26
|
}
|
|
27
|
+
if (meta.tier === "convention") {
|
|
28
|
+
return base ? { setting: heuristicCap(meta.defaultSeverity, meta), named: false } : undefined;
|
|
29
|
+
}
|
|
21
30
|
if (layer.preset === undefined)
|
|
22
31
|
return undefined;
|
|
23
32
|
return { setting: heuristicCap(tierSeverity(layer.preset, meta), meta), named: false };
|
|
@@ -32,9 +41,13 @@ function heuristicCap(setting, meta) {
|
|
|
32
41
|
* that is `strict` still keeps the severity you gave a rule for the whole project.
|
|
33
42
|
*/
|
|
34
43
|
export function ruleSettingWith(config, applied, pluginName, key, meta) {
|
|
35
|
-
|
|
44
|
+
const conventions = config.conventions === true;
|
|
45
|
+
let said = layerSetting(config, true, conventions, pluginName, key, meta) ?? {
|
|
46
|
+
setting: "off",
|
|
47
|
+
named: false,
|
|
48
|
+
};
|
|
36
49
|
for (const override of applied) {
|
|
37
|
-
const next = layerSetting(override, false, pluginName, key, meta);
|
|
50
|
+
const next = layerSetting(override, false, conventions, pluginName, key, meta);
|
|
38
51
|
if (next !== undefined && (next.named || !said.named))
|
|
39
52
|
said = next;
|
|
40
53
|
}
|
|
@@ -72,6 +85,7 @@ export function addonsWith(config, applied) {
|
|
|
72
85
|
function tierSeverity(preset, meta) {
|
|
73
86
|
switch (meta.tier) {
|
|
74
87
|
case "core":
|
|
88
|
+
case "convention":
|
|
75
89
|
case "addon":
|
|
76
90
|
return meta.defaultSeverity;
|
|
77
91
|
case "coverage":
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The test files a project's own test runner names, read from its config as data: Jest's
|
|
3
|
+
* `testMatch` and `testRegex` (`jest.config.*`, the `jest` key of `package.json`, or the file a
|
|
4
|
+
* `package.json` script passes to `jest --config`), and Vitest's `test.include`
|
|
5
|
+
* (`vitest.config.*`, `vite.config.*`, or the file a script passes to `vitest --config`). A config
|
|
6
|
+
* file that is code is read where its values are written as literals; a value it computes is not
|
|
7
|
+
* read, and the file is named in `unread` (`stateward coverage` says so), as is a `package.json`
|
|
8
|
+
* whose script gives a config stateward cannot read.
|
|
9
|
+
*/
|
|
10
|
+
export type TestRunnerFiles = {
|
|
11
|
+
/** Whether an absolute file path is a test file by one of the configs read. */
|
|
12
|
+
readonly matches: (file: string) => boolean;
|
|
13
|
+
/** The config files, absolute, that hold test-file settings stateward could not read. */
|
|
14
|
+
readonly unread: readonly string[];
|
|
15
|
+
};
|
|
16
|
+
/** The test files the test-runner configs in each of `dirs` name (see `TestRunnerFiles`). */
|
|
17
|
+
export declare function testRunnerFiles(dirs: readonly string[]): TestRunnerFiles;
|
|
18
|
+
//# sourceMappingURL=test-runner.d.ts.map
|