@shivaedev/quality 0.7.2 → 0.8.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 +23 -0
- package/README.md +102 -8
- package/biome/plugins/constant-names.grit +17 -0
- package/biome/plugins/effect-fn-spans.grit +13 -3
- package/biome/plugins/handler-names.grit +10 -0
- package/biome/plugins/schema-names.grit +13 -0
- package/biome/plugins/schema-struct-keys.grit +7 -0
- package/biome/plugins/service-layers.grit +13 -0
- package/biome/plugins/type-re-exports.grit +8 -0
- package/biome/preset.json +48 -1
- package/dist/baseline/compare.d.ts +1 -1
- package/dist/baseline/compare.d.ts.map +1 -1
- package/dist/baseline/compare.js +1 -1
- package/dist/baseline/compare.js.map +1 -1
- package/dist/baseline/format.d.ts +1 -1
- package/dist/baseline/format.d.ts.map +1 -1
- package/dist/baseline/format.js +2 -2
- package/dist/baseline/format.js.map +1 -1
- package/dist/baseline/legacy.d.ts +2 -2
- package/dist/baseline/legacy.d.ts.map +1 -1
- package/dist/baseline/legacy.js +2 -2
- package/dist/baseline/legacy.js.map +1 -1
- package/dist/baseline/rewrite.js +1 -1
- package/dist/baseline/rewrite.js.map +1 -1
- package/dist/baseline/update.d.ts +1 -1
- package/dist/baseline/update.d.ts.map +1 -1
- package/dist/baseline/update.js +1 -1
- package/dist/baseline/update.js.map +1 -1
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/baseline.d.ts +3 -3
- package/dist/cli/baseline.d.ts.map +1 -1
- package/dist/cli/baseline.js +7 -7
- package/dist/cli/baseline.js.map +1 -1
- package/dist/cli/fix.d.ts +1 -1
- package/dist/cli/fix.d.ts.map +1 -1
- package/dist/cli/fix.js +7 -7
- package/dist/cli/fix.js.map +1 -1
- package/dist/cli/lint.d.ts +2 -2
- package/dist/cli/lint.d.ts.map +1 -1
- package/dist/cli/lint.js +4 -4
- package/dist/cli/lint.js.map +1 -1
- package/dist/cli/migrate.d.ts +1 -1
- package/dist/cli/migrate.d.ts.map +1 -1
- package/dist/cli/migrate.js +9 -9
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/run-main.d.ts +1 -1
- package/dist/cli/run-main.d.ts.map +1 -1
- package/dist/cli/run-main.js +1 -1
- package/dist/cli/run-main.js.map +1 -1
- package/dist/cli/shrink.d.ts +2 -2
- package/dist/cli/shrink.d.ts.map +1 -1
- package/dist/cli/shrink.js +2 -2
- package/dist/cli/shrink.js.map +1 -1
- package/dist/cli.js +7 -7
- package/dist/cli.js.map +1 -1
- package/dist/config/decode.d.ts +2 -2
- package/dist/config/decode.d.ts.map +1 -1
- package/dist/config/decode.js +1 -1
- package/dist/config/decode.js.map +1 -1
- package/dist/config/load.d.ts +2 -2
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +2 -2
- package/dist/config/load.js.map +1 -1
- package/dist/config/resolve.d.ts +3 -3
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config/resolve.js +1 -1
- package/dist/config/resolve.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/engine/baseline-file.d.ts +3 -3
- package/dist/engine/baseline-file.d.ts.map +1 -1
- package/dist/engine/baseline-file.js +5 -5
- package/dist/engine/baseline-file.js.map +1 -1
- package/dist/engine/evaluate.d.ts +3 -3
- package/dist/engine/evaluate.d.ts.map +1 -1
- package/dist/engine/evaluate.js +2 -2
- package/dist/engine/evaluate.js.map +1 -1
- package/dist/engine/run-rules.d.ts +2 -2
- package/dist/engine/run-rules.d.ts.map +1 -1
- package/dist/engine/run-rules.js +2 -2
- package/dist/engine/run-rules.js.map +1 -1
- package/dist/engine/session.d.ts +4 -4
- package/dist/engine/session.d.ts.map +1 -1
- package/dist/engine/session.js +6 -6
- package/dist/engine/session.js.map +1 -1
- package/dist/engine/violation.d.ts +2 -2
- package/dist/engine/violation.d.ts.map +1 -1
- package/dist/exceptions/registry.d.ts +2 -2
- package/dist/exceptions/registry.d.ts.map +1 -1
- package/dist/exceptions/registry.js +2 -2
- 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 +1 -1
- package/dist/git/base.js.map +1 -1
- package/dist/git/command.d.ts +1 -1
- package/dist/git/command.d.ts.map +1 -1
- package/dist/git/command.js +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/imports/departures.d.ts +1 -1
- package/dist/imports/departures.d.ts.map +1 -1
- package/dist/imports/departures.js +1 -1
- package/dist/imports/departures.js.map +1 -1
- package/dist/imports/fences/evaluate.d.ts +2 -2
- package/dist/imports/fences/evaluate.d.ts.map +1 -1
- package/dist/imports/fences/match.d.ts +2 -2
- package/dist/imports/fences/match.d.ts.map +1 -1
- package/dist/imports/fences/match.js +2 -2
- package/dist/imports/fences/match.js.map +1 -1
- package/dist/imports/fences/policy.js +1 -1
- package/dist/imports/fences/policy.js.map +1 -1
- package/dist/imports/fences/reach.d.ts +2 -2
- package/dist/imports/fences/reach.d.ts.map +1 -1
- package/dist/imports/fences/vocabulary.d.ts +1 -1
- package/dist/imports/fences/vocabulary.d.ts.map +1 -1
- package/dist/imports/generated.d.ts +1 -1
- package/dist/imports/generated.d.ts.map +1 -1
- package/dist/imports/generated.js +1 -1
- package/dist/imports/generated.js.map +1 -1
- package/dist/imports/graph.d.ts +1 -1
- package/dist/imports/graph.d.ts.map +1 -1
- package/dist/imports/graph.js +1 -1
- package/dist/imports/graph.js.map +1 -1
- package/dist/imports/resolve.js +1 -1
- package/dist/imports/resolve.js.map +1 -1
- package/dist/imports/workspace.d.ts +1 -1
- package/dist/imports/workspace.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/inventory/collect.d.ts +1 -1
- package/dist/inventory/collect.d.ts.map +1 -1
- package/dist/manifests/sorted.d.ts +1 -1
- package/dist/manifests/sorted.d.ts.map +1 -1
- package/dist/manifests/sorted.js +3 -3
- package/dist/manifests/sorted.js.map +1 -1
- package/dist/naming/exportFits.d.ts +2 -0
- package/dist/naming/exportFits.d.ts.map +1 -0
- package/dist/naming/exportFits.js +20 -0
- package/dist/naming/exportFits.js.map +1 -0
- package/dist/naming/mainExport.d.ts +3 -0
- package/dist/naming/mainExport.d.ts.map +1 -0
- package/dist/naming/mainExport.js +10 -0
- package/dist/naming/mainExport.js.map +1 -0
- package/dist/naming/ownExports.d.ts +8 -0
- package/dist/naming/ownExports.d.ts.map +1 -0
- package/dist/naming/ownExports.js +78 -0
- package/dist/naming/ownExports.js.map +1 -0
- package/dist/naming/packageLayout.d.ts +8 -0
- package/dist/naming/packageLayout.d.ts.map +1 -0
- package/dist/naming/packageLayout.js +57 -0
- package/dist/naming/packageLayout.js.map +1 -0
- package/dist/naming/testName.d.ts +11 -0
- package/dist/naming/testName.d.ts.map +1 -0
- package/dist/naming/testName.js +13 -0
- package/dist/naming/testName.js.map +1 -0
- package/dist/naming/words.d.ts +8 -0
- package/dist/naming/words.d.ts.map +1 -0
- package/dist/naming/words.js +21 -0
- package/dist/naming/words.js.map +1 -0
- package/dist/report/render.d.ts +1 -1
- package/dist/report/render.d.ts.map +1 -1
- package/dist/report/render.js +2 -2
- package/dist/report/render.js.map +1 -1
- package/dist/report/stale.d.ts +1 -1
- package/dist/report/stale.d.ts.map +1 -1
- package/dist/rules/biome.d.ts +1 -1
- package/dist/rules/biome.d.ts.map +1 -1
- package/dist/rules/biome.js +3 -3
- package/dist/rules/biome.js.map +1 -1
- package/dist/rules/built-in.d.ts +13 -1
- package/dist/rules/built-in.d.ts.map +1 -1
- package/dist/rules/built-in.js +24 -14
- package/dist/rules/built-in.js.map +1 -1
- package/dist/rules/comments/kinds.js +1 -1
- 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 +2 -2
- package/dist/rules/comments/max-per-file.js.map +1 -1
- package/dist/rules/comments/no-jsdoc.d.ts +1 -1
- package/dist/rules/comments/no-jsdoc.js +1 -1
- package/dist/rules/comments/no-jsdoc.js.map +1 -1
- package/dist/rules/comments/pattern-rule.d.ts +1 -1
- package/dist/rules/comments/pattern-rule.d.ts.map +1 -1
- package/dist/rules/comments/pattern-rule.js +1 -1
- package/dist/rules/comments/pattern-rule.js.map +1 -1
- package/dist/rules/comments/scan.d.ts +1 -1
- package/dist/rules/comments/scan.d.ts.map +1 -1
- package/dist/rules/comments/scan.js +1 -1
- package/dist/rules/comments/scan.js.map +1 -1
- package/dist/rules/files/folderNames.d.ts +5 -0
- package/dist/rules/files/folderNames.d.ts.map +1 -0
- package/dist/rules/files/folderNames.js +74 -0
- package/dist/rules/files/folderNames.js.map +1 -0
- package/dist/rules/files/namedAfterExport.d.ts +4 -0
- package/dist/rules/files/namedAfterExport.d.ts.map +1 -0
- package/dist/rules/files/namedAfterExport.js +76 -0
- package/dist/rules/files/namedAfterExport.js.map +1 -0
- package/dist/rules/files/otherNames.d.ts +5 -0
- package/dist/rules/files/otherNames.d.ts.map +1 -0
- package/dist/rules/files/otherNames.js +99 -0
- package/dist/rules/files/otherNames.js.map +1 -0
- package/dist/rules/imports/aliased.d.ts +1 -1
- package/dist/rules/imports/aliased.d.ts.map +1 -1
- package/dist/rules/imports/aliased.js +2 -2
- package/dist/rules/imports/aliased.js.map +1 -1
- package/dist/rules/imports/cycles.d.ts +1 -1
- package/dist/rules/imports/cycles.d.ts.map +1 -1
- package/dist/rules/imports/cycles.js +4 -4
- package/dist/rules/imports/cycles.js.map +1 -1
- package/dist/rules/imports/fences.d.ts +2 -2
- package/dist/rules/imports/fences.d.ts.map +1 -1
- package/dist/rules/imports/fences.js +3 -3
- package/dist/rules/imports/fences.js.map +1 -1
- package/dist/rules/imports/resolvable.d.ts +1 -1
- package/dist/rules/imports/resolvable.js +3 -3
- package/dist/rules/imports/resolvable.js.map +1 -1
- package/dist/rules/manifests-sorted.d.ts +1 -1
- package/dist/rules/manifests-sorted.d.ts.map +1 -1
- package/dist/rules/manifests-sorted.js +2 -2
- package/dist/rules/manifests-sorted.js.map +1 -1
- package/dist/rules/max-lines.d.ts +1 -1
- package/dist/rules/max-lines.js +1 -1
- package/dist/rules/max-lines.js.map +1 -1
- package/dist/rules/suppressions/biome/configs.d.ts +1 -1
- package/dist/rules/suppressions/biome/configs.d.ts.map +1 -1
- package/dist/rules/suppressions/biome/declarations.d.ts +1 -1
- package/dist/rules/suppressions/biome/declarations.d.ts.map +1 -1
- package/dist/rules/suppressions/biome/declarations.js +1 -1
- package/dist/rules/suppressions/biome/declarations.js.map +1 -1
- package/dist/rules/suppressions/biome/resolve.d.ts +1 -1
- package/dist/rules/suppressions/biome/resolve.d.ts.map +1 -1
- package/dist/rules/suppressions/biome/resolve.js +1 -1
- package/dist/rules/suppressions/biome/resolve.js.map +1 -1
- package/dist/rules/suppressions/biome-overrides.d.ts +1 -1
- package/dist/rules/suppressions/biome-overrides.js +4 -4
- 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/no-double-cast.d.ts +1 -1
- package/dist/rules/suppressions/no-double-cast.d.ts.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 -1
- package/dist/rules/suppressions/no-inline.d.ts.map +1 -1
- package/dist/rules/suppressions/no-inline.js +2 -2
- 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 +1 -1
- package/dist/rules/suppressions/stylesheet-comments.js.map +1 -1
- package/dist/rules/syntax.d.ts +1 -1
- package/dist/rules/syntax.d.ts.map +1 -1
- package/dist/rules/test-names/colocated.d.ts +4 -0
- package/dist/rules/test-names/colocated.d.ts.map +1 -0
- package/dist/rules/test-names/colocated.js +31 -0
- package/dist/rules/test-names/colocated.js.map +1 -0
- package/dist/rules/test-names/follow.d.ts +4 -0
- package/dist/rules/test-names/follow.d.ts.map +1 -0
- package/dist/rules/test-names/follow.js +66 -0
- package/dist/rules/test-names/follow.js.map +1 -0
- package/dist/rules/test-names/usesDom.d.ts +3 -0
- package/dist/rules/test-names/usesDom.d.ts.map +1 -0
- package/dist/rules/test-names/usesDom.js +18 -0
- package/dist/rules/test-names/usesDom.js.map +1 -0
- package/dist/vitest.d.ts +3 -1
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +11 -11
- package/dist/vitest.js.map +1 -1
- package/package.json +10 -2
- package/src/baseline/compare.ts +1 -1
- package/src/baseline/format.ts +2 -2
- package/src/baseline/legacy.ts +2 -2
- package/src/baseline/rewrite.ts +1 -1
- package/src/baseline/update.ts +1 -1
- package/src/cli/args.ts +1 -1
- package/src/cli/baseline.ts +8 -8
- package/src/cli/fix.ts +7 -7
- package/src/cli/lint.ts +4 -4
- package/src/cli/migrate.ts +9 -9
- package/src/cli/run-main.ts +2 -2
- package/src/cli/shrink.ts +5 -5
- package/src/cli.ts +7 -7
- package/src/config/decode.ts +2 -2
- package/src/config/load.ts +3 -3
- package/src/config/resolve.ts +6 -6
- package/src/config.ts +1 -1
- package/src/engine/baseline-file.ts +6 -6
- package/src/engine/evaluate.ts +3 -3
- package/src/engine/run-rules.ts +3 -3
- package/src/engine/session.ts +6 -6
- package/src/engine/violation.ts +2 -2
- package/src/exceptions/registry.ts +2 -2
- package/src/git/base.ts +1 -1
- package/src/git/command.ts +1 -1
- package/src/git/history.ts +1 -1
- package/src/imports/departures.ts +2 -2
- package/src/imports/fences/evaluate.ts +2 -2
- package/src/imports/fences/match.ts +2 -2
- package/src/imports/fences/policy.ts +2 -2
- package/src/imports/fences/reach.ts +2 -2
- package/src/imports/fences/vocabulary.ts +1 -1
- package/src/imports/generated.ts +2 -2
- package/src/imports/graph.ts +2 -2
- package/src/imports/resolve.ts +1 -1
- package/src/imports/workspace.ts +1 -1
- package/src/index.ts +3 -3
- package/src/inventory/collect.ts +1 -1
- package/src/manifests/sorted.ts +3 -3
- package/src/naming/exportFits.ts +21 -0
- package/src/naming/mainExport.ts +11 -0
- package/src/naming/ownExports.ts +95 -0
- package/src/naming/packageLayout.ts +75 -0
- package/src/naming/testName.ts +25 -0
- package/src/naming/words.ts +28 -0
- package/src/report/render.ts +3 -3
- package/src/report/stale.ts +3 -3
- package/src/rules/biome.ts +3 -3
- package/src/rules/built-in.ts +24 -14
- package/src/rules/comments/kinds.ts +1 -1
- package/src/rules/comments/max-per-file.ts +2 -2
- package/src/rules/comments/no-jsdoc.ts +1 -1
- package/src/rules/comments/pattern-rule.ts +1 -1
- package/src/rules/comments/scan.ts +2 -2
- package/src/rules/files/folderNames.ts +92 -0
- package/src/rules/files/namedAfterExport.ts +87 -0
- package/src/rules/files/otherNames.ts +118 -0
- package/src/rules/imports/aliased.ts +2 -2
- package/src/rules/imports/cycles.ts +4 -4
- package/src/rules/imports/fences.ts +4 -4
- package/src/rules/imports/resolvable.ts +3 -3
- package/src/rules/manifests-sorted.ts +2 -2
- package/src/rules/max-lines.ts +1 -1
- package/src/rules/suppressions/biome/configs.ts +1 -1
- package/src/rules/suppressions/biome/declarations.ts +1 -1
- package/src/rules/suppressions/biome/resolve.ts +2 -2
- package/src/rules/suppressions/biome-overrides.ts +4 -4
- package/src/rules/suppressions/directives.ts +1 -1
- package/src/rules/suppressions/no-double-cast.ts +2 -2
- package/src/rules/suppressions/no-inline.ts +2 -2
- package/src/rules/suppressions/stylesheet-comments.ts +1 -1
- package/src/rules/syntax.ts +1 -1
- package/src/rules/test-names/colocated.ts +34 -0
- package/src/rules/test-names/follow.ts +78 -0
- package/src/rules/test-names/usesDom.ts +22 -0
- package/src/vitest.ts +14 -11
package/src/cli/args.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { Result } from "effect";
|
|
3
|
-
import type { WarningDetail } from "
|
|
3
|
+
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 }
|
package/src/cli/baseline.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { Console, Effect, type FileSystem } from "effect";
|
|
3
|
-
import type { BaselineEntry } from "
|
|
4
|
-
import { rewriteBaseline } from "
|
|
5
|
-
import { adopt, type Pruned, prune, type Scope } from "
|
|
6
|
-
import { openSession, type Session } from "
|
|
7
|
-
import { applyRegistry } from "
|
|
8
|
-
import { SetupFailure } from "
|
|
9
|
-
import { writeText } from "
|
|
10
|
-
import { plural } from "
|
|
3
|
+
import type { BaselineEntry } from "#baseline/format.ts";
|
|
4
|
+
import { rewriteBaseline } from "#baseline/rewrite.ts";
|
|
5
|
+
import { adopt, type Pruned, prune, type Scope } from "#baseline/update.ts";
|
|
6
|
+
import { openSession, type Session } from "#engine/session.ts";
|
|
7
|
+
import { applyRegistry } from "#exceptions/registry.ts";
|
|
8
|
+
import { SetupFailure } from "#failure.ts";
|
|
9
|
+
import { writeText } from "#inventory/filesystem.ts";
|
|
10
|
+
import { plural } from "#report/plural.ts";
|
|
11
11
|
|
|
12
12
|
const save = (session: Session, entries: readonly BaselineEntry[]): Effect.Effect<void, SetupFailure, FileSystem.FileSystem> =>
|
|
13
13
|
Effect.mapError(
|
package/src/cli/fix.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { relative } from "node:path";
|
|
2
2
|
import { Console, Effect, FileSystem } from "effect";
|
|
3
|
-
import { biomeReport, type Report } from "
|
|
4
|
-
import { loadConfig } from "
|
|
5
|
-
import { SetupFailure } from "
|
|
6
|
-
import { posix } from "
|
|
7
|
-
import { walk } from "
|
|
8
|
-
import { sortManifests } from "
|
|
9
|
-
import { plural } from "
|
|
3
|
+
import { biomeReport, type Report } from "#biome/report.ts";
|
|
4
|
+
import { loadConfig } from "#config/load.ts";
|
|
5
|
+
import { SetupFailure } from "#failure.ts";
|
|
6
|
+
import { posix } from "#inventory/ignore-scope.ts";
|
|
7
|
+
import { walk } from "#inventory/walk.ts";
|
|
8
|
+
import { sortManifests } from "#manifests/sorted.ts";
|
|
9
|
+
import { plural } from "#report/plural.ts";
|
|
10
10
|
|
|
11
11
|
export const MAX_FIX_ROUNDS = 5;
|
|
12
12
|
|
package/src/cli/lint.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Console, Effect, type FileSystem } from "effect";
|
|
2
|
-
import { evaluate, passes } from "
|
|
3
|
-
import { openSession } from "
|
|
4
|
-
import { GateFailed, type SetupFailure } from "
|
|
5
|
-
import { render, type WarningDetail } from "
|
|
2
|
+
import { evaluate, passes } from "#engine/evaluate.ts";
|
|
3
|
+
import { openSession } from "#engine/session.ts";
|
|
4
|
+
import { GateFailed, type SetupFailure } from "#failure.ts";
|
|
5
|
+
import { render, type WarningDetail } from "#report/render.ts";
|
|
6
6
|
|
|
7
7
|
export const lint = (
|
|
8
8
|
cwd: string,
|
package/src/cli/migrate.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { Console, Effect, FileSystem } from "effect";
|
|
3
|
-
import { encodeBaseline } from "
|
|
4
|
-
import { convertLegacy, decodeLegacyBaseline, LEGACY_BASELINE } from "
|
|
5
|
-
import { loadConfig } from "
|
|
6
|
-
import { validOrFail } from "
|
|
7
|
-
import { readInput } from "
|
|
8
|
-
import { scan } from "
|
|
9
|
-
import { SetupFailure } from "
|
|
10
|
-
import { writeText } from "
|
|
11
|
-
import { plural } from "
|
|
3
|
+
import { encodeBaseline } from "#baseline/format.ts";
|
|
4
|
+
import { convertLegacy, decodeLegacyBaseline, LEGACY_BASELINE } from "#baseline/legacy.ts";
|
|
5
|
+
import { loadConfig } from "#config/load.ts";
|
|
6
|
+
import { validOrFail } from "#decoded.ts";
|
|
7
|
+
import { readInput } from "#engine/baseline-file.ts";
|
|
8
|
+
import { scan } from "#engine/session.ts";
|
|
9
|
+
import { SetupFailure } from "#failure.ts";
|
|
10
|
+
import { writeText } from "#inventory/filesystem.ts";
|
|
11
|
+
import { plural } from "#report/plural.ts";
|
|
12
12
|
|
|
13
13
|
export const migrateBaseline = (
|
|
14
14
|
cwd: string,
|
package/src/cli/run-main.ts
CHANGED
|
@@ -5,8 +5,8 @@ import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
|
|
|
5
5
|
import * as NodePath from "@effect/platform-node/NodePath";
|
|
6
6
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
7
7
|
import { Cause, Console, Effect, Exit, type FileSystem, Layer, Runtime } from "effect";
|
|
8
|
-
import { SetupFailure } from "
|
|
9
|
-
import type { Git } from "
|
|
8
|
+
import { SetupFailure } from "#failure.ts";
|
|
9
|
+
import type { Git } from "#git/command.ts";
|
|
10
10
|
|
|
11
11
|
const INTERRUPTED = 130;
|
|
12
12
|
const COULD_NOT_RUN = 2;
|
package/src/cli/shrink.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Console, Effect, type FileSystem } from "effect";
|
|
2
|
-
import type { Scope } from "
|
|
3
|
-
import type { SetupFailure } from "
|
|
4
|
-
import { resolveBase } from "
|
|
5
|
-
import type { Git } from "
|
|
6
|
-
import { changesSince } from "
|
|
2
|
+
import type { Scope } from "#baseline/update.ts";
|
|
3
|
+
import type { SetupFailure } from "#failure.ts";
|
|
4
|
+
import { resolveBase } from "#git/base.ts";
|
|
5
|
+
import type { Git } from "#git/command.ts";
|
|
6
|
+
import { changesSince } from "#git/history.ts";
|
|
7
7
|
import { shrinkBaseline } from "./baseline.ts";
|
|
8
8
|
|
|
9
9
|
const followedMoves = (root: string, against: string | undefined): Effect.Effect<Scope, SetupFailure, Git> =>
|
package/src/cli.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { Console, Effect } from "effect";
|
|
4
|
-
import { parseCommand, USAGE } from "
|
|
5
|
-
import { writeBaseline } from "
|
|
6
|
-
import { fix } from "
|
|
7
|
-
import { lint } from "
|
|
8
|
-
import { migrateBaseline } from "
|
|
9
|
-
import { runMain } from "
|
|
10
|
-
import { pruneBaseline, tightenBaseline } from "
|
|
4
|
+
import { parseCommand, USAGE } from "#cli/args.ts";
|
|
5
|
+
import { writeBaseline } from "#cli/baseline.ts";
|
|
6
|
+
import { fix } from "#cli/fix.ts";
|
|
7
|
+
import { lint } from "#cli/lint.ts";
|
|
8
|
+
import { migrateBaseline } from "#cli/migrate.ts";
|
|
9
|
+
import { runMain } from "#cli/run-main.ts";
|
|
10
|
+
import { pruneBaseline, tightenBaseline } from "#cli/shrink.ts";
|
|
11
11
|
import { SetupFailure } from "./failure.ts";
|
|
12
12
|
|
|
13
13
|
const parsed = parseCommand(process.argv.slice(2));
|
package/src/config/decode.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { type Decoded, decodeWith } from "
|
|
3
|
-
import type { Rule } from "
|
|
2
|
+
import { type Decoded, decodeWith } from "#decoded.ts";
|
|
3
|
+
import type { Rule } from "#rule.ts";
|
|
4
4
|
|
|
5
5
|
const isRule = (value: unknown): value is Rule =>
|
|
6
6
|
typeof value === "object"
|
package/src/config/load.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { dirname, resolve } from "node:path";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import { Effect, FileSystem } from "effect";
|
|
4
|
-
import { validOrFail } from "
|
|
5
|
-
import { SetupFailure } from "
|
|
6
|
-
import type { InventoryScope } from "
|
|
4
|
+
import { validOrFail } from "#decoded.ts";
|
|
5
|
+
import { SetupFailure } from "#failure.ts";
|
|
6
|
+
import type { InventoryScope } from "#inventory/collect.ts";
|
|
7
7
|
import { type ConfigInput, decodeConfig } from "./decode.ts";
|
|
8
8
|
import { CONFIG_FILE } from "./file.ts";
|
|
9
9
|
import { type ResolvedRules, resolveRules } from "./resolve.ts";
|
package/src/config/resolve.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import type { Level } from "
|
|
3
|
-
import type { Decoded } from "
|
|
4
|
-
import type { ActiveRule } from "
|
|
5
|
-
import type { RuleIndex } from "
|
|
6
|
-
import type { Rule } from "
|
|
7
|
-
import { builtInRules } from "
|
|
2
|
+
import type { Level } from "#config.ts";
|
|
3
|
+
import type { Decoded } from "#decoded.ts";
|
|
4
|
+
import type { ActiveRule } from "#engine/run-rules.ts";
|
|
5
|
+
import type { RuleIndex } from "#engine/violation.ts";
|
|
6
|
+
import type { Rule } from "#rule.ts";
|
|
7
|
+
import { builtInRules } from "#rules/built-in.ts";
|
|
8
8
|
import type { ConfigInput } from "./decode.ts";
|
|
9
9
|
|
|
10
10
|
export interface ResolvedRules extends RuleIndex {
|
package/src/config.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { Effect, type FileSystem } from "effect";
|
|
3
|
-
import { type BaselineEntry, decodeBaseline } from "
|
|
4
|
-
import { LEGACY_BASELINE } from "
|
|
5
|
-
import type { ResolvedConfig } from "
|
|
6
|
-
import { validOrFail } from "
|
|
7
|
-
import { SetupFailure } from "
|
|
8
|
-
import { readOptionalText } from "
|
|
3
|
+
import { type BaselineEntry, decodeBaseline } from "#baseline/format.ts";
|
|
4
|
+
import { LEGACY_BASELINE } from "#baseline/legacy.ts";
|
|
5
|
+
import type { ResolvedConfig } from "#config/load.ts";
|
|
6
|
+
import { validOrFail } from "#decoded.ts";
|
|
7
|
+
import { SetupFailure } from "#failure.ts";
|
|
8
|
+
import { readOptionalText } from "#inventory/filesystem.ts";
|
|
9
9
|
|
|
10
10
|
export interface BaselineFile {
|
|
11
11
|
readonly entries: readonly BaselineEntry[];
|
package/src/engine/evaluate.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { applyBaseline, type Regression, type StaleBaselineEntry } from "
|
|
2
|
-
import type { BaselineEntry } from "
|
|
3
|
-
import { applyRegistry, type RegistryEntry, type StaleRegistryEntry } from "
|
|
1
|
+
import { applyBaseline, type Regression, type StaleBaselineEntry } from "#baseline/compare.ts";
|
|
2
|
+
import type { BaselineEntry } from "#baseline/format.ts";
|
|
3
|
+
import { applyRegistry, type RegistryEntry, type StaleRegistryEntry } from "#exceptions/registry.ts";
|
|
4
4
|
import { byLocation, type RuleIndex, type Violation } from "./violation.ts";
|
|
5
5
|
|
|
6
6
|
export interface Outcome {
|
package/src/engine/run-rules.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isAbsolute, relative } from "node:path";
|
|
2
2
|
import { Effect } from "effect";
|
|
3
|
-
import { SetupFailure } from "
|
|
4
|
-
import { posix } from "
|
|
5
|
-
import type { Finding, Findings, RuleInputs } from "
|
|
3
|
+
import { SetupFailure } from "#failure.ts";
|
|
4
|
+
import { posix } from "#inventory/ignore-scope.ts";
|
|
5
|
+
import type { Finding, Findings, RuleInputs } from "#rule.ts";
|
|
6
6
|
import type { ActiveLevel, Violation } from "./violation.ts";
|
|
7
7
|
|
|
8
8
|
export interface ActiveRule {
|
package/src/engine/session.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import { Effect, type FileSystem } from "effect";
|
|
3
|
-
import { loadConfig, type ResolvedConfig } from "
|
|
4
|
-
import { validOrFail } from "
|
|
5
|
-
import { decodeRegistry, type RegistryEntry } from "
|
|
6
|
-
import { SetupFailure } from "
|
|
7
|
-
import { collectInventory, type Inventory } from "
|
|
8
|
-
import { type FilesystemFailure, readOptionalText } from "
|
|
3
|
+
import { loadConfig, type ResolvedConfig } from "#config/load.ts";
|
|
4
|
+
import { validOrFail } from "#decoded.ts";
|
|
5
|
+
import { decodeRegistry, type RegistryEntry } from "#exceptions/registry.ts";
|
|
6
|
+
import { SetupFailure } from "#failure.ts";
|
|
7
|
+
import { collectInventory, type Inventory } from "#inventory/collect.ts";
|
|
8
|
+
import { type FilesystemFailure, readOptionalText } from "#inventory/filesystem.ts";
|
|
9
9
|
import { type BaselineFile, readBaseline, readInput } from "./baseline-file.ts";
|
|
10
10
|
import { runRules } from "./run-rules.ts";
|
|
11
11
|
import type { Violation } from "./violation.ts";
|
package/src/engine/violation.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { type Decoded, decodeWith } from "
|
|
3
|
-
import { type RuleIndex, registrable, unusedEntryProblem, type Violation } from "
|
|
2
|
+
import { type Decoded, decodeWith } from "#decoded.ts";
|
|
3
|
+
import { type RuleIndex, registrable, unusedEntryProblem, type Violation } from "#engine/violation.ts";
|
|
4
4
|
|
|
5
5
|
const RegistryEntry = Schema.Struct({
|
|
6
6
|
file: Schema.NonEmptyString,
|
package/src/git/base.ts
CHANGED
package/src/git/command.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Stream } from "effect";
|
|
2
2
|
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
|
3
|
-
import { SetupFailure } from "
|
|
3
|
+
import { SetupFailure } from "#failure.ts";
|
|
4
4
|
|
|
5
5
|
export interface GitResult {
|
|
6
6
|
readonly code: number;
|
package/src/git/history.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { posix } from "node:path";
|
|
3
|
-
import type { RuleInputs } from "
|
|
4
|
-
import { parse } from "
|
|
3
|
+
import type { RuleInputs } from "#rule.ts";
|
|
4
|
+
import { parse } from "#rules/syntax.ts";
|
|
5
5
|
import type { ImportRequest } from "./extract.ts";
|
|
6
6
|
import { type Project, projectsFor } from "./projects.ts";
|
|
7
7
|
import { resolveImport } from "./resolve.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { ImportEdge, ImportGraph } from "#imports/graph.ts";
|
|
2
|
+
import type { Finding } from "#rule.ts";
|
|
3
3
|
import { type Compiler, compile, type Matcher } from "./match.ts";
|
|
4
4
|
import type { Fence } from "./model.ts";
|
|
5
5
|
import { labelOf, outgoing, reachedFrom } from "./reach.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { builtinName, type Endpoint, packageNameOf } from "
|
|
2
|
-
import { packageOf, type WorkspacePackage } from "
|
|
1
|
+
import { builtinName, type Endpoint, packageNameOf } from "#imports/resolve.ts";
|
|
2
|
+
import { packageOf, type WorkspacePackage } from "#imports/workspace.ts";
|
|
3
3
|
import type { Selector } from "./model.ts";
|
|
4
4
|
|
|
5
5
|
export interface PolicyScope {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ImportEdge } from "
|
|
2
|
-
import { type Endpoint, packageNameOf } from "
|
|
1
|
+
import type { ImportEdge } from "#imports/graph.ts";
|
|
2
|
+
import { type Endpoint, packageNameOf } from "#imports/resolve.ts";
|
|
3
3
|
import { type CompiledFence, compileFence, type FenceGraph } from "./evaluate.ts";
|
|
4
4
|
import type { PolicyScope } from "./match.ts";
|
|
5
5
|
import type { Chain, ExampleStep, Fence } from "./model.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ImportEdge } from "
|
|
2
|
-
import type { Endpoint } from "
|
|
1
|
+
import type { ImportEdge } from "#imports/graph.ts";
|
|
2
|
+
import type { Endpoint } from "#imports/resolve.ts";
|
|
3
3
|
import type { Matcher } from "./match.ts";
|
|
4
4
|
|
|
5
5
|
export interface Reached {
|
package/src/imports/generated.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { posix } from "node:path";
|
|
3
3
|
import { promisify } from "node:util";
|
|
4
|
-
import { emptyScope, type IgnoreScope, verdictFor, withIgnoreFile } from "
|
|
5
|
-
import type { RuleInputs } from "
|
|
4
|
+
import { emptyScope, type IgnoreScope, verdictFor, withIgnoreFile } from "#inventory/ignore-scope.ts";
|
|
5
|
+
import type { RuleInputs } from "#rule.ts";
|
|
6
6
|
import type { ImportGraph, UnresolvedImport } from "./graph.ts";
|
|
7
7
|
|
|
8
8
|
type Reader = Pick<RuleInputs, "readText" | "root">;
|
package/src/imports/graph.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { join, posix } from "node:path";
|
|
3
|
-
import type { RuleInputs, SourceFile } from "
|
|
4
|
-
import { parse } from "
|
|
3
|
+
import type { RuleInputs, SourceFile } from "#rule.ts";
|
|
4
|
+
import { parse } from "#rules/syntax.ts";
|
|
5
5
|
import { ambientModules } from "./ambient.ts";
|
|
6
6
|
import { type ImportKind, type ImportRequest, importsOf } from "./extract.ts";
|
|
7
7
|
import { projectsFor } from "./projects.ts";
|
package/src/imports/resolve.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { realpathSync } from "node:fs";
|
|
|
2
2
|
import { isBuiltin } from "node:module";
|
|
3
3
|
import { dirname, join, relative } from "node:path";
|
|
4
4
|
import ts from "typescript";
|
|
5
|
-
import { posix } from "
|
|
5
|
+
import { posix } from "#inventory/ignore-scope.ts";
|
|
6
6
|
import type { Ambient } from "./ambient.ts";
|
|
7
7
|
import type { ImportRequest } from "./extract.ts";
|
|
8
8
|
import type { Project } from "./projects.ts";
|
package/src/imports/workspace.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
export { fence } from "#imports/fences/dsl.ts";
|
|
2
|
+
export type { Chain, ExampleStep, Examples, External, Fence, Target } from "#imports/fences/model.ts";
|
|
3
|
+
export { anyOf, anything, external, files, folders, modules, packages, scopes, workspace } from "#imports/fences/selectors.ts";
|
|
1
4
|
export type { BuiltInRules, Level, QualityConfig, RuleSetting, RuleSettings } from "./config.ts";
|
|
2
5
|
export { defineConfig } from "./config.ts";
|
|
3
|
-
export { fence } from "./imports/fences/dsl.ts";
|
|
4
|
-
export type { Chain, ExampleStep, Examples, External, Fence, Target } from "./imports/fences/model.ts";
|
|
5
|
-
export { anyOf, anything, external, files, folders, modules, packages, scopes, workspace } from "./imports/fences/selectors.ts";
|
|
6
6
|
export type { Configured, Finding, Findings, Rule, RuleContext, RuleInputs, SourceFile } from "./rule.ts";
|
|
7
7
|
export { defineRule } from "./rule.ts";
|
|
8
8
|
export type { StandardIssue, StandardResult, StandardSchemaV1 } from "./standard-schema.ts";
|
package/src/inventory/collect.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join, relative } from "node:path";
|
|
2
2
|
import { Effect, FileSystem } from "effect";
|
|
3
3
|
import ignore from "ignore";
|
|
4
|
-
import type { SourceFile } from "
|
|
4
|
+
import type { SourceFile } from "#rule.ts";
|
|
5
5
|
import { FilesystemFailure, orWhenAbsent, readRequiredText } from "./filesystem.ts";
|
|
6
6
|
import { posix } from "./ignore-scope.ts";
|
|
7
7
|
import { scopeAbove, walk } from "./walk.ts";
|
package/src/manifests/sorted.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { basename, join, relative } from "node:path";
|
|
2
2
|
import { Effect, FileSystem } from "effect";
|
|
3
3
|
import { sortPackageJson } from "sort-package-json";
|
|
4
|
-
import { FilesystemFailure } from "
|
|
5
|
-
import { posix } from "
|
|
6
|
-
import { walk } from "
|
|
4
|
+
import { FilesystemFailure } from "#inventory/filesystem.ts";
|
|
5
|
+
import { posix } from "#inventory/ignore-scope.ts";
|
|
6
|
+
import { walk } from "#inventory/walk.ts";
|
|
7
7
|
|
|
8
8
|
export type Sorting = { readonly _tag: "Invalid" } | { readonly _tag: "Sorted" } | { readonly _tag: "Unsorted"; readonly sorted: string };
|
|
9
9
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CAMEL, isUpper, PASCAL, sameWord, wordsOf } from "#naming/words.ts";
|
|
2
|
+
|
|
3
|
+
function restIsFolders(rest: readonly string[], folders: readonly string[]): boolean {
|
|
4
|
+
const folderWords = folders.flatMap(wordsOf);
|
|
5
|
+
return rest.every((word) => folderWords.some((folder) => sameWord(word, folder)));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function exportFits(name: string, stem: string, folders: readonly string[]): boolean {
|
|
9
|
+
if (!(CAMEL.test(stem) || PASCAL.test(stem)) || isUpper(stem) !== isUpper(name)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const named = wordsOf(name);
|
|
13
|
+
const filed = wordsOf(stem);
|
|
14
|
+
for (let start = 0; start + filed.length <= named.length; start += 1) {
|
|
15
|
+
const matches = filed.every((word, offset) => word === named[start + offset]);
|
|
16
|
+
if (matches && restIsFolders([...named.slice(0, start), ...named.slice(start + filed.length)], folders)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OwnExport } from "#naming/ownExports.ts";
|
|
2
|
+
|
|
3
|
+
export function mainExport(exports: readonly OwnExport[]): OwnExport | undefined {
|
|
4
|
+
const values = exports.filter((entry) => entry.kind === "value");
|
|
5
|
+
const types = exports.filter((entry) => entry.kind === "type");
|
|
6
|
+
const [value] = values;
|
|
7
|
+
if (values.length === 1 && value !== undefined && types.every((type) => type.name.startsWith(value.name))) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
return values.length === 0 && types.length === 1 ? types[0] : undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export interface OwnExport {
|
|
4
|
+
readonly constant: boolean;
|
|
5
|
+
readonly kind: "type" | "value";
|
|
6
|
+
readonly name: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const CONSTANT_CASE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/u;
|
|
10
|
+
|
|
11
|
+
const PRIMITIVE_LITERALS: ReadonlySet<ts.SyntaxKind> = new Set([
|
|
12
|
+
ts.SyntaxKind.BigIntLiteral,
|
|
13
|
+
ts.SyntaxKind.FalseKeyword,
|
|
14
|
+
ts.SyntaxKind.NoSubstitutionTemplateLiteral,
|
|
15
|
+
ts.SyntaxKind.NumericLiteral,
|
|
16
|
+
ts.SyntaxKind.StringLiteral,
|
|
17
|
+
ts.SyntaxKind.TrueKeyword,
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
function isPrimitiveLiteral(node: ts.Expression | undefined): boolean {
|
|
21
|
+
if (node === undefined) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (ts.isPrefixUnaryExpression(node)) {
|
|
25
|
+
return isPrimitiveLiteral(node.operand);
|
|
26
|
+
}
|
|
27
|
+
return PRIMITIVE_LITERALS.has(node.kind);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isExported(statement: ts.Statement): boolean {
|
|
31
|
+
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;
|
|
32
|
+
const exported = modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
33
|
+
const isDefault = modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) ?? false;
|
|
34
|
+
return exported && !isDefault;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function variables(statement: ts.VariableStatement): readonly OwnExport[] {
|
|
38
|
+
const constant = (statement.declarationList.flags & ts.NodeFlags.Const) !== 0;
|
|
39
|
+
return statement.declarationList.declarations.flatMap((declaration) =>
|
|
40
|
+
ts.isIdentifier(declaration.name)
|
|
41
|
+
? [
|
|
42
|
+
{
|
|
43
|
+
constant: constant && (CONSTANT_CASE.test(declaration.name.text) || isPrimitiveLiteral(declaration.initializer)),
|
|
44
|
+
kind: "value" as const,
|
|
45
|
+
name: declaration.name.text,
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
: [],
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function declared(statement: ts.Statement): readonly OwnExport[] {
|
|
53
|
+
if (ts.isVariableStatement(statement)) {
|
|
54
|
+
return variables(statement);
|
|
55
|
+
}
|
|
56
|
+
if (ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement)) {
|
|
57
|
+
return [{ constant: false, kind: "type", name: statement.name.text }];
|
|
58
|
+
}
|
|
59
|
+
const named =
|
|
60
|
+
ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement) || ts.isModuleDeclaration(statement)
|
|
61
|
+
? statement.name
|
|
62
|
+
: undefined;
|
|
63
|
+
return named !== undefined && ts.isIdentifier(named) ? [{ constant: false, kind: "value", name: named.text }] : [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function locals(source: ts.SourceFile): ReadonlyMap<string, OwnExport> {
|
|
67
|
+
const all = source.statements.flatMap(declared);
|
|
68
|
+
return new Map(all.map((local) => [local.name, local]));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function listed(statement: ts.ExportDeclaration, known: ReadonlyMap<string, OwnExport>): readonly OwnExport[] {
|
|
72
|
+
const clause = statement.exportClause;
|
|
73
|
+
if (statement.moduleSpecifier !== undefined || clause === undefined || !ts.isNamedExports(clause)) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
return clause.elements.flatMap((element) => {
|
|
77
|
+
const name = element.name.text;
|
|
78
|
+
const local = known.get((element.propertyName ?? element.name).text);
|
|
79
|
+
if (name === "default" || local === undefined) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
const typeOnly = statement.isTypeOnly || element.isTypeOnly;
|
|
83
|
+
return [{ constant: local.constant, kind: typeOnly ? ("type" as const) : local.kind, name }];
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function ownExports(source: ts.SourceFile): readonly OwnExport[] {
|
|
88
|
+
const known = locals(source);
|
|
89
|
+
return source.statements.flatMap((statement) => {
|
|
90
|
+
if (ts.isExportDeclaration(statement)) {
|
|
91
|
+
return listed(statement, known);
|
|
92
|
+
}
|
|
93
|
+
return isExported(statement) ? declared(statement) : [];
|
|
94
|
+
});
|
|
95
|
+
}
|