Skip to content

Commit 87745a6

Browse files
authored
Dynamic ruleName for migration (#2987)
Need it for #2980 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e5da940 commit 87745a6

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

migration/index.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { RuleTester } from "@typescript-eslint/rule-tester";
2-
import migration from "./index.ts";
32
import parser from "@typescript-eslint/parser";
43
import manifest from "./package.json" with { type: "json" };
54

@@ -11,10 +10,12 @@ const tester = new RuleTester({
1110
languageOptions: { parser },
1211
});
1312

14-
const ruleName = `v${manifest.version.split(".")[0]}`;
15-
const theRule = migration.rules[ruleName as keyof typeof migration.rules];
13+
describe("Migration", async () => {
14+
vi.stubEnv("TSDOWN_VERSION", manifest.version);
15+
const { default: migration } = await import("./index.ts");
16+
const ruleName = `v${manifest.version.split(".")[0]}`;
17+
const theRule = migration.rules[ruleName as keyof typeof migration.rules];
1618

17-
describe("Migration", () => {
1819
test("should consist of one rule being the major version of the package", () => {
1920
expect(migration.rules).toHaveProperty(ruleName);
2021
expect(migration).toMatchSnapshot();

migration/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ const listen = <
3838
{},
3939
);
4040

41-
const v25 = ESLintUtils.RuleCreator.withoutDocs({
41+
// eslint-disable-next-line no-restricted-syntax -- substituted by TSDOWN and vitest
42+
const ruleName = `v${process.env.TSDOWN_VERSION!.split(".")[0]}`;
43+
44+
const theRule = ESLintUtils.RuleCreator.withoutDocs({
4245
meta: {
4346
type: "problem",
4447
fixable: "code",
@@ -90,5 +93,5 @@ const v25 = ESLintUtils.RuleCreator.withoutDocs({
9093
});
9194

9295
export default {
93-
rules: { v25 },
96+
rules: { [ruleName]: theRule } as Record<`v${number}`, typeof theRule>,
9497
} satisfies TSESLint.Linter.Plugin;

migration/tsdown.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { defineConfig } from "tsdown";
2+
import manifest from "./package.json" with { type: "json" };
23

34
export default defineConfig({
45
entry: "index.ts",
56
minify: true,
67
skipNodeModulesBundle: true,
78
attw: { profile: "esmOnly", level: "error" },
9+
define: {
10+
"process.env.TSDOWN_VERSION": `"${manifest.version}"`, // used by ruleName
11+
},
812
});

0 commit comments

Comments
 (0)