@shivaedev/quality 0.70.1 → 0.70.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +14 -14
- package/dist/adapters/bundlerEntries.d.ts.map +1 -1
- package/dist/adapters/bundlerEntries.js +16 -2
- package/dist/adapters/bundlerEntries.js.map +1 -1
- package/dist/adapters/bundlerSources.js +2 -2
- package/dist/adapters/bundlerSources.js.map +1 -1
- package/dist/adapters/foreignCallback.d.ts +5 -0
- package/dist/adapters/foreignCallback.d.ts.map +1 -0
- package/dist/adapters/foreignCallback.js +29 -0
- package/dist/adapters/foreignCallback.js.map +1 -0
- package/dist/adapters/foreignResources.d.ts.map +1 -1
- package/dist/adapters/foreignResources.js +9 -34
- package/dist/adapters/foreignResources.js.map +1 -1
- package/dist/adapters/frameworkCallback.d.ts.map +1 -1
- package/dist/adapters/frameworkCallback.js +9 -2
- package/dist/adapters/frameworkCallback.js.map +1 -1
- package/dist/adapters/mappedBuildBindings.d.ts +4 -0
- package/dist/adapters/mappedBuildBindings.d.ts.map +1 -0
- package/dist/adapters/mappedBuildBindings.js +18 -0
- package/dist/adapters/mappedBuildBindings.js.map +1 -0
- package/dist/adapters/nonEmptyContext.d.ts +3 -0
- package/dist/adapters/nonEmptyContext.d.ts.map +1 -0
- package/dist/adapters/nonEmptyContext.js +11 -0
- package/dist/adapters/nonEmptyContext.js.map +1 -0
- package/dist/adapters/outsideImportFindings.d.ts.map +1 -1
- package/dist/adapters/outsideImportFindings.js +1 -0
- package/dist/adapters/outsideImportFindings.js.map +1 -1
- package/dist/adapters/ownedServiceParameters.d.ts +3 -0
- package/dist/adapters/ownedServiceParameters.d.ts.map +1 -0
- package/dist/adapters/ownedServiceParameters.js +24 -0
- package/dist/adapters/ownedServiceParameters.js.map +1 -0
- package/dist/adapters/parameterOrigins.d.ts +3 -0
- package/dist/adapters/parameterOrigins.d.ts.map +1 -0
- package/dist/adapters/parameterOrigins.js +53 -0
- package/dist/adapters/parameterOrigins.js.map +1 -0
- package/dist/baseline/update.d.ts +1 -1
- package/dist/baseline/update.d.ts.map +1 -1
- package/dist/baseline/update.js +4 -7
- package/dist/baseline/update.js.map +1 -1
- package/dist/cli/args.d.ts +0 -2
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +0 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/baseline.d.ts +1 -1
- package/dist/cli/baseline.d.ts.map +1 -1
- package/dist/cli/baseline.js +12 -26
- package/dist/cli/baseline.js.map +1 -1
- package/dist/cli/misplaced.d.ts +0 -7
- package/dist/cli/misplaced.d.ts.map +1 -1
- package/dist/cli/misplaced.js +2 -4
- package/dist/cli/misplaced.js.map +1 -1
- package/dist/cli/program.js +1 -1
- package/dist/cli/program.js.map +1 -1
- package/dist/cli/reportBaselineWrite.d.ts +4 -0
- package/dist/cli/reportBaselineWrite.d.ts.map +1 -0
- package/dist/cli/reportBaselineWrite.js +19 -0
- package/dist/cli/reportBaselineWrite.js.map +1 -0
- package/dist/cli/usage.d.ts +1 -1
- package/dist/cli/usage.d.ts.map +1 -1
- package/dist/cli/usage.js +3 -3
- package/dist/rules/effect/adapterImports.js +1 -1
- package/dist/rules/effect/adapterImports.js.map +1 -1
- package/dist/rules/effect/serviceFindings.d.ts.map +1 -1
- package/dist/rules/effect/serviceFindings.js +3 -0
- package/dist/rules/effect/serviceFindings.js.map +1 -1
- package/dist/rules/effect/serviceParameters.js +1 -1
- package/dist/rules/effect/serviceParameters.js.map +1 -1
- package/dist/rules/effect/serviceTypes.d.ts.map +1 -1
- package/dist/rules/effect/serviceTypes.js +12 -8
- package/dist/rules/effect/serviceTypes.js.map +1 -1
- package/docs/debt-and-hooks.md +5 -7
- package/package.json +1 -1
- package/src/adapters/bundlerEntries.ts +17 -2
- package/src/adapters/bundlerSources.ts +2 -2
- package/src/adapters/foreignCallback.ts +35 -0
- package/src/adapters/foreignResources.ts +11 -35
- package/src/adapters/frameworkCallback.ts +10 -2
- package/src/adapters/mappedBuildBindings.ts +18 -0
- package/src/adapters/nonEmptyContext.ts +11 -0
- package/src/adapters/outsideImportFindings.ts +1 -0
- package/src/adapters/ownedServiceParameters.ts +25 -0
- package/src/adapters/parameterOrigins.ts +60 -0
- package/src/baseline/update.ts +3 -9
- package/src/cli/args.ts +0 -4
- package/src/cli/baseline.ts +10 -28
- package/src/cli/misplaced.ts +2 -4
- package/src/cli/program.ts +1 -1
- package/src/cli/reportBaselineWrite.ts +26 -0
- package/src/cli/usage.ts +3 -3
- package/src/rules/effect/adapterImports.ts +1 -1
- package/src/rules/effect/serviceFindings.ts +3 -0
- package/src/rules/effect/serviceParameters.ts +1 -1
- package/src/rules/effect/serviceTypes.ts +14 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceParameters.js","sourceRoot":"","sources":["../../../src/rules/effect/serviceParameters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAmB,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,EAAE,MAAkB;QAC/D,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,iBAAi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OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACtC,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBACnE,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC;YACH,OAAO,eAAe,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;QAChG,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC;IACF,WAAW,EACV,6wBAA6wB;IAC9wB,EAAE,EAAE,2BAA2B;IAC/B,WAAW,EAAE,KAAK;CAClB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceTypes.d.ts","sourceRoot":"","sources":["../../../src/rules/effect/serviceTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"serviceTypes.d.ts","sourceRoot":"","sources":["../../../src/rules/effect/serviceTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAQ5B,wBAAgB,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,EAAE,gBAAgB,UAAQ;oBA2H5D,EAAE,CAAC,IAAI;wBA9EG,EAAE,CAAC,IAAI,KAAG,OAAO;2BAcd,EAAE,CAAC,IAAI,KAAG,OAAO;qBAvCvB,EAAE,CAAC,IAAI,SAAS,MAAM,KAAG,IAAI;EAoHrD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { browserLibraryType } from "#adapters/browserLibraryType.ts";
|
|
3
3
|
import { callerContextData } from "#adapters/callerContextData.ts";
|
|
4
|
+
import { nonEmptyContext } from "#adapters/nonEmptyContext.ts";
|
|
4
5
|
const SERVICE = "~effect/Context/Service";
|
|
5
6
|
const CONTEXT = "~effect/Context";
|
|
6
7
|
export function serviceTypes(checker, initializerState = false) {
|
|
@@ -59,14 +60,16 @@ export function serviceTypes(checker, initializerState = false) {
|
|
|
59
60
|
const contextual = declaration !== undefined && ts.isObjectLiteralExpression(declaration) ? checker.getContextualType(declaration) : undefined;
|
|
60
61
|
return contextual !== undefined && shapes.has(contextual);
|
|
61
62
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (parameter === undefined) {
|
|
66
|
-
return false;
|
|
63
|
+
function serviceReturn(type) {
|
|
64
|
+
if (type.isUnionOrIntersection()) {
|
|
65
|
+
return type.types.some(serviceReturn);
|
|
67
66
|
}
|
|
68
|
-
const
|
|
69
|
-
return
|
|
67
|
+
const context = propertyType(type, CONTEXT);
|
|
68
|
+
return (type.getProperty(SERVICE) !== undefined
|
|
69
|
+
|| (!computation(type) && (implementation(type) || (context !== undefined && nonEmptyContext(checker, context)))));
|
|
70
|
+
}
|
|
71
|
+
function factoryService(type) {
|
|
72
|
+
return !initializerState && type.getCallSignatures().some((signature) => serviceReturn(signature.getReturnType()));
|
|
70
73
|
}
|
|
71
74
|
function carries(type, seen = new Set()) {
|
|
72
75
|
if (seen.has(type)
|
|
@@ -92,7 +95,7 @@ export function serviceTypes(checker, initializerState = false) {
|
|
|
92
95
|
}
|
|
93
96
|
const context = propertyType(type, CONTEXT);
|
|
94
97
|
if (context !== undefined) {
|
|
95
|
-
return nonEmptyContext(context);
|
|
98
|
+
return nonEmptyContext(checker, context);
|
|
96
99
|
}
|
|
97
100
|
if (computation(type)) {
|
|
98
101
|
return false;
|
|
@@ -102,6 +105,7 @@ export function serviceTypes(checker, initializerState = false) {
|
|
|
102
105
|
return true;
|
|
103
106
|
}
|
|
104
107
|
return (implementation(type)
|
|
108
|
+
|| factoryService(type)
|
|
105
109
|
|| checker.getIndexInfosOfType(type).some((index) => carries(index.type, seen))
|
|
106
110
|
|| type.getProperties().some((property) => !(property.flags & ts.SymbolFlags.Method) && carries(checker.getTypeOfSymbol(property), seen)));
|
|
107
111
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceTypes.js","sourceRoot":"","sources":["../../../src/rules/effect/serviceTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"serviceTypes.js","sourceRoot":"","sources":["../../../src/rules/effect/serviceTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,MAAM,OAAO,GAAG,yBAAyB,CAAC;AAC1C,MAAM,OAAO,GAAG,iBAAiB,CAAC;AAElC,MAAM,UAAU,YAAY,CAAC,OAAuB,EAAE,gBAAgB,GAAG,KAAK;IAC7E,MAAM,MAAM,GAAG,IAAI,GAAG,EAAW,CAAC;IAClC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAW,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC5C,SAAS,YAAY,CAAC,IAAa,EAAE,IAAY;QAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACxC,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC/E,CAAC;IACD,SAAS,OAAO,CAAC,IAA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AC,IAAI,EAAE,IAAI,CAAC,CAAC;eAC5E,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,CACzI,CAAC;IACH,CAAC;IACD,OAAO;QACN,OAAO,EAAE,CAAC,IAAa,EAAE,EAAE;YAC1B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC;YACd,CAAC;YACD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC1B,OAAO,MAAM,CAAC;QACf,CAAC;QACD,WAAW;QACX,cAAc;QACd,QAAQ;KACR,CAAC;AACH,CAAC"}
|
package/docs/debt-and-hooks.md
CHANGED
|
@@ -4,7 +4,9 @@ The [README](../README.md) introduces the gate. This page explains how the basel
|
|
|
4
4
|
|
|
5
5
|
## Baseline
|
|
6
6
|
|
|
7
|
-
`quality baseline write
|
|
7
|
+
`quality baseline write` records every current finding, including findings in unchanged files after a policy upgrade. Repeat `--rule <id>` to record only named rules or rule families; unrelated entries stay unchanged. Writing is a deliberate step: commit checks and CI still reject findings the baseline does not cover.
|
|
8
|
+
|
|
9
|
+
After every write, the output asks you to fix every finding you can fix instead of recording it. It names the recorded rules and counts, marking rules absent from the previous baseline as new. For each recorded case of those new rules, judge whether the rule reads the code correctly. Report any misread to Platform with the file, lines and what Quality would need instead of leaving it as debt. Run `quality baseline tighten` after repairs.
|
|
8
10
|
|
|
9
11
|
```jsonl
|
|
10
12
|
{"path":"src/legacy/sync.ts","rule":"comments/no-jsdoc","count":3}
|
|
@@ -14,7 +16,7 @@ The [README](../README.md) introduces the gate. This page explains how the basel
|
|
|
14
16
|
The baseline is sharded: `packages/<package>/quality-baseline.jsonl` holds paths inside that package, and the root `quality-baseline.jsonl` holds all other paths. Packages without entries have no file. Each shard is JSON Lines with one entry per line: the violations of one rule in one file. `count` is how many violations the file may have. For a rule that counts occurrences, such as `comments/no-jsdoc`, that is the number of occurrences. For a rule with a limit, it is the amount over the limit: the entry above lets `src/server/db.ts` have 412 lines under a limit of 150. A new baseline is sorted by path and then rule. Later edits preserve unrelated lines, including their formatting and order, so the diff shows the entries that changed.
|
|
15
17
|
|
|
16
18
|
`quality lint` fails when a baselined file has more violations than its `count`; the report then lists all of that file's violations for the rule. A file at or below its entry passes. An entry that allows more than is left, including a file with no violations left, is listed as a note and does not fail, so fixing debt never breaks the build; `tighten` and `prune` lower it. An entry for an unknown rule fails until it is pruned.
|
|
17
|
-
- `quality baseline write`
|
|
19
|
+
- `quality baseline write` replaces the baseline with every current finding. With `--rule <id>`, only the named rules are replaced; repeat the option to select several rules.
|
|
18
20
|
- `quality baseline tighten` lowers and removes the entries of files changed since `HEAD`, and with `--staged`, of the files staged for the next commit. It carries the entry of a file that git sees as moved to the new path. Every other line stays byte for byte.
|
|
19
21
|
- `quality baseline prune` does the same for every entry. It carries the entries of files moved since the merge base (see `--against` under [Command line](../README.md#command-line)), and prunes without following moves outside a git work tree.
|
|
20
22
|
- `quality baseline migrate` moves a baseline from the earlier JSON format, `quality/baseline.json` or the file `--from` names, to the root and package shards, and removes the old one. `--from quality/baseline.jsonl` splits a single JSON Lines baseline without changing its counts. An old entry that stored a size, such as a line count, becomes that size less the rule's current limit; an entry whose file is now within the limit is dropped.
|
|
@@ -35,13 +37,9 @@ quality lint
|
|
|
35
37
|
|
|
36
38
|
`tighten` counts the files as they are on disk. When a commit stages only part of a file, stash the rest first (as lint-staged does), or the entry may be lowered below what the commit holds.
|
|
37
39
|
|
|
38
|
-
### Baseline growth
|
|
39
|
-
|
|
40
|
-
An error-level finding that neither the config exceptions nor the baseline covers fails `quality lint`; that is how new debt gets noticed. The baseline itself may grow: a reviewer sees each new or raised entry in the diff and judges it. For moved files, run `quality baseline prune --against <base>` to carry existing counts to the new paths. The failing report ends with that guidance. For retained findings in a changed file, use `quality baseline write --rule <id> --file <path>` and call out new or raised counts in the pull request. Writing a rule does not absorb findings from other files.
|
|
41
|
-
|
|
42
40
|
### Counts after a policy change
|
|
43
41
|
|
|
44
|
-
A count depends on the rule's limit, so a Quality policy change that adjusts a limit shifts every count of that rule. A looser limit leaves entries that allow more than is left: they pass, and `tighten` and `prune` lower them. A stricter limit can make an error-level rule's files fail `quality lint`, since each is now further over the limit. Inspect the findings under the new policy before recording retained debt again with `quality baseline write
|
|
42
|
+
A count depends on the rule's limit, so a Quality policy change that adjusts a limit shifts every count of that rule. A looser limit leaves entries that allow more than is left: they pass, and `tighten` and `prune` lower them. A stricter limit can make an error-level rule's files fail `quality lint`, since each is now further over the limit. Inspect the findings under the new policy before recording retained debt again with `quality baseline write`. Commit the counts with the policy upgrade. Review the recorded cases using the guidance printed after the write.
|
|
45
43
|
|
|
46
44
|
## Exceptions
|
|
47
45
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/quality",
|
|
3
|
-
"version": "0.70.
|
|
3
|
+
"version": "0.70.3",
|
|
4
4
|
"description": "Repository quality gate with typed rules, a baseline of existing debt and a registry of reasoned exceptions",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/quality#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -4,6 +4,7 @@ import { buildEntryPaths } from "#adapters/buildEntryPaths.ts";
|
|
|
4
4
|
import { type BuildBindings, buildEntryValue, buildOption } from "#adapters/buildEntryValue.ts";
|
|
5
5
|
import { buildArguments, buildHelper } from "#adapters/buildHelper.ts";
|
|
6
6
|
import { importedCall } from "#adapters/importedCall.ts";
|
|
7
|
+
import { mappedBuildBindings } from "#adapters/mappedBuildBindings.ts";
|
|
7
8
|
import type { SourceFile } from "#rule.ts";
|
|
8
9
|
import { parse } from "#rules/parse.ts";
|
|
9
10
|
|
|
@@ -21,6 +22,9 @@ function entryOption(call: ts.CallExpression): string | undefined {
|
|
|
21
22
|
return "entrypoints";
|
|
22
23
|
}
|
|
23
24
|
const imported = importedCall(call);
|
|
25
|
+
if (imported?.module === "rolldown" && ["build", "watch"].includes(imported.name)) {
|
|
26
|
+
return "input";
|
|
27
|
+
}
|
|
24
28
|
return imported?.module === "esbuild" && ESBUILD.has(imported.name) ? "entryPoints" : undefined;
|
|
25
29
|
}
|
|
26
30
|
|
|
@@ -28,7 +32,16 @@ function entriesOf(call: ts.CallExpression, file: string, cwd: string, bindings:
|
|
|
28
32
|
const option = entryOption(call);
|
|
29
33
|
const [argument] = call.arguments;
|
|
30
34
|
const options = argument === undefined ? undefined : buildEntryValue(argument, new Set(), bindings);
|
|
31
|
-
if (option === undefined || options === undefined
|
|
35
|
+
if (option === undefined || options === undefined) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
const configs = option === "input" && ts.isArrayLiteralExpression(options) ? options.elements : [options];
|
|
39
|
+
return configs.flatMap((config) => configuredEntries(config, option, file, cwd, bindings));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function configuredEntries(value: ts.Expression, option: string, file: string, cwd: string, bindings: BuildBindings): readonly string[] {
|
|
43
|
+
const options = buildEntryValue(value, new Set(), bindings);
|
|
44
|
+
if (!ts.isObjectLiteralExpression(options)) {
|
|
32
45
|
return [];
|
|
33
46
|
}
|
|
34
47
|
const directory = buildOption(options, "absWorkingDir");
|
|
@@ -55,7 +68,9 @@ export function bundlerEntries(
|
|
|
55
68
|
if (ts.isFunctionLike(node)) {
|
|
56
69
|
const body = callbackBody(node);
|
|
57
70
|
if (body !== undefined) {
|
|
58
|
-
|
|
71
|
+
for (const mapped of mappedBuildBindings(node, bindings)) {
|
|
72
|
+
visit(body, mapped, active);
|
|
73
|
+
}
|
|
59
74
|
}
|
|
60
75
|
return;
|
|
61
76
|
}
|
|
@@ -5,7 +5,7 @@ import { parse } from "#rules/parse.ts";
|
|
|
5
5
|
|
|
6
6
|
function usesBundler(source: ts.SourceFile): boolean {
|
|
7
7
|
function visit(node: ts.Node): boolean {
|
|
8
|
-
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text
|
|
8
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier) && ["esbuild", "rolldown"].includes(node.moduleSpecifier.text)) {
|
|
9
9
|
return true;
|
|
10
10
|
}
|
|
11
11
|
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "Bun" && node.name.text === "build") {
|
|
@@ -19,7 +19,7 @@ function usesBundler(source: ts.SourceFile): boolean {
|
|
|
19
19
|
function directSources(files: readonly SourceFile[]): Map<string, ts.SourceFile> {
|
|
20
20
|
const sources = new Map<string, ts.SourceFile>();
|
|
21
21
|
for (const file of files) {
|
|
22
|
-
if (!(file.text.includes("esbuild") || file.text.includes("Bun"))) {
|
|
22
|
+
if (!(file.text.includes("esbuild") || file.text.includes("rolldown") || file.text.includes("Bun"))) {
|
|
23
23
|
continue;
|
|
24
24
|
}
|
|
25
25
|
const source = parse(file);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export function foreignDeclaration(node: ts.Declaration): boolean {
|
|
4
|
+
const file = node.getSourceFile().fileName.replaceAll("\\", "/");
|
|
5
|
+
return file.includes("/node_modules/") && !/\/(?:effect|@effect|@shivaedev)\//u.test(file);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function contextualCallbackType(checker: ts.TypeChecker, node: ts.Node): ts.Type | undefined {
|
|
9
|
+
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
10
|
+
return checker.getContextualType(node);
|
|
11
|
+
}
|
|
12
|
+
if (ts.isMethodDeclaration(node) && ts.isObjectLiteralExpression(node.parent)) {
|
|
13
|
+
const object = checker.getContextualType(node.parent);
|
|
14
|
+
const property = object?.getProperty(node.name.getText().replace(/^["']|["']$/gu, ""));
|
|
15
|
+
return property === undefined ? undefined : checker.getTypeOfSymbol(property);
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function foreignCallbackParameter(checker: ts.TypeChecker, parameter: ts.ParameterDeclaration): boolean {
|
|
21
|
+
const fn = parameter.parent;
|
|
22
|
+
const context = contextualCallbackType(checker, fn);
|
|
23
|
+
if (
|
|
24
|
+
(context === undefined ? [] : checker.getNonNullableType(context).getCallSignatures()).some(
|
|
25
|
+
(signature) => signature.declaration !== undefined && foreignDeclaration(signature.declaration),
|
|
26
|
+
)
|
|
27
|
+
) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (!((ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)) && ts.isCallExpression(fn.parent) && fn.parent.arguments.includes(fn))) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const owner = checker.getResolvedSignature(fn.parent);
|
|
34
|
+
return owner?.declaration !== undefined && foreignDeclaration(owner.declaration);
|
|
35
|
+
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
import { foreignCallbackParameter, foreignDeclaration } from "#adapters/foreignCallback.ts";
|
|
3
|
+
import { parameterOrigins } from "#adapters/parameterOrigins.ts";
|
|
2
4
|
import { serviceProperty } from "#adapters/serviceAssemblySyntax.ts";
|
|
3
5
|
import { effectApi, resolvedValue } from "#adapters/serviceModelSyntax.ts";
|
|
4
6
|
import { returnValues } from "#rules/stories/returnValues.ts";
|
|
5
7
|
|
|
6
|
-
function foreign(node: ts.Declaration): boolean {
|
|
7
|
-
const file = node.getSourceFile().fileName.replaceAll("\\", "/");
|
|
8
|
-
return file.includes("/node_modules/") && !/\/(?:effect|@effect|@shivaedev)\//u.test(file);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
8
|
function constructed(checker: ts.TypeChecker, node: ts.Node, seen = new Set<ts.Node>()): boolean {
|
|
12
9
|
if (seen.has(node)) {
|
|
13
10
|
return false;
|
|
@@ -30,7 +27,7 @@ function constructed(checker: ts.TypeChecker, node: ts.Node, seen = new Set<ts.N
|
|
|
30
27
|
|
|
31
28
|
function acquisition(checker: ts.TypeChecker, node: ts.CallExpression | ts.NewExpression, seen: Set<ts.Node>): boolean {
|
|
32
29
|
const signature = checker.getResolvedSignature(node);
|
|
33
|
-
if (signature?.declaration !== undefined &&
|
|
30
|
+
if (signature?.declaration !== undefined && foreignDeclaration(signature.declaration)) {
|
|
34
31
|
return true;
|
|
35
32
|
}
|
|
36
33
|
if (ts.isCallExpression(node)) {
|
|
@@ -48,42 +45,21 @@ function acquisition(checker: ts.TypeChecker, node: ts.CallExpression | ts.NewEx
|
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
export function foreignResources(checker: ts.TypeChecker, sources: readonly ts.SourceFile[]) {
|
|
51
|
-
|
|
52
|
-
function argumentsIn() {
|
|
53
|
-
if (calls !== undefined) {
|
|
54
|
-
return calls;
|
|
55
|
-
}
|
|
56
|
-
const arguments_ = new Map<ts.ParameterDeclaration, ts.Expression[]>();
|
|
57
|
-
function visit(node: ts.Node): void {
|
|
58
|
-
if (ts.isCallExpression(node)) {
|
|
59
|
-
const declaration = checker.getResolvedSignature(node)?.declaration;
|
|
60
|
-
for (const [index, parameter] of (declaration?.parameters ?? []).entries()) {
|
|
61
|
-
const argument = node.arguments[index];
|
|
62
|
-
if (argument !== undefined && ts.isParameter(parameter)) {
|
|
63
|
-
const values = arguments_.get(parameter) ?? [];
|
|
64
|
-
values.push(argument);
|
|
65
|
-
arguments_.set(parameter, values);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
ts.forEachChild(node, visit);
|
|
70
|
-
}
|
|
71
|
-
for (const source of sources) {
|
|
72
|
-
visit(source);
|
|
73
|
-
}
|
|
74
|
-
calls = arguments_;
|
|
75
|
-
return arguments_;
|
|
76
|
-
}
|
|
48
|
+
const originates = parameterOrigins(checker, sources);
|
|
77
49
|
return (parameter: ts.ParameterDeclaration): boolean => {
|
|
78
50
|
const source = parameter.getSourceFile();
|
|
79
51
|
if (!/(?:^|\/)adapters\//u.test(source.fileName)) {
|
|
80
52
|
return false;
|
|
81
53
|
}
|
|
82
54
|
const type = checker.getTypeAtLocation(parameter);
|
|
83
|
-
if (!(type.getSymbol()?.declarations ?? []).some(
|
|
55
|
+
if (!(type.getSymbol()?.declarations ?? []).some(foreignDeclaration) || type.getProperty("~effect/Context/Service") !== undefined) {
|
|
84
56
|
return false;
|
|
85
57
|
}
|
|
86
|
-
|
|
87
|
-
|
|
58
|
+
return originates(parameter, (value) => {
|
|
59
|
+
const declaration = ts.isIdentifier(value) ? checker.getSymbolAtLocation(value)?.valueDeclaration : value;
|
|
60
|
+
return (
|
|
61
|
+
(declaration !== undefined && ts.isParameter(declaration) && foreignCallbackParameter(checker, declaration)) || constructed(checker, value)
|
|
62
|
+
);
|
|
63
|
+
});
|
|
88
64
|
};
|
|
89
65
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { callbackEscapes } from "#adapters/callbackEscapes.ts";
|
|
3
|
+
import { contextualCallbackType } from "#adapters/foreignCallback.ts";
|
|
3
4
|
import { frameworkOwner } from "#adapters/frameworkOwner.ts";
|
|
4
5
|
import { effectApi, resolvedValue } from "#adapters/serviceModelSyntax.ts";
|
|
5
6
|
|
|
@@ -20,11 +21,19 @@ function wrapsEffectFunction(checker: ts.TypeChecker, expression: ts.Expression)
|
|
|
20
21
|
return effectApi(checker, callee, "fn") || effectApi(checker, callee, "fnUntraced");
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
function suppliedCallback(checker: ts.TypeChecker, node: ts.Node, local: ReadonlySet<ts.SourceFile>): boolean {
|
|
25
|
+
const contextual = contextualCallbackType(checker, node);
|
|
26
|
+
return (contextual === undefined ? [] : checker.getNonNullableType(contextual).getCallSignatures()).some((signature) => supplied(signature, local));
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
export function frameworkCallback(checker: ts.TypeChecker, node: ts.Node, local: ReadonlySet<ts.SourceFile>, seen = new Set<ts.Node>()): boolean {
|
|
24
30
|
if (seen.has(node)) {
|
|
25
31
|
return false;
|
|
26
32
|
}
|
|
27
33
|
seen.add(node);
|
|
34
|
+
if (ts.isMethodDeclaration(node) && suppliedCallback(checker, node, local)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
28
37
|
if (!(ts.isArrowFunction(node) || ts.isFunctionExpression(node))) {
|
|
29
38
|
return false;
|
|
30
39
|
}
|
|
@@ -44,8 +53,7 @@ export function frameworkCallback(checker: ts.TypeChecker, node: ts.Node, local:
|
|
|
44
53
|
}
|
|
45
54
|
return !callbackEscapes(checker, node.parent, node);
|
|
46
55
|
}
|
|
47
|
-
|
|
48
|
-
if ((contextual === undefined ? [] : checker.getNonNullableType(contextual).getCallSignatures()).some((signature) => supplied(signature, local))) {
|
|
56
|
+
if (suppliedCallback(checker, node, local)) {
|
|
49
57
|
return true;
|
|
50
58
|
}
|
|
51
59
|
const property = node.parent;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { type BuildBindings, buildEntryValue } from "#adapters/buildEntryValue.ts";
|
|
3
|
+
|
|
4
|
+
export function mappedBuildBindings(node: ts.Node, bindings: BuildBindings): readonly BuildBindings[] {
|
|
5
|
+
if (!((ts.isArrowFunction(node) || ts.isFunctionExpression(node)) && ts.isCallExpression(node.parent))) {
|
|
6
|
+
return [bindings];
|
|
7
|
+
}
|
|
8
|
+
const callee = node.parent.expression;
|
|
9
|
+
const parameter = node.parameters[0];
|
|
10
|
+
if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== "map" || parameter === undefined) {
|
|
11
|
+
return [bindings];
|
|
12
|
+
}
|
|
13
|
+
const array = buildEntryValue(callee.expression, new Set(), bindings);
|
|
14
|
+
if (!ts.isArrayLiteralExpression(array)) {
|
|
15
|
+
return [bindings];
|
|
16
|
+
}
|
|
17
|
+
return array.elements.map((element) => new Map([...bindings, [parameter, buildEntryValue(element, new Set(), bindings)]]));
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export function nonEmptyContext(checker: ts.TypeChecker, context: ts.Type): boolean {
|
|
4
|
+
const variance = context.getProperty("_Services");
|
|
5
|
+
const parameter = variance === undefined ? undefined : checker.getTypeOfSymbol(variance).getCallSignatures()[0]?.parameters[0];
|
|
6
|
+
if (parameter === undefined) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const required = checker.getTypeOfSymbol(parameter);
|
|
10
|
+
return !((checker.getBaseConstraintOfType(required) ?? required).flags & ts.TypeFlags.Never);
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { parameterOrigins } from "#adapters/parameterOrigins.ts";
|
|
3
|
+
import { serviceAssemblyImports } from "#adapters/serviceAssemblyImports.ts";
|
|
4
|
+
import { directServiceDefinitions, serviceProperty } from "#adapters/serviceAssemblySyntax.ts";
|
|
5
|
+
|
|
6
|
+
export function ownedServiceParameters(checker: ts.TypeChecker, sources: readonly ts.SourceFile[]) {
|
|
7
|
+
const states = new Set<ts.Node>();
|
|
8
|
+
for (const source of sources) {
|
|
9
|
+
for (const definition of directServiceDefinitions(source, serviceAssemblyImports(source).definitions)) {
|
|
10
|
+
const config = definition.arguments[0];
|
|
11
|
+
const methods = config !== undefined && ts.isObjectLiteralExpression(config) ? serviceProperty(config, "methods") : undefined;
|
|
12
|
+
const state = methods !== undefined && ts.isArrowFunction(methods) ? methods.parameters[0] : undefined;
|
|
13
|
+
if (state !== undefined) {
|
|
14
|
+
states.add(state);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const originates = parameterOrigins(checker, sources);
|
|
19
|
+
return (parameter: ts.ParameterDeclaration): boolean =>
|
|
20
|
+
states.size > 0
|
|
21
|
+
&& originates(parameter, (value) => {
|
|
22
|
+
const declaration = ts.isIdentifier(value) ? checker.getSymbolAtLocation(value)?.valueDeclaration : value;
|
|
23
|
+
return declaration !== undefined && states.has(declaration);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { resolvedValue } from "#adapters/serviceModelSyntax.ts";
|
|
3
|
+
|
|
4
|
+
export function parameterOrigins(checker: ts.TypeChecker, sources: readonly ts.SourceFile[]) {
|
|
5
|
+
let calls: Map<ts.ParameterDeclaration, (ts.Expression | undefined)[]> | undefined;
|
|
6
|
+
function argumentsIn() {
|
|
7
|
+
if (calls !== undefined) {
|
|
8
|
+
return calls;
|
|
9
|
+
}
|
|
10
|
+
const arguments_ = new Map<ts.ParameterDeclaration, (ts.Expression | undefined)[]>();
|
|
11
|
+
function visit(node: ts.Node): void {
|
|
12
|
+
if (ts.isCallExpression(node)) {
|
|
13
|
+
const declaration = checker.getResolvedSignature(node)?.declaration;
|
|
14
|
+
for (const [index, parameter] of (declaration?.parameters ?? []).entries()) {
|
|
15
|
+
const argument = node.arguments[index];
|
|
16
|
+
if (ts.isParameter(parameter)) {
|
|
17
|
+
const values = arguments_.get(parameter) ?? [];
|
|
18
|
+
values.push(argument);
|
|
19
|
+
arguments_.set(parameter, values);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
ts.forEachChild(node, visit);
|
|
24
|
+
}
|
|
25
|
+
for (const source of sources) {
|
|
26
|
+
visit(source);
|
|
27
|
+
}
|
|
28
|
+
calls = arguments_;
|
|
29
|
+
return arguments_;
|
|
30
|
+
}
|
|
31
|
+
return (parameter: ts.ParameterDeclaration, accepts: (value: ts.Node) => boolean): boolean => originates(checker, parameter, accepts, argumentsIn);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function originates(
|
|
35
|
+
checker: ts.TypeChecker,
|
|
36
|
+
node: ts.Node,
|
|
37
|
+
accepts: (value: ts.Node) => boolean,
|
|
38
|
+
argumentsIn: () => ReadonlyMap<ts.ParameterDeclaration, readonly (ts.Expression | undefined)[]>,
|
|
39
|
+
seen: ReadonlySet<ts.Node> = new Set(),
|
|
40
|
+
): boolean {
|
|
41
|
+
if (seen.has(node)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (accepts(node)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
const visited = new Set([...seen, node]);
|
|
48
|
+
if (ts.isExpression(node)) {
|
|
49
|
+
const value = resolvedValue(checker, node);
|
|
50
|
+
if (value !== node) {
|
|
51
|
+
return originates(checker, value, accepts, argumentsIn, visited);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const declared = ts.isIdentifier(node) ? checker.getSymbolAtLocation(node)?.valueDeclaration : node;
|
|
55
|
+
if (declared === undefined || !ts.isParameter(declared)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const values = argumentsIn().get(declared) ?? [];
|
|
59
|
+
return values.length > 0 && values.every((value) => value !== undefined && originates(checker, value, accepts, argumentsIn, visited));
|
|
60
|
+
}
|
package/src/baseline/update.ts
CHANGED
|
@@ -37,22 +37,16 @@ export function adopt(
|
|
|
37
37
|
rules: readonly string[],
|
|
38
38
|
violations: readonly Violation[],
|
|
39
39
|
index: RuleIndex,
|
|
40
|
-
files?: ReadonlySet<string>,
|
|
41
40
|
): Adoption {
|
|
42
|
-
if (existing !== undefined && rules.length === 0) {
|
|
43
|
-
return { _tag: "Refused", reasons: ["a baseline exists. Record a rule with --rule <id>, or drop fixed debt with prune."] };
|
|
44
|
-
}
|
|
45
41
|
const reasons = rules.flatMap((id) => refusal(id, index));
|
|
46
42
|
if (reasons.length > 0) {
|
|
47
43
|
return { _tag: "Refused", reasons };
|
|
48
44
|
}
|
|
49
45
|
function named(rule: string): boolean {
|
|
50
|
-
return rules.some((name) => covers(name, rule));
|
|
46
|
+
return rules.length === 0 || rules.some((name) => covers(name, rule));
|
|
51
47
|
}
|
|
52
|
-
const kept = (existing ?? []).filter((entry) => !
|
|
53
|
-
const adopted = violations.filter(
|
|
54
|
-
(violation) => (rules.length === 0 || named(violation.rule)) && (files === undefined || files.has(violation.file)),
|
|
55
|
-
);
|
|
48
|
+
const kept = (existing ?? []).filter((entry) => !named(entry.rule));
|
|
49
|
+
const adopted = violations.filter((violation) => named(violation.rule));
|
|
56
50
|
const added = record(adopted);
|
|
57
51
|
return { _tag: "Adopted", added: added.length, entries: [...kept, ...added], replaced: (existing ?? []).length - kept.length };
|
|
58
52
|
}
|
package/src/cli/args.ts
CHANGED
|
@@ -15,8 +15,6 @@ export type Command =
|
|
|
15
15
|
readonly _tag: "BaselineWrite";
|
|
16
16
|
readonly config: string | undefined;
|
|
17
17
|
readonly rules: readonly string[];
|
|
18
|
-
readonly files: readonly string[];
|
|
19
|
-
readonly firstAdoption: boolean;
|
|
20
18
|
}
|
|
21
19
|
| { readonly _tag: "BaselinePrune"; readonly config: string | undefined; readonly against: string | undefined }
|
|
22
20
|
| { readonly _tag: "BaselineTighten"; readonly config: string | undefined; readonly staged: boolean }
|
|
@@ -60,8 +58,6 @@ function commandFor(name: string, values: Values): Parsed {
|
|
|
60
58
|
return parsed({
|
|
61
59
|
_tag: "BaselineWrite",
|
|
62
60
|
config,
|
|
63
|
-
files: values.file ?? [],
|
|
64
|
-
firstAdoption: values["first-adoption"] === true,
|
|
65
61
|
rules: values.rule ?? [],
|
|
66
62
|
});
|
|
67
63
|
case "baseline prune":
|
package/src/cli/baseline.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Console, Effect, type FileSystem, Path } from "effect";
|
|
1
|
+
import { Console, Effect, type FileSystem } from "effect";
|
|
3
2
|
import type { BaselineEntry } from "#baseline/format.ts";
|
|
4
3
|
import { saveShards } from "#baseline/shards.ts";
|
|
5
4
|
import { adopt, type Pruned, prune, type Scope } from "#baseline/update.ts";
|
|
5
|
+
import { reportBaselineWrite } from "#cli/reportBaselineWrite.ts";
|
|
6
6
|
import { openSession, type Session } from "#engine/session.ts";
|
|
7
7
|
import { applyRegistry } from "#exceptions/registry.ts";
|
|
8
8
|
import { SetupFailure } from "#failure.ts";
|
|
9
|
-
import { changesSince } from "#git/history.ts";
|
|
10
9
|
import { plural } from "#report/plural.ts";
|
|
11
10
|
import type { RuleServices } from "#rule.ts";
|
|
12
11
|
|
|
@@ -22,38 +21,21 @@ export const writeBaseline = Effect.fn("Cli.writeBaseline")(function* (
|
|
|
22
21
|
cwd: string,
|
|
23
22
|
config: string | undefined,
|
|
24
23
|
rules: readonly string[],
|
|
25
|
-
files: readonly string[],
|
|
26
|
-
firstAdoption = false,
|
|
27
24
|
): Effect.fn.Return<void, SetupFailure, RuleServices> {
|
|
28
|
-
const { relative, resolve } = yield* Path.Path.pipe(Effect.provide(NodePath.layer));
|
|
29
|
-
|
|
30
25
|
const session = yield* openSession(cwd, config);
|
|
31
|
-
const existing = session.baseline.
|
|
32
|
-
|
|
33
|
-
return yield* new SetupFailure({
|
|
34
|
-
message: "baseline write refused: a baseline exists. Record a rule with --rule <id> and --file <path>; use prune for moved or fixed debt.",
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
const selected = files.length === 0 ? undefined : new Set(files.map((file) => relative(session.config.root, resolve(session.config.root, file))));
|
|
38
|
-
if (selected !== undefined && !firstAdoption) {
|
|
39
|
-
const changed = yield* changesSince(session.config.root, ["HEAD"]);
|
|
40
|
-
const outside = [...selected].filter((file) => !changed.files.has(file));
|
|
41
|
-
if (outside.length > 0) {
|
|
42
|
-
return yield* new SetupFailure({
|
|
43
|
-
message: `baseline write refused: outside the current change set: ${outside.join(", ")}. Stage new files with git add first.`,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const adoption = adopt(existing, rules, unregistered(session), session.config, selected);
|
|
26
|
+
const existing = session.baseline.entries;
|
|
27
|
+
const adoption = adopt(existing, rules, unregistered(session), session.config);
|
|
48
28
|
if (adoption._tag === "Refused") {
|
|
49
29
|
return yield* new SetupFailure({ message: `baseline write refused:\n${adoption.reasons.map((reason) => ` - ${reason}`).join("\n")}` });
|
|
50
30
|
}
|
|
51
31
|
if (adoption.added === 0 && adoption.replaced === 0) {
|
|
52
|
-
|
|
32
|
+
yield* Console.log(`quality: no error-level violations to record; ${session.config.baseline} is unchanged.`);
|
|
33
|
+
} else {
|
|
34
|
+
yield* save(session, adoption.entries);
|
|
35
|
+
const replaced = adoption.replaced > 0 ? `, replacing ${plural(adoption.replaced, "entry", "entries")}` : "";
|
|
36
|
+
yield* Console.log(`quality: recorded ${plural(adoption.added, "entry", "entries")} in ${session.config.baseline}${replaced}.`);
|
|
53
37
|
}
|
|
54
|
-
yield*
|
|
55
|
-
const replaced = adoption.replaced > 0 ? `, replacing ${plural(adoption.replaced, "entry", "entries")}` : "";
|
|
56
|
-
yield* Console.log(`quality: recorded ${plural(adoption.added, "entry", "entries")} in ${session.config.baseline}${replaced}.`);
|
|
38
|
+
yield* reportBaselineWrite(existing, adoption.entries, rules);
|
|
57
39
|
});
|
|
58
40
|
|
|
59
41
|
function changes(pruned: Pruned): string {
|
package/src/cli/misplaced.ts
CHANGED
|
@@ -4,8 +4,6 @@ export const OPTIONS = {
|
|
|
4
4
|
against: { type: "string" },
|
|
5
5
|
config: { type: "string" },
|
|
6
6
|
coverage: { type: "boolean" },
|
|
7
|
-
file: { multiple: true, type: "string" },
|
|
8
|
-
"first-adoption": { type: "boolean" },
|
|
9
7
|
force: { type: "boolean" },
|
|
10
8
|
from: { type: "string" },
|
|
11
9
|
help: { short: "h", type: "boolean" },
|
|
@@ -17,14 +15,14 @@ export type Values = ReturnType<typeof parseArgs<{ options: typeof OPTIONS; allo
|
|
|
17
15
|
|
|
18
16
|
type Option = Exclude<keyof Values, "config" | "help">;
|
|
19
17
|
|
|
20
|
-
const COMMAND_OPTIONS: readonly Option[] = ["against", "coverage", "
|
|
18
|
+
const COMMAND_OPTIONS: readonly Option[] = ["against", "coverage", "force", "from", "rule", "staged"];
|
|
21
19
|
|
|
22
20
|
export const ACCEPTS: Readonly<Record<string, readonly Option[]>> = {
|
|
23
21
|
"baseline install-driver": [],
|
|
24
22
|
"baseline migrate": ["from"],
|
|
25
23
|
"baseline prune": ["against"],
|
|
26
24
|
"baseline tighten": ["staged"],
|
|
27
|
-
"baseline write": ["rule"
|
|
25
|
+
"baseline write": ["rule"],
|
|
28
26
|
ci: ["coverage"],
|
|
29
27
|
"exceptions migrate": ["from"],
|
|
30
28
|
fix: ["rule"],
|