Skip to content

Commit b27601e

Browse files
committed
test(lint): name the cycle rule once and note the second test's narrowed config
1 parent 383c7ee commit b27601e

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎packages/cli/test/import-cycle-lint.test.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { afterAll, describe, expect, it } from "vitest";
1111
* This does NOT re-implement cycle detection — that would be exactly the
1212
* "re-derive what the tool already knows" mistake the style guide forbids.
1313
* Every assertion below asks ESLint, running the repository's real
14-
* `eslint.config.js`, and checks what it answers.
14+
* `eslint.config.js`, and checks what it answers. The second test layers two
15+
* narrowings on top of that config, type-aware parsing off and only this rule
16+
* run, neither of which touches the settings the rule resolves imports with;
17+
* the comment at that call explains why.
1518
*
1619
* It exists because the rule's failure mode is silence. While this rule was
1720
* being added, the config resolved correctly, matched the right files, and
@@ -25,6 +28,7 @@ import { afterAll, describe, expect, it } from "vitest";
2528

2629
const REPO_ROOT = resolve(import.meta.dirname, "..", "..", "..");
2730
const CLI_SOURCE = resolve(REPO_ROOT, "packages/cli/src");
31+
const RULE_ID = "import-x/no-cycle";
2832

2933
const temporaryDirectories: string[] = [];
3034

@@ -40,16 +44,16 @@ function createESLint(): ESLint {
4044
return new ESLint({ cwd: REPO_ROOT });
4145
}
4246

43-
describe("import-x/no-cycle", () => {
47+
describe(RULE_ID, () => {
4448
it("is enabled as an error for files in packages/cli/src", async () => {
4549
const config = (await createESLint().calculateConfigForFile(
4650
join(CLI_SOURCE, "index.ts")
4751
)) as { rules?: Record<string, unknown> };
4852

4953
// "error" is 2 once ESLint normalizes it. A config block that stopped
5054
// matching `packages/cli/src` would leave this undefined.
51-
expect(config.rules?.["import-x/no-cycle"]).toBeDefined();
52-
expect((config.rules?.["import-x/no-cycle"] as unknown[])[0]).toBe(2);
55+
expect(config.rules?.[RULE_ID]).toBeDefined();
56+
expect((config.rules?.[RULE_ID] as unknown[])[0]).toBe(2);
5357
});
5458

5559
it("reports a value cycle written into packages/cli/src", async () => {
@@ -87,13 +91,11 @@ describe("import-x/no-cycle", () => {
8791
files: ["**/*.ts"],
8892
languageOptions: { parserOptions: { projectService: false } },
8993
},
90-
ruleFilter: ({ ruleId }) => ruleId === "import-x/no-cycle",
94+
ruleFilter: ({ ruleId }) => ruleId === RULE_ID,
9195
});
9296
const results = await eslint.lintFiles([join(directory, "*.ts")]);
9397
const cycleMessages = results.flatMap((result) =>
94-
result.messages.filter(
95-
(message) => message.ruleId === "import-x/no-cycle"
96-
)
98+
result.messages.filter((message) => message.ruleId === RULE_ID)
9799
);
98100

99101
expect(cycleMessages.length).toBeGreaterThan(0);

0 commit comments

Comments
 (0)