@shivaedev/quality 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +187 -30
- package/biome/declarations.json +17 -0
- package/biome/plugins/ambient-runtime.grit +18 -0
- package/biome/plugins/effect-fn-spans.grit +7 -0
- package/biome/preset.json +602 -0
- package/dist/baseline/compare.d.ts +8 -9
- package/dist/baseline/compare.d.ts.map +1 -1
- package/dist/baseline/compare.js +4 -4
- package/dist/baseline/compare.js.map +1 -1
- package/dist/baseline/format.d.ts +4 -4
- package/dist/baseline/format.d.ts.map +1 -1
- package/dist/baseline/format.js +3 -2
- package/dist/baseline/format.js.map +1 -1
- package/dist/baseline/guard.d.ts +3 -3
- package/dist/baseline/guard.d.ts.map +1 -1
- package/dist/baseline/guard.js +6 -5
- package/dist/baseline/guard.js.map +1 -1
- package/dist/baseline/legacy.d.ts +3 -3
- package/dist/baseline/legacy.d.ts.map +1 -1
- package/dist/baseline/legacy.js.map +1 -1
- package/dist/baseline/rewrite.d.ts +1 -1
- package/dist/baseline/rewrite.d.ts.map +1 -1
- package/dist/baseline/rewrite.js.map +1 -1
- package/dist/baseline/update.d.ts +8 -9
- package/dist/baseline/update.d.ts.map +1 -1
- package/dist/baseline/update.js +10 -9
- package/dist/baseline/update.js.map +1 -1
- package/dist/biome/report.d.ts +33 -0
- package/dist/biome/report.d.ts.map +1 -0
- package/dist/biome/report.js +25 -0
- package/dist/biome/report.js.map +1 -0
- package/dist/biome/run.d.ts +7 -0
- package/dist/biome/run.d.ts.map +1 -0
- package/dist/biome/run.js +16 -0
- package/dist/biome/run.js.map +1 -0
- package/dist/cli/args.d.ts +6 -3
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +9 -4
- 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 +3 -3
- package/dist/cli/baseline.js.map +1 -1
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/fix.d.ts +4 -0
- package/dist/cli/fix.d.ts.map +1 -0
- package/dist/cli/fix.js +19 -0
- package/dist/cli/fix.js.map +1 -0
- package/dist/cli/lint.js +1 -1
- package/dist/cli/lint.js.map +1 -1
- package/dist/cli/run-main.d.ts.map +1 -1
- package/dist/cli/run-main.js +7 -3
- package/dist/cli/run-main.js.map +1 -1
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/config/decode.d.ts +4 -4
- package/dist/config/decode.js +12 -12
- package/dist/config/decode.js.map +1 -1
- package/dist/config/load.d.ts +3 -3
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +1 -1
- package/dist/config/load.js.map +1 -1
- package/dist/config/resolve.d.ts +3 -5
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config/resolve.js +11 -5
- package/dist/config/resolve.js.map +1 -1
- package/dist/config.d.ts +9 -9
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/decoded.d.ts +1 -1
- package/dist/decoded.d.ts.map +1 -1
- package/dist/engine/baseline-file.d.ts +1 -1
- package/dist/engine/baseline-file.d.ts.map +1 -1
- package/dist/engine/evaluate.d.ts +8 -9
- package/dist/engine/evaluate.d.ts.map +1 -1
- package/dist/engine/evaluate.js +4 -4
- package/dist/engine/evaluate.js.map +1 -1
- package/dist/engine/run-rules.d.ts +4 -3
- package/dist/engine/run-rules.d.ts.map +1 -1
- package/dist/engine/run-rules.js +3 -3
- package/dist/engine/run-rules.js.map +1 -1
- package/dist/engine/session.d.ts +3 -3
- package/dist/engine/session.d.ts.map +1 -1
- package/dist/engine/violation.d.ts +11 -3
- package/dist/engine/violation.d.ts.map +1 -1
- package/dist/engine/violation.js +6 -2
- package/dist/engine/violation.js.map +1 -1
- package/dist/exceptions/registry.d.ts +7 -8
- package/dist/exceptions/registry.d.ts.map +1 -1
- package/dist/exceptions/registry.js +6 -6
- package/dist/exceptions/registry.js.map +1 -1
- package/dist/git/base.d.ts +1 -1
- package/dist/git/base.d.ts.map +1 -1
- package/dist/git/base.js.map +1 -1
- package/dist/git/command.d.ts +3 -3
- package/dist/git/command.d.ts.map +1 -1
- package/dist/git/command.js.map +1 -1
- package/dist/git/history.d.ts +1 -1
- package/dist/git/history.d.ts.map +1 -1
- package/dist/git/history.js +1 -1
- package/dist/git/history.js.map +1 -1
- package/dist/imports/ambient.d.ts +7 -0
- package/dist/imports/ambient.d.ts.map +1 -0
- package/dist/imports/ambient.js +44 -0
- package/dist/imports/ambient.js.map +1 -0
- package/dist/imports/components.d.ts +2 -0
- package/dist/imports/components.d.ts.map +1 -0
- package/dist/imports/components.js +63 -0
- package/dist/imports/components.js.map +1 -0
- package/dist/imports/extract.d.ts +10 -0
- package/dist/imports/extract.d.ts.map +1 -0
- package/dist/imports/extract.js +100 -0
- package/dist/imports/extract.js.map +1 -0
- package/dist/imports/fences/dsl.d.ts +18 -0
- package/dist/imports/fences/dsl.d.ts.map +1 -0
- package/dist/imports/fences/dsl.js +14 -0
- package/dist/imports/fences/dsl.js.map +1 -0
- package/dist/imports/fences/evaluate.d.ts +12 -0
- package/dist/imports/fences/evaluate.d.ts.map +1 -0
- package/dist/imports/fences/evaluate.js +55 -0
- package/dist/imports/fences/evaluate.js.map +1 -0
- package/dist/imports/fences/match.d.ts +17 -0
- package/dist/imports/fences/match.d.ts.map +1 -0
- package/dist/imports/fences/match.js +106 -0
- package/dist/imports/fences/match.js.map +1 -0
- package/dist/imports/fences/model.d.ts +60 -0
- package/dist/imports/fences/model.d.ts.map +1 -0
- package/dist/imports/fences/model.js +2 -0
- package/dist/imports/fences/model.js.map +1 -0
- package/dist/imports/fences/policy.d.ts +5 -0
- package/dist/imports/fences/policy.d.ts.map +1 -0
- package/dist/imports/fences/policy.js +59 -0
- package/dist/imports/fences/policy.js.map +1 -0
- package/dist/imports/fences/reach.d.ts +12 -0
- package/dist/imports/fences/reach.d.ts.map +1 -0
- package/dist/imports/fences/reach.js +39 -0
- package/dist/imports/fences/reach.js.map +1 -0
- package/dist/imports/fences/selectors.d.ts +11 -0
- package/dist/imports/fences/selectors.d.ts.map +1 -0
- package/dist/imports/fences/selectors.js +27 -0
- package/dist/imports/fences/selectors.js.map +1 -0
- package/dist/imports/fences/vocabulary.d.ts +9 -0
- package/dist/imports/fences/vocabulary.d.ts.map +1 -0
- package/dist/imports/fences/vocabulary.js +40 -0
- package/dist/imports/fences/vocabulary.js.map +1 -0
- package/dist/imports/generated.d.ts +6 -0
- package/dist/imports/generated.d.ts.map +1 -0
- package/dist/imports/generated.js +78 -0
- package/dist/imports/generated.js.map +1 -0
- package/dist/imports/glob.d.ts +2 -0
- package/dist/imports/glob.d.ts.map +1 -0
- package/dist/imports/glob.js +125 -0
- package/dist/imports/glob.js.map +1 -0
- package/dist/imports/graph.d.ts +23 -0
- package/dist/imports/graph.d.ts.map +1 -0
- package/dist/imports/graph.js +56 -0
- package/dist/imports/graph.js.map +1 -0
- package/dist/imports/paths.d.ts +2 -0
- package/dist/imports/paths.d.ts.map +1 -0
- package/dist/imports/paths.js +24 -0
- package/dist/imports/paths.js.map +1 -0
- package/dist/imports/pnpm-workspace.d.ts +2 -0
- package/dist/imports/pnpm-workspace.d.ts.map +1 -0
- package/dist/imports/pnpm-workspace.js +122 -0
- package/dist/imports/pnpm-workspace.js.map +1 -0
- package/dist/imports/projects.d.ts +10 -0
- package/dist/imports/projects.d.ts.map +1 -0
- package/dist/imports/projects.js +83 -0
- package/dist/imports/projects.js.map +1 -0
- package/dist/imports/resolve.d.ts +16 -0
- package/dist/imports/resolve.d.ts.map +1 -0
- package/dist/imports/resolve.js +88 -0
- package/dist/imports/resolve.js.map +1 -0
- package/dist/imports/workspace.d.ts +10 -0
- package/dist/imports/workspace.d.ts.map +1 -0
- package/dist/imports/workspace.js +55 -0
- package/dist/imports/workspace.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/inventory/collect.d.ts +6 -6
- package/dist/inventory/collect.d.ts.map +1 -1
- package/dist/inventory/collect.js.map +1 -1
- package/dist/manifests/sorted.d.ts +14 -0
- package/dist/manifests/sorted.d.ts.map +1 -0
- package/dist/manifests/sorted.js +39 -0
- package/dist/manifests/sorted.js.map +1 -0
- package/dist/report/guard.d.ts +1 -1
- package/dist/report/guard.d.ts.map +1 -1
- package/dist/report/guard.js +1 -1
- package/dist/report/guard.js.map +1 -1
- package/dist/report/render.d.ts +2 -2
- package/dist/report/render.d.ts.map +1 -1
- package/dist/report/render.js.map +1 -1
- package/dist/report/stale.d.ts +2 -2
- package/dist/report/stale.d.ts.map +1 -1
- package/dist/report/stale.js.map +1 -1
- package/dist/rule.d.ts +12 -11
- package/dist/rule.d.ts.map +1 -1
- package/dist/rule.js.map +1 -1
- package/dist/rules/biome.d.ts +4 -0
- package/dist/rules/biome.d.ts.map +1 -0
- package/dist/rules/biome.js +40 -0
- package/dist/rules/biome.js.map +1 -0
- package/dist/rules/built-in.d.ts +8 -10
- package/dist/rules/built-in.d.ts.map +1 -1
- package/dist/rules/built-in.js +12 -0
- package/dist/rules/built-in.js.map +1 -1
- package/dist/rules/comments/kinds.d.ts +1 -2
- package/dist/rules/comments/kinds.d.ts.map +1 -1
- package/dist/rules/comments/kinds.js +7 -16
- package/dist/rules/comments/kinds.js.map +1 -1
- package/dist/rules/comments/max-per-file.d.ts +1 -1
- package/dist/rules/comments/max-per-file.js +11 -11
- package/dist/rules/comments/max-per-file.js.map +1 -1
- package/dist/rules/comments/no-banner.js +2 -2
- package/dist/rules/comments/no-banner.js.map +1 -1
- package/dist/rules/comments/no-environment-pragma.d.ts +2 -0
- package/dist/rules/comments/no-environment-pragma.d.ts.map +1 -0
- package/dist/rules/comments/no-environment-pragma.js +8 -0
- package/dist/rules/comments/no-environment-pragma.js.map +1 -0
- package/dist/rules/comments/no-jsdoc.js +3 -3
- package/dist/rules/comments/no-jsdoc.js.map +1 -1
- package/dist/rules/comments/no-line-reference.js +2 -2
- package/dist/rules/comments/no-line-reference.js.map +1 -1
- package/dist/rules/comments/no-pr-reference.js +6 -6
- package/dist/rules/comments/no-pr-reference.js.map +1 -1
- package/dist/rules/comments/no-todo.js +2 -2
- package/dist/rules/comments/no-todo.js.map +1 -1
- package/dist/rules/comments/pattern-rule.d.ts +2 -2
- package/dist/rules/comments/pattern-rule.d.ts.map +1 -1
- package/dist/rules/comments/pattern-rule.js +2 -2
- package/dist/rules/comments/pattern-rule.js.map +1 -1
- package/dist/rules/comments/scan.d.ts +6 -6
- package/dist/rules/comments/scan.d.ts.map +1 -1
- package/dist/rules/comments/scan.js +2 -2
- package/dist/rules/comments/scan.js.map +1 -1
- package/dist/rules/imports/cycles.d.ts +2 -0
- package/dist/rules/imports/cycles.d.ts.map +1 -0
- package/dist/rules/imports/cycles.js +38 -0
- package/dist/rules/imports/cycles.js.map +1 -0
- package/dist/rules/imports/fences.d.ts +5 -0
- package/dist/rules/imports/fences.d.ts.map +1 -0
- package/dist/rules/imports/fences.js +24 -0
- package/dist/rules/imports/fences.js.map +1 -0
- package/dist/rules/imports/resolvable.d.ts +4 -0
- package/dist/rules/imports/resolvable.d.ts.map +1 -0
- package/dist/rules/imports/resolvable.js +22 -0
- package/dist/rules/imports/resolvable.js.map +1 -0
- package/dist/rules/manifests-sorted.d.ts +2 -0
- package/dist/rules/manifests-sorted.d.ts.map +1 -0
- package/dist/rules/manifests-sorted.js +22 -0
- package/dist/rules/manifests-sorted.js.map +1 -0
- package/dist/rules/max-lines.js +4 -4
- package/dist/rules/max-lines.js.map +1 -1
- package/dist/rules/suppressions/biome/configs.d.ts +21 -10
- package/dist/rules/suppressions/biome/configs.d.ts.map +1 -1
- package/dist/rules/suppressions/biome/configs.js +58 -22
- package/dist/rules/suppressions/biome/configs.js.map +1 -1
- package/dist/rules/suppressions/biome/declarations.d.ts +18 -0
- package/dist/rules/suppressions/biome/declarations.d.ts.map +1 -0
- package/dist/rules/suppressions/biome/declarations.js +20 -0
- package/dist/rules/suppressions/biome/declarations.js.map +1 -0
- package/dist/rules/suppressions/biome/json.d.ts +2 -2
- package/dist/rules/suppressions/biome/json.d.ts.map +1 -1
- package/dist/rules/suppressions/biome/json.js +1 -1
- package/dist/rules/suppressions/biome/json.js.map +1 -1
- package/dist/rules/suppressions/biome/resolve.d.ts +3 -0
- package/dist/rules/suppressions/biome/resolve.d.ts.map +1 -0
- package/dist/rules/suppressions/biome/resolve.js +70 -0
- package/dist/rules/suppressions/biome/resolve.js.map +1 -0
- package/dist/rules/suppressions/biome/weakenings.d.ts +5 -5
- package/dist/rules/suppressions/biome/weakenings.d.ts.map +1 -1
- package/dist/rules/suppressions/biome/weakenings.js +41 -33
- package/dist/rules/suppressions/biome/weakenings.js.map +1 -1
- package/dist/rules/suppressions/biome-overrides.d.ts +1 -1
- package/dist/rules/suppressions/biome-overrides.d.ts.map +1 -1
- package/dist/rules/suppressions/biome-overrides.js +35 -27
- package/dist/rules/suppressions/biome-overrides.js.map +1 -1
- package/dist/rules/suppressions/directives.d.ts +1 -1
- package/dist/rules/suppressions/directives.d.ts.map +1 -1
- package/dist/rules/suppressions/directives.js +11 -11
- package/dist/rules/suppressions/directives.js.map +1 -1
- package/dist/rules/suppressions/no-double-cast.js +2 -2
- package/dist/rules/suppressions/no-double-cast.js.map +1 -1
- package/dist/rules/suppressions/no-inline.d.ts +1 -7
- package/dist/rules/suppressions/no-inline.d.ts.map +1 -1
- package/dist/rules/suppressions/no-inline.js +7 -30
- package/dist/rules/suppressions/no-inline.js.map +1 -1
- package/dist/rules/suppressions/stylesheet-comments.d.ts +1 -1
- package/dist/rules/suppressions/stylesheet-comments.d.ts.map +1 -1
- package/dist/rules/suppressions/stylesheet-comments.js +3 -3
- package/dist/rules/suppressions/stylesheet-comments.js.map +1 -1
- package/dist/rules/syntax.js +4 -4
- package/dist/rules/syntax.js.map +1 -1
- package/dist/standard-schema.d.ts +1 -1
- package/dist/standard-schema.d.ts.map +1 -1
- package/dist/vitest.d.ts +3 -0
- package/dist/vitest.d.ts.map +1 -0
- package/dist/vitest.js +20 -0
- package/dist/vitest.js.map +1 -0
- package/package.json +48 -31
- package/src/baseline/compare.ts +10 -15
- package/src/baseline/format.ts +8 -6
- package/src/baseline/guard.ts +11 -10
- package/src/baseline/legacy.ts +3 -3
- package/src/baseline/rewrite.ts +1 -1
- package/src/baseline/update.ts +21 -21
- package/src/biome/report.ts +35 -0
- package/src/biome/run.ts +23 -0
- package/src/cli/args.ts +14 -8
- package/src/cli/baseline.ts +5 -6
- package/src/cli/check.ts +1 -1
- package/src/cli/fix.ts +19 -0
- package/src/cli/lint.ts +1 -1
- package/src/cli/run-main.ts +8 -3
- package/src/cli.ts +3 -0
- package/src/config/decode.ts +12 -12
- package/src/config/load.ts +4 -4
- package/src/config/resolve.ts +15 -11
- package/src/config.ts +9 -9
- package/src/decoded.ts +1 -1
- package/src/engine/baseline-file.ts +1 -1
- package/src/engine/evaluate.ts +14 -16
- package/src/engine/run-rules.ts +8 -7
- package/src/engine/session.ts +3 -3
- package/src/engine/violation.ts +18 -4
- package/src/exceptions/registry.ts +10 -16
- package/src/git/base.ts +2 -2
- package/src/git/command.ts +3 -3
- package/src/git/history.ts +2 -2
- package/src/imports/ambient.ts +54 -0
- package/src/imports/components.ts +80 -0
- package/src/imports/extract.ts +129 -0
- package/src/imports/fences/dsl.ts +33 -0
- package/src/imports/fences/evaluate.ts +75 -0
- package/src/imports/fences/match.ts +148 -0
- package/src/imports/fences/model.ts +42 -0
- package/src/imports/fences/policy.ts +70 -0
- package/src/imports/fences/reach.ts +62 -0
- package/src/imports/fences/selectors.ts +37 -0
- package/src/imports/fences/vocabulary.ts +51 -0
- package/src/imports/generated.ts +95 -0
- package/src/imports/glob.ts +142 -0
- package/src/imports/graph.ts +81 -0
- package/src/imports/paths.ts +28 -0
- package/src/imports/pnpm-workspace.ts +134 -0
- package/src/imports/projects.ts +106 -0
- package/src/imports/resolve.ts +115 -0
- package/src/imports/workspace.ts +76 -0
- package/src/index.ts +3 -0
- package/src/inventory/collect.ts +6 -6
- package/src/manifests/sorted.ts +46 -0
- package/src/report/guard.ts +2 -2
- package/src/report/render.ts +9 -9
- package/src/report/stale.ts +3 -3
- package/src/rule.ts +13 -12
- package/src/rules/biome.ts +47 -0
- package/src/rules/built-in.ts +12 -0
- package/src/rules/comments/kinds.ts +11 -21
- package/src/rules/comments/max-per-file.ts +13 -13
- package/src/rules/comments/no-banner.ts +2 -2
- package/src/rules/comments/no-environment-pragma.ts +9 -0
- package/src/rules/comments/no-jsdoc.ts +3 -3
- package/src/rules/comments/no-line-reference.ts +2 -2
- package/src/rules/comments/no-pr-reference.ts +6 -6
- package/src/rules/comments/no-todo.ts +2 -2
- package/src/rules/comments/pattern-rule.ts +6 -6
- package/src/rules/comments/scan.ts +13 -13
- package/src/rules/imports/cycles.ts +44 -0
- package/src/rules/imports/fences.ts +27 -0
- package/src/rules/imports/resolvable.ts +23 -0
- package/src/rules/manifests-sorted.ts +23 -0
- package/src/rules/max-lines.ts +6 -6
- package/src/rules/suppressions/biome/configs.ts +99 -30
- package/src/rules/suppressions/biome/declarations.ts +37 -0
- package/src/rules/suppressions/biome/json.ts +3 -3
- package/src/rules/suppressions/biome/resolve.ts +86 -0
- package/src/rules/suppressions/biome/weakenings.ts +64 -48
- package/src/rules/suppressions/biome-overrides.ts +45 -36
- package/src/rules/suppressions/directives.ts +12 -12
- package/src/rules/suppressions/no-double-cast.ts +4 -4
- package/src/rules/suppressions/no-inline.ts +13 -37
- package/src/rules/suppressions/stylesheet-comments.ts +4 -4
- package/src/rules/syntax.ts +4 -4
- package/src/standard-schema.ts +1 -1
- package/src/vitest.ts +22 -0
- package/tsconfig/base.json +35 -0
- package/tsconfig/package.json +10 -0
package/src/baseline/compare.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { groupBy, keyOf, unusedEntryProblem, type Violation } from "../engine/violation.ts";
|
|
1
|
+
import { groupBy, keyOf, levelOf, type RuleIndex, unusedEntryProblem, type Violation } from "../engine/violation.ts";
|
|
3
2
|
import type { BaselineEntry } from "./format.ts";
|
|
4
3
|
|
|
5
4
|
export interface Regression {
|
|
6
|
-
readonly entry: BaselineEntry;
|
|
7
5
|
readonly count: number;
|
|
6
|
+
readonly entry: BaselineEntry;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
export interface StaleBaselineEntry {
|
|
@@ -13,20 +12,16 @@ export interface StaleBaselineEntry {
|
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
export interface BaselineCheck {
|
|
16
|
-
readonly kept: ReadonlyArray<Violation>;
|
|
17
|
-
readonly regressions: ReadonlyArray<Regression>;
|
|
18
|
-
readonly stale: ReadonlyArray<StaleBaselineEntry>;
|
|
19
|
-
readonly loose: ReadonlyArray<StaleBaselineEntry>;
|
|
20
15
|
readonly baselined: number;
|
|
16
|
+
readonly kept: readonly Violation[];
|
|
17
|
+
readonly loose: readonly StaleBaselineEntry[];
|
|
18
|
+
readonly regressions: readonly Regression[];
|
|
19
|
+
readonly stale: readonly StaleBaselineEntry[];
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
export const countOf = (violations:
|
|
22
|
+
export const countOf = (violations: readonly Violation[]): number => violations.reduce((total, violation) => total + (violation.count ?? 1), 0);
|
|
24
23
|
|
|
25
|
-
export const applyBaseline = (
|
|
26
|
-
violations: ReadonlyArray<Violation>,
|
|
27
|
-
entries: ReadonlyArray<BaselineEntry>,
|
|
28
|
-
levels: ReadonlyMap<string, Level>,
|
|
29
|
-
): BaselineCheck => {
|
|
24
|
+
export const applyBaseline = (violations: readonly Violation[], entries: readonly BaselineEntry[], rules: RuleIndex): BaselineCheck => {
|
|
30
25
|
const groups = groupBy(violations, (violation) => keyOf(violation.rule, violation.file));
|
|
31
26
|
const covered = new Set<string>();
|
|
32
27
|
const regressions: Regression[] = [];
|
|
@@ -35,10 +30,10 @@ export const applyBaseline = (
|
|
|
35
30
|
for (const entry of entries) {
|
|
36
31
|
const group = groups.get(keyOf(entry.rule, entry.file)) ?? [];
|
|
37
32
|
if (group.length === 0) {
|
|
38
|
-
const level =
|
|
33
|
+
const level = levelOf(rules, entry.rule);
|
|
39
34
|
(level === undefined || level === "off" ? stale : loose).push({
|
|
40
35
|
entry,
|
|
41
|
-
problem: unusedEntryProblem(
|
|
36
|
+
problem: unusedEntryProblem(rules, entry.rule, "has no violations left"),
|
|
42
37
|
});
|
|
43
38
|
continue;
|
|
44
39
|
}
|
package/src/baseline/format.ts
CHANGED
|
@@ -3,17 +3,17 @@ import { type Decoded, decodeWith } from "../decoded.ts";
|
|
|
3
3
|
import { keyOf } from "../engine/violation.ts";
|
|
4
4
|
|
|
5
5
|
const Line = Schema.Struct({
|
|
6
|
+
count: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
6
7
|
path: Schema.NonEmptyString,
|
|
7
8
|
rule: Schema.NonEmptyString,
|
|
8
|
-
count: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
const standard = Schema.toStandardSchemaV1(Schema.fromJsonString(Line), { parseOptions: { errors: "all", onExcessProperty: "error" } });
|
|
12
12
|
|
|
13
13
|
export interface BaselineEntry {
|
|
14
|
-
readonly rule: string;
|
|
15
|
-
readonly file: string;
|
|
16
14
|
readonly count: number;
|
|
15
|
+
readonly file: string;
|
|
16
|
+
readonly rule: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const codepoints = (left: string, right: string): number => (left < right ? -1 : Number(left > right));
|
|
@@ -27,7 +27,7 @@ export const linesOf = (raw: string | undefined): ReadonlyArray<{ readonly line:
|
|
|
27
27
|
.map((text, index) => ({ line: index + 1, text }))
|
|
28
28
|
.filter((row) => row.text.trim() !== "");
|
|
29
29
|
|
|
30
|
-
export const decodeBaseline = async (raw: string | undefined): Promise<Decoded<
|
|
30
|
+
export const decodeBaseline = async (raw: string | undefined): Promise<Decoded<readonly BaselineEntry[]>> => {
|
|
31
31
|
const issues: string[] = [];
|
|
32
32
|
const entries: BaselineEntry[] = [];
|
|
33
33
|
const seen = new Set<string>();
|
|
@@ -47,9 +47,11 @@ export const decodeBaseline = async (raw: string | undefined): Promise<Decoded<R
|
|
|
47
47
|
return issues.length === 0 ? { _tag: "Valid", value: entries } : { _tag: "Invalid", issues };
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
const LINE_KEYS = ["path", "rule", "count"];
|
|
51
|
+
|
|
52
|
+
export const encodeEntry = (entry: BaselineEntry): string => JSON.stringify({ count: entry.count, path: entry.file, rule: entry.rule }, LINE_KEYS);
|
|
51
53
|
|
|
52
|
-
export const encodeBaseline = (entries:
|
|
54
|
+
export const encodeBaseline = (entries: readonly BaselineEntry[]): string =>
|
|
53
55
|
[...entries]
|
|
54
56
|
.sort(byPathAndRule)
|
|
55
57
|
.map((entry) => `${encodeEntry(entry)}\n`)
|
package/src/baseline/guard.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { groupBy, keyOf } from "../engine/violation.ts";
|
|
1
|
+
import { covers, groupBy, keyOf } from "../engine/violation.ts";
|
|
2
2
|
import type { BaselineEntry } from "./format.ts";
|
|
3
3
|
|
|
4
4
|
export type GuardProblem =
|
|
@@ -8,16 +8,16 @@ export type GuardProblem =
|
|
|
8
8
|
| { readonly _tag: "NothingAdopted"; readonly rule: string };
|
|
9
9
|
|
|
10
10
|
export interface GuardResult {
|
|
11
|
-
readonly
|
|
11
|
+
readonly adopted: readonly string[];
|
|
12
12
|
readonly moved: number;
|
|
13
|
-
readonly
|
|
13
|
+
readonly problems: readonly GuardProblem[];
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const guardBaseline = (
|
|
17
|
-
base:
|
|
18
|
-
working:
|
|
17
|
+
base: readonly BaselineEntry[],
|
|
18
|
+
working: readonly BaselineEntry[],
|
|
19
19
|
renames: ReadonlyMap<string, string>,
|
|
20
|
-
adopt:
|
|
20
|
+
adopt: readonly string[],
|
|
21
21
|
): GuardResult => {
|
|
22
22
|
const before = new Map(base.map((entry) => [keyOf(entry.rule, entry.file), entry]));
|
|
23
23
|
const covered = new Set(base.map((entry) => entry.rule));
|
|
@@ -36,12 +36,13 @@ export const guardBaseline = (
|
|
|
36
36
|
moved += 1;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
const adopted = (rule: string): boolean => adopt.some((name) => covers(name, rule));
|
|
39
40
|
const fresh = [...byRule.entries()].filter(([rule]) => !covered.has(rule));
|
|
40
|
-
for (const [rule, entries] of fresh.filter(([rule]) => !
|
|
41
|
+
for (const [rule, entries] of fresh.filter(([rule]) => !adopted(rule))) {
|
|
41
42
|
problems.push({ _tag: "Unadopted", entries: entries.length, rule });
|
|
42
43
|
}
|
|
43
|
-
for (const
|
|
44
|
-
problems.push({ _tag: "NothingAdopted", rule });
|
|
44
|
+
for (const name of adopt.filter((candidate) => ![...byRule.keys()].some((rule) => covers(candidate, rule)))) {
|
|
45
|
+
problems.push({ _tag: "NothingAdopted", rule: name });
|
|
45
46
|
}
|
|
46
|
-
return { adopted: fresh.map(([rule]) => rule).filter(
|
|
47
|
+
return { adopted: fresh.map(([rule]) => rule).filter(adopted), moved, problems };
|
|
47
48
|
};
|
package/src/baseline/legacy.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface LegacyEntry extends BaselineEntry {
|
|
|
19
19
|
readonly measure?: number | undefined;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const decodeLegacyBaseline = async (raw: string): Promise<Decoded<
|
|
22
|
+
export const decodeLegacyBaseline = async (raw: string): Promise<Decoded<readonly LegacyEntry[]>> => {
|
|
23
23
|
const decoded = await decodeWith(standard, raw);
|
|
24
24
|
if (decoded._tag === "Invalid") {
|
|
25
25
|
return decoded;
|
|
@@ -30,9 +30,9 @@ export const decodeLegacyBaseline = async (raw: string): Promise<Decoded<Readonl
|
|
|
30
30
|
return { _tag: "Valid", value: entries };
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export const measured = (legacy:
|
|
33
|
+
export const measured = (legacy: readonly LegacyEntry[]): boolean => legacy.some((entry) => entry.measure !== undefined);
|
|
34
34
|
|
|
35
|
-
export const convertLegacy = (legacy:
|
|
35
|
+
export const convertLegacy = (legacy: readonly LegacyEntry[], violations: readonly Violation[]): readonly BaselineEntry[] => {
|
|
36
36
|
const current = groupBy(violations, (violation) => keyOf(violation.rule, violation.file));
|
|
37
37
|
return legacy.flatMap(({ count, file, measure, rule }) => {
|
|
38
38
|
if (measure === undefined) {
|
package/src/baseline/rewrite.ts
CHANGED
|
@@ -7,7 +7,7 @@ interface Row {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// An untouched entry keeps its exact line and a new one goes before the first line that sorts after it, so two branches conflict only on the same or neighbouring entries.
|
|
10
|
-
export const rewriteBaseline = (raw: string | undefined, before:
|
|
10
|
+
export const rewriteBaseline = (raw: string | undefined, before: readonly BaselineEntry[], after: readonly BaselineEntry[]): string => {
|
|
11
11
|
const wanted = new Map(after.map((entry) => [keyOf(entry.rule, entry.file), entry]));
|
|
12
12
|
const lines = linesOf(raw);
|
|
13
13
|
const rows: Row[] = before.flatMap((old, index) => {
|
package/src/baseline/update.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { groupBy, keyOf, type Violation } from "../engine/violation.ts";
|
|
1
|
+
import { covers, groupBy, keyOf, levelOf, type RuleIndex, type Violation } from "../engine/violation.ts";
|
|
3
2
|
import { countOf } from "./compare.ts";
|
|
4
3
|
import type { BaselineEntry } from "./format.ts";
|
|
5
4
|
|
|
6
5
|
export type Adoption =
|
|
7
|
-
| { readonly _tag: "Refused"; readonly reasons:
|
|
8
|
-
| { readonly _tag: "Adopted"; readonly entries:
|
|
6
|
+
| { readonly _tag: "Refused"; readonly reasons: readonly string[] }
|
|
7
|
+
| { readonly _tag: "Adopted"; readonly entries: readonly BaselineEntry[]; readonly added: number; readonly replaced: number };
|
|
9
8
|
|
|
10
9
|
export interface Pruned {
|
|
11
|
-
readonly entries:
|
|
10
|
+
readonly entries: readonly BaselineEntry[];
|
|
11
|
+
readonly lowered: number;
|
|
12
12
|
readonly moved: number;
|
|
13
13
|
readonly removed: number;
|
|
14
|
-
readonly lowered: number;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
const record = (violations:
|
|
16
|
+
const record = (violations: readonly Violation[]): readonly BaselineEntry[] =>
|
|
18
17
|
[...groupBy(violations, (violation) => keyOf(violation.rule, violation.file)).values()].flatMap((group) => {
|
|
19
18
|
const first = group[0];
|
|
20
19
|
if (first === undefined) {
|
|
@@ -24,8 +23,8 @@ const record = (violations: ReadonlyArray<Violation>): ReadonlyArray<BaselineEnt
|
|
|
24
23
|
return count > 0 ? [{ count, file: first.file, rule: first.rule }] : [];
|
|
25
24
|
});
|
|
26
25
|
|
|
27
|
-
const refusal = (id: string,
|
|
28
|
-
const level =
|
|
26
|
+
const refusal = (id: string, index: RuleIndex): readonly string[] => {
|
|
27
|
+
const level = levelOf(index, id);
|
|
29
28
|
if (level === undefined) {
|
|
30
29
|
return [`${id}: no built-in or local rule has this id.`];
|
|
31
30
|
}
|
|
@@ -33,27 +32,28 @@ const refusal = (id: string, levels: ReadonlyMap<string, Level>): ReadonlyArray<
|
|
|
33
32
|
};
|
|
34
33
|
|
|
35
34
|
export const adopt = (
|
|
36
|
-
existing:
|
|
37
|
-
rules:
|
|
38
|
-
violations:
|
|
39
|
-
|
|
35
|
+
existing: readonly BaselineEntry[] | undefined,
|
|
36
|
+
rules: readonly string[],
|
|
37
|
+
violations: readonly Violation[],
|
|
38
|
+
index: RuleIndex,
|
|
40
39
|
): Adoption => {
|
|
41
40
|
if (existing !== undefined && rules.length === 0) {
|
|
42
41
|
return { _tag: "Refused", reasons: ["a baseline exists. Record a rule with --rule <id>, or drop fixed debt with prune."] };
|
|
43
42
|
}
|
|
44
|
-
const reasons = rules.flatMap((id) => refusal(id,
|
|
43
|
+
const reasons = rules.flatMap((id) => refusal(id, index));
|
|
45
44
|
if (reasons.length > 0) {
|
|
46
45
|
return { _tag: "Refused", reasons };
|
|
47
46
|
}
|
|
48
|
-
const
|
|
49
|
-
const
|
|
47
|
+
const named = (rule: string): boolean => rules.some((name) => covers(name, rule));
|
|
48
|
+
const kept = (existing ?? []).filter((entry) => !named(entry.rule));
|
|
49
|
+
const adopted = violations.filter((violation) => violation.level === "error" && (rules.length === 0 || named(violation.rule)));
|
|
50
50
|
const added = record(adopted);
|
|
51
51
|
return { _tag: "Adopted", added: added.length, entries: [...kept, ...added], replaced: (existing ?? []).length - kept.length };
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
export interface Scope {
|
|
55
|
-
readonly moves: ReadonlyMap<string, string>;
|
|
56
55
|
readonly files?: ReadonlySet<string> | undefined;
|
|
56
|
+
readonly moves: ReadonlyMap<string, string>;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const inScope = (entry: BaselineEntry, scope: Scope): boolean =>
|
|
@@ -71,9 +71,9 @@ const destination = (
|
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
export const prune = (
|
|
74
|
-
existing:
|
|
75
|
-
violations:
|
|
76
|
-
|
|
74
|
+
existing: readonly BaselineEntry[],
|
|
75
|
+
violations: readonly Violation[],
|
|
76
|
+
index: RuleIndex,
|
|
77
77
|
scope: Scope = { moves: new Map() },
|
|
78
78
|
): Pruned => {
|
|
79
79
|
const current = new Map(record(violations).map((entry) => [keyOf(entry.rule, entry.file), entry]));
|
|
@@ -83,7 +83,7 @@ export const prune = (
|
|
|
83
83
|
if (!inScope(before, scope)) {
|
|
84
84
|
return [{ after: before, before }];
|
|
85
85
|
}
|
|
86
|
-
const level =
|
|
86
|
+
const level = levelOf(index, before.rule);
|
|
87
87
|
const now = current.get(keyOf(before.rule, before.file)) ?? destination(before, current, scope.moves, taken);
|
|
88
88
|
if (now === undefined || level === undefined || level === "off") {
|
|
89
89
|
return [];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { type BiomeRun, runBiome } from "./run.ts";
|
|
3
|
+
|
|
4
|
+
const Position = Schema.Struct({ line: Schema.Int });
|
|
5
|
+
|
|
6
|
+
const Diagnostic = Schema.Struct({
|
|
7
|
+
category: Schema.optionalKey(Schema.String),
|
|
8
|
+
location: Schema.Struct({ path: Schema.optionalKey(Schema.String), start: Schema.optionalKey(Position) }),
|
|
9
|
+
message: Schema.String,
|
|
10
|
+
severity: Schema.String,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export type Diagnostic = typeof Diagnostic.Type;
|
|
14
|
+
|
|
15
|
+
const Report = Schema.Struct({
|
|
16
|
+
diagnostics: Schema.Array(Diagnostic),
|
|
17
|
+
summary: Schema.Struct({ changed: Schema.Int }),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export type Report = typeof Report.Type;
|
|
21
|
+
|
|
22
|
+
const decodeReport = Schema.decodeUnknownOption(Schema.fromJsonString(Report));
|
|
23
|
+
|
|
24
|
+
const failure = (args: readonly string[], run: BiomeRun): Error =>
|
|
25
|
+
new Error(`biome ${args.join(" ")} exited ${run.code} without a report:\n${[run.stdout, run.stderr].join("\n").trim()}`);
|
|
26
|
+
|
|
27
|
+
export async function biomeReport(root: string, args: readonly string[]): Promise<Report> {
|
|
28
|
+
const command = [...args, "--reporter=json", "--max-diagnostics=none", "."];
|
|
29
|
+
const run = await runBiome(root, command);
|
|
30
|
+
const report = decodeReport(run.stdout.trim());
|
|
31
|
+
if (report._tag === "None") {
|
|
32
|
+
throw failure(command, run);
|
|
33
|
+
}
|
|
34
|
+
return report.value;
|
|
35
|
+
}
|
package/src/biome/run.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
|
|
5
|
+
export interface BiomeRun {
|
|
6
|
+
readonly code: number;
|
|
7
|
+
readonly stderr: string;
|
|
8
|
+
readonly stdout: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const BIN = createRequire(import.meta.url).resolve("@biomejs/biome/bin/biome");
|
|
12
|
+
|
|
13
|
+
export function runBiome(root: string, args: readonly string[]): Promise<BiomeRun> {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
execFile(process.execPath, [BIN, ...args, "--colors=off"], { cwd: root, maxBuffer: 2 ** 30 }, (error, stdout, stderr) => {
|
|
16
|
+
if (error !== null && typeof error.code !== "number") {
|
|
17
|
+
reject(error);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
resolve({ code: error === null ? 0 : Number(error.code), stderr, stdout });
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
package/src/cli/args.ts
CHANGED
|
@@ -4,7 +4,8 @@ import type { WarningDetail } from "../report/render.ts";
|
|
|
4
4
|
|
|
5
5
|
export type Command =
|
|
6
6
|
| { readonly _tag: "Lint"; readonly config: string | undefined; readonly warnings: WarningDetail }
|
|
7
|
-
| { readonly _tag: "
|
|
7
|
+
| { readonly _tag: "Fix"; readonly config: string | undefined }
|
|
8
|
+
| { readonly _tag: "BaselineWrite"; readonly config: string | undefined; readonly rules: readonly string[] }
|
|
8
9
|
| { readonly _tag: "BaselinePrune"; readonly config: string | undefined; readonly against: string | undefined }
|
|
9
10
|
| { readonly _tag: "BaselineCheck"; readonly config: string | undefined; readonly against: string | undefined }
|
|
10
11
|
| { readonly _tag: "BaselineTighten"; readonly config: string | undefined; readonly staged: boolean }
|
|
@@ -15,6 +16,7 @@ export type Parsed = { readonly _tag: "Parsed"; readonly command: Command } | {
|
|
|
15
16
|
|
|
16
17
|
export const USAGE = `Usage:
|
|
17
18
|
quality lint [--config <file>] [--warnings summary|all]
|
|
19
|
+
quality fix [--config <file>]
|
|
18
20
|
quality baseline write [--config <file>] [--rule <id>]...
|
|
19
21
|
quality baseline prune [--config <file>] [--against <ref>]
|
|
20
22
|
quality baseline tighten [--config <file>] [--staged]
|
|
@@ -23,6 +25,7 @@ export const USAGE = `Usage:
|
|
|
23
25
|
|
|
24
26
|
lint Run every rule. Exits 1 on an error-level violation, a file over its baseline, a stale registry entry
|
|
25
27
|
or a baseline entry for a rule that is off or unknown.
|
|
28
|
+
fix Apply Biome's safe fixes, assist actions and formatting.
|
|
26
29
|
baseline write Record current error-level violations. Creates the baseline, or records the named rules again, replacing their entries.
|
|
27
30
|
baseline prune Drop fixed debt, lower entries to what is left and carry entries to files git saw move. Never adds or raises an entry.
|
|
28
31
|
baseline tighten Prune only the entries of files changed since HEAD, or with --staged, in the index.
|
|
@@ -51,15 +54,16 @@ type Values = ReturnType<typeof parseArgs<{ options: typeof OPTIONS; allowPositi
|
|
|
51
54
|
|
|
52
55
|
type Option = Exclude<keyof Values, "config" | "help">;
|
|
53
56
|
|
|
54
|
-
const COMMAND_OPTIONS:
|
|
57
|
+
const COMMAND_OPTIONS: readonly Option[] = ["against", "from", "rule", "staged", "warnings"];
|
|
55
58
|
|
|
56
|
-
const ACCEPTS: Readonly<Record<string,
|
|
57
|
-
lint: ["warnings"],
|
|
58
|
-
"baseline write": ["rule"],
|
|
59
|
-
"baseline prune": ["against"],
|
|
60
|
-
"baseline tighten": ["staged"],
|
|
59
|
+
const ACCEPTS: Readonly<Record<string, readonly Option[]>> = {
|
|
61
60
|
"baseline check": ["against"],
|
|
62
61
|
"baseline migrate": ["from"],
|
|
62
|
+
"baseline prune": ["against"],
|
|
63
|
+
"baseline tighten": ["staged"],
|
|
64
|
+
"baseline write": ["rule"],
|
|
65
|
+
fix: [],
|
|
66
|
+
lint: ["warnings"],
|
|
63
67
|
};
|
|
64
68
|
|
|
65
69
|
const misplaced = (name: string, values: Values): string | undefined => {
|
|
@@ -80,6 +84,8 @@ const commandFor = (name: string, values: Values): Parsed => {
|
|
|
80
84
|
? parsed({ _tag: "Lint", config, warnings })
|
|
81
85
|
: usage(`--warnings takes summary or all, not "${warnings}".`);
|
|
82
86
|
}
|
|
87
|
+
case "fix":
|
|
88
|
+
return parsed({ _tag: "Fix", config });
|
|
83
89
|
case "baseline write":
|
|
84
90
|
return parsed({ _tag: "BaselineWrite", config, rules: values.rule ?? [] });
|
|
85
91
|
case "baseline prune":
|
|
@@ -93,7 +99,7 @@ const commandFor = (name: string, values: Values): Parsed => {
|
|
|
93
99
|
}
|
|
94
100
|
};
|
|
95
101
|
|
|
96
|
-
export const parseCommand = (args:
|
|
102
|
+
export const parseCommand = (args: readonly string[]): Parsed => {
|
|
97
103
|
const result = Result.try({
|
|
98
104
|
catch: (error) => (error instanceof Error ? error.message : String(error)),
|
|
99
105
|
try: () => parseArgs({ allowPositionals: true, args: [...args], options: OPTIONS, strict: true }),
|
package/src/cli/baseline.ts
CHANGED
|
@@ -9,24 +9,23 @@ import { SetupFailure } from "../failure.ts";
|
|
|
9
9
|
import { writeText } from "../inventory/filesystem.ts";
|
|
10
10
|
import { plural } from "../report/plural.ts";
|
|
11
11
|
|
|
12
|
-
const save = (session: Session, entries:
|
|
12
|
+
const save = (session: Session, entries: readonly BaselineEntry[]): Effect.Effect<void, SetupFailure, FileSystem.FileSystem> =>
|
|
13
13
|
Effect.mapError(
|
|
14
14
|
writeText(join(session.config.root, session.config.baseline), rewriteBaseline(session.baseline.raw, session.baseline.entries, entries)),
|
|
15
15
|
(failure) => new SetupFailure({ message: failure.message }),
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
const unregistered = (session: Session) =>
|
|
19
|
-
applyRegistry(session.violations, session.registry, session.config.levels, session.config.unregistrable).kept;
|
|
18
|
+
const unregistered = (session: Session) => applyRegistry(session.violations, session.registry, session.config).kept;
|
|
20
19
|
|
|
21
20
|
export const writeBaseline = (
|
|
22
21
|
cwd: string,
|
|
23
22
|
config: string | undefined,
|
|
24
|
-
rules:
|
|
23
|
+
rules: readonly string[],
|
|
25
24
|
): Effect.Effect<void, SetupFailure, FileSystem.FileSystem> =>
|
|
26
25
|
Effect.gen(function* () {
|
|
27
26
|
const session = yield* openSession(cwd, config);
|
|
28
27
|
const existing = session.baseline.raw === undefined ? undefined : session.baseline.entries;
|
|
29
|
-
const adoption = adopt(existing, rules, unregistered(session), session.config
|
|
28
|
+
const adoption = adopt(existing, rules, unregistered(session), session.config);
|
|
30
29
|
if (adoption._tag === "Refused") {
|
|
31
30
|
return yield* new SetupFailure({ message: `baseline write refused:\n${adoption.reasons.map((reason) => ` - ${reason}`).join("\n")}` });
|
|
32
31
|
}
|
|
@@ -57,7 +56,7 @@ export const shrinkBaseline = <Requirements>(
|
|
|
57
56
|
if (session.baseline.raw === undefined) {
|
|
58
57
|
return yield* Console.log(`quality: no baseline at ${session.config.baseline}; nothing to lower.`);
|
|
59
58
|
}
|
|
60
|
-
const pruned = prune(session.baseline.entries, unregistered(session), session.config
|
|
59
|
+
const pruned = prune(session.baseline.entries, unregistered(session), session.config, yield* scopeOf(session));
|
|
61
60
|
if (pruned.removed === 0 && pruned.lowered === 0 && pruned.moved === 0) {
|
|
62
61
|
return yield* Console.log(`quality: ${session.config.baseline} is current.`);
|
|
63
62
|
}
|
package/src/cli/check.ts
CHANGED
|
@@ -17,7 +17,7 @@ const baseEntries = (
|
|
|
17
17
|
config: ResolvedConfig,
|
|
18
18
|
base: Base,
|
|
19
19
|
path: string,
|
|
20
|
-
): Effect.Effect<
|
|
20
|
+
): Effect.Effect<readonly BaselineEntry[], SetupFailure, FileSystem.FileSystem | Git> =>
|
|
21
21
|
Effect.gen(function* () {
|
|
22
22
|
const raw = yield* readAt(config.root, base.commit, path);
|
|
23
23
|
if (raw !== undefined) {
|
package/src/cli/fix.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Console, Effect, type FileSystem } from "effect";
|
|
2
|
+
import { biomeReport } from "../biome/report.ts";
|
|
3
|
+
import { loadConfig } from "../config/load.ts";
|
|
4
|
+
import { SetupFailure } from "../failure.ts";
|
|
5
|
+
import { sortManifests } from "../manifests/sorted.ts";
|
|
6
|
+
import { plural } from "../report/plural.ts";
|
|
7
|
+
|
|
8
|
+
export function fix(cwd: string, config: string | undefined): Effect.Effect<void, SetupFailure, FileSystem.FileSystem> {
|
|
9
|
+
return Effect.gen(function* () {
|
|
10
|
+
const { root } = yield* loadConfig(cwd, config);
|
|
11
|
+
const sorted = yield* Effect.mapError(sortManifests(root), (failure) => new SetupFailure({ message: failure.message }));
|
|
12
|
+
yield* Console.log(`quality: sort-package-json rewrote ${plural(sorted, "manifest")}.`);
|
|
13
|
+
const report = yield* Effect.tryPromise({
|
|
14
|
+
catch: (cause) => new SetupFailure({ message: cause instanceof Error ? cause.message : String(cause) }),
|
|
15
|
+
try: () => biomeReport(root, ["check", "--write"]),
|
|
16
|
+
});
|
|
17
|
+
yield* Console.log(`quality: Biome rewrote ${plural(report.summary.changed, "file")}.`);
|
|
18
|
+
});
|
|
19
|
+
}
|
package/src/cli/lint.ts
CHANGED
|
@@ -11,7 +11,7 @@ export const lint = (
|
|
|
11
11
|
): Effect.Effect<void, SetupFailure | GateFailed, FileSystem.FileSystem> =>
|
|
12
12
|
Effect.gen(function* () {
|
|
13
13
|
const session = yield* openSession(cwd, config);
|
|
14
|
-
const outcome = evaluate(session.violations, session.registry, session.baseline.entries, session.config
|
|
14
|
+
const outcome = evaluate(session.violations, session.registry, session.baseline.entries, session.config);
|
|
15
15
|
yield* Console.log(
|
|
16
16
|
render(outcome, {
|
|
17
17
|
baseline: session.config.baseline,
|
package/src/cli/run-main.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import process from "node:process";
|
|
1
2
|
import * as NodeChildProcessSpawner from "@effect/platform-node/NodeChildProcessSpawner";
|
|
2
3
|
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
|
|
3
4
|
import * as NodePath from "@effect/platform-node/NodePath";
|
|
@@ -20,11 +21,15 @@ const explain = (cause: Cause.Cause<unknown>): Effect.Effect<void> => {
|
|
|
20
21
|
const exitCodeOf = (error: unknown): number =>
|
|
21
22
|
typeof error === "object" && error !== null && Runtime.errorExitCode in error ? Runtime.getErrorExitCode(error) : COULD_NOT_RUN;
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
+
const exitCode = (exit: Exit.Exit<unknown, unknown>): number => {
|
|
24
25
|
if (Exit.isSuccess(exit)) {
|
|
25
|
-
return
|
|
26
|
+
return 0;
|
|
26
27
|
}
|
|
27
|
-
return
|
|
28
|
+
return Cause.hasInterruptsOnly(exit.cause) ? INTERRUPTED : exitCodeOf(Cause.squash(exit.cause));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const teardown: Runtime.Teardown = (exit, onExit) => {
|
|
32
|
+
process.stdout.write("", () => process.stderr.write("", () => onExit(exitCode(exit))));
|
|
28
33
|
};
|
|
29
34
|
|
|
30
35
|
const services = NodeChildProcessSpawner.layer.pipe(Layer.provideMerge(Layer.mergeAll(NodeFileSystem.layer, NodePath.layer)));
|
package/src/cli.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Console, Effect } from "effect";
|
|
|
4
4
|
import { parseCommand, USAGE } from "./cli/args.ts";
|
|
5
5
|
import { writeBaseline } from "./cli/baseline.ts";
|
|
6
6
|
import { checkBaseline } from "./cli/check.ts";
|
|
7
|
+
import { fix } from "./cli/fix.ts";
|
|
7
8
|
import { lint } from "./cli/lint.ts";
|
|
8
9
|
import { migrateBaseline } from "./cli/migrate.ts";
|
|
9
10
|
import { runMain } from "./cli/run-main.ts";
|
|
@@ -22,6 +23,8 @@ const program = Effect.gen(function* () {
|
|
|
22
23
|
return yield* Console.log(USAGE);
|
|
23
24
|
case "Lint":
|
|
24
25
|
return yield* lint(process.cwd(), command.config, command.warnings);
|
|
26
|
+
case "Fix":
|
|
27
|
+
return yield* fix(process.cwd(), command.config);
|
|
25
28
|
case "BaselineWrite":
|
|
26
29
|
return yield* writeBaseline(process.cwd(), command.config, command.rules);
|
|
27
30
|
case "BaselinePrune":
|
package/src/config/decode.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { type Decoded, decodeWith } from "../decoded.ts";
|
|
|
3
3
|
import type { Rule } from "../rule.ts";
|
|
4
4
|
|
|
5
5
|
const isRule = (value: unknown): value is Rule =>
|
|
6
|
-
typeof value === "object"
|
|
7
|
-
value !== null
|
|
8
|
-
"id" in value
|
|
9
|
-
typeof value.id === "string"
|
|
10
|
-
"description" in value
|
|
11
|
-
typeof value.description === "string"
|
|
12
|
-
"configure" in value
|
|
13
|
-
typeof value.configure === "function";
|
|
6
|
+
typeof value === "object"
|
|
7
|
+
&& value !== null
|
|
8
|
+
&& "id" in value
|
|
9
|
+
&& typeof value.id === "string"
|
|
10
|
+
&& "description" in value
|
|
11
|
+
&& typeof value.description === "string"
|
|
12
|
+
&& "configure" in value
|
|
13
|
+
&& typeof value.configure === "function";
|
|
14
14
|
|
|
15
15
|
const Level = Schema.Literals(["error", "warn", "off"]);
|
|
16
16
|
|
|
@@ -19,14 +19,14 @@ const Setting = Schema.Union([Level, Schema.Struct({ level: Schema.optionalKey(L
|
|
|
19
19
|
const LocalRule = Schema.declare(isRule, { expected: "a rule made with defineRule" });
|
|
20
20
|
|
|
21
21
|
const ConfigInput = Schema.Struct({
|
|
22
|
-
|
|
22
|
+
adopt: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
23
|
+
baseline: Schema.optionalKey(Schema.String),
|
|
23
24
|
exclude: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
24
25
|
extensions: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
25
|
-
registry: Schema.optionalKey(Schema.String),
|
|
26
|
-
baseline: Schema.optionalKey(Schema.String),
|
|
27
|
-
adopt: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
28
26
|
local: Schema.optionalKey(Schema.Array(LocalRule)),
|
|
27
|
+
registry: Schema.optionalKey(Schema.String),
|
|
29
28
|
rules: Schema.optionalKey(Schema.Record(Schema.String, Setting)),
|
|
29
|
+
sources: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
export type ConfigInput = typeof ConfigInput.Type;
|
package/src/config/load.ts
CHANGED
|
@@ -11,11 +11,11 @@ import { type ResolvedRules, resolveRules } from "./resolve.ts";
|
|
|
11
11
|
const DEFAULT_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
|
|
12
12
|
|
|
13
13
|
export interface ResolvedConfig extends ResolvedRules, InventoryScope {
|
|
14
|
-
readonly
|
|
14
|
+
readonly adopt: readonly string[];
|
|
15
|
+
readonly baseline: string;
|
|
15
16
|
readonly file: string;
|
|
16
17
|
readonly registry: string;
|
|
17
|
-
readonly
|
|
18
|
-
readonly adopt: ReadonlyArray<string>;
|
|
18
|
+
readonly root: string;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const messageOf = (cause: unknown): string => (cause instanceof Error ? cause.message : String(cause));
|
|
@@ -23,8 +23,8 @@ const messageOf = (cause: unknown): string => (cause instanceof Error ? cause.me
|
|
|
23
23
|
const importDefault = (file: string): Effect.Effect<unknown, SetupFailure> =>
|
|
24
24
|
Effect.flatMap(
|
|
25
25
|
Effect.tryPromise({
|
|
26
|
-
try: async (): Promise<unknown> => import(pathToFileURL(file).href),
|
|
27
26
|
catch: (cause) => new SetupFailure({ message: `cannot load ${file}: ${messageOf(cause)}` }),
|
|
27
|
+
try: async (): Promise<unknown> => import(pathToFileURL(file).href),
|
|
28
28
|
}),
|
|
29
29
|
(loaded) =>
|
|
30
30
|
typeof loaded === "object" && loaded !== null && "default" in loaded
|