Skip to content

Conversation

@RobinTail
Copy link
Owner

@RobinTail RobinTail commented Oct 4, 2025

Need it for #2980

Summary by CodeRabbit

  • New Features

    • Migration rule name now auto-matches the current major version, eliminating manual updates when versions change.
    • Plugin exports adapt dynamically to the detected version for smoother upgrades.
  • Chores

    • Build configuration now injects the package version into the environment to power automatic versioning.
  • Tests

    • Test suite updated to use dynamic imports and environment stubs to validate version-aware behavior.

@RobinTail RobinTail added the enhancement New feature or request label Oct 4, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 4, 2025

Walkthrough

Tests and plugin code were updated to use a dynamically computed ESLint rule key based on TSDOWN_VERSION. The test now stubs the env and dynamically imports the rule module. The plugin exports rules with a computed key. The build config defines the env variable from package.json.

Changes

Cohort / File(s) Summary
Tests: dynamic import and env stub
migration/index.spec.ts
Moves rule import into an async describe with dynamic import, stubs process.env via vi using package.json version, initializes ruleName/theRule post-import, keeps existing test cases.
Plugin: dynamic rule key/export
migration/index.ts
Computes ruleName from TSDOWN_VERSION, defines theRule, exports rules using computed key: { [ruleName]: theRule } with type assertion; removes hardcoded v25 export.
Build config: define env from manifest
migration/tsdown.config.ts
Imports manifest JSON and defines process.env.TSDOWN_VERSION to manifest.version in defineConfig.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Tester as Test Runner (vitest)
  participant Env as vi.stubEnv
  participant Mod as migration/index.ts
  participant ESLint as RuleTester

  Tester->>Env: stub process.env.TSDOWN_VERSION = manifest.version
  note over Env: Ensures version available at import time
  Tester->>Mod: dynamic import()
  Mod->>Mod: compute ruleName from TSDOWN_VERSION (major)
  Mod->>Tester: export rules { [ruleName]: theRule }
  Tester->>ESLint: tester.run(ruleName, theRule, cases)
  ESLint-->>Tester: results (valid/invalid as specified)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Removing DependsOnMethod #2938 — Modifies the same migration/index.ts and tests to add a v26 migration rule; intersects with this PR’s dynamic rule-key/export changes.

Suggested labels

refactoring

Poem

I twitch my whiskers at versioned breeze,
A rule hops names with env-set keys.
From package page to tester’s burrow,
The import jumps—no need to furrow.
Carrots counted: v? we see—
Dynamic nibbles, linting free! 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely describes the primary change in this pull request, which is making the ruleName dynamic in the migration module. It directly references the main enhancement without extraneous or vague language. Reviewers can immediately understand the focus of the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dynamic-ruleName

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coveralls-official
Copy link

Coverage Status

coverage: 100.0%. remained the same
when pulling 73c79e5 on dynamic-ruleName
into e5da940 on master.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
migration/index.spec.ts (1)

13-17: Refactor async setup to beforeAll instead of async describe.

Async describe callbacks are discouraged in testing frameworks. The dynamic import and environment setup should occur in beforeAll to follow best practices.

Apply this diff to refactor:

-describe("Migration", async () => {
-  vi.stubEnv("TSDOWN_VERSION", manifest.version);
-  const { default: migration } = await import("./index.ts");
-  const ruleName = `v${manifest.version.split(".")[0]}`;
-  const theRule = migration.rules[ruleName as keyof typeof migration.rules];
+describe("Migration", () => {
+  let migration: Awaited<ReturnType<typeof import("./index.ts")>>["default"];
+  let ruleName: string;
+  let theRule: ReturnType<typeof import("./index.ts")>["default"]["rules"][string];
+
+  beforeAll(async () => {
+    vi.stubEnv("TSDOWN_VERSION", manifest.version);
+    const imported = await import("./index.ts");
+    migration = imported.default;
+    ruleName = `v${manifest.version.split(".")[0]}`;
+    theRule = migration.rules[ruleName as keyof typeof migration.rules];
+  });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5da940 and 73c79e5.

📒 Files selected for processing (3)
  • migration/index.spec.ts (1 hunks)
  • migration/index.ts (2 hunks)
  • migration/tsdown.config.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-29T06:00:10.793Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2974
File: express-zod-api/src/zts-helpers.ts:2-3
Timestamp: 2025-09-29T06:00:10.793Z
Learning: tsdown handles module resolution and bundling independently of TypeScript's native compilation settings like rewriteRelativeImportExtensions, making such TypeScript emit-related configuration unnecessary when using tsdown for builds.

Applied to files:

  • migration/tsdown.config.ts
🔇 Additional comments (2)
migration/tsdown.config.ts (1)

2-2: LGTM! Clean manifest integration.

The import attributes syntax and define block are correctly structured. The double-quoted string interpolation ensures tsdown replaces process.env.TSDOWN_VERSION with a proper string literal at build time.

Also applies to: 9-11

migration/index.ts (1)

96-96: Dynamic rule export key format validated ruleName derives from manifest.version.split('.')[0] and migration/package.json version matches semver, ensuring valid v<number> keys.

@RobinTail RobinTail merged commit 87745a6 into master Oct 4, 2025
13 checks passed
@RobinTail RobinTail deleted the dynamic-ruleName branch October 4, 2025 07:51
@RobinTail RobinTail added refactoring The better way to achieve the same result and removed enhancement New feature or request labels Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring The better way to achieve the same result

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants