Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/tools/implementations/createRuleBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test("createRuleBlockImpl should create a rule with glob pattern", async () => {
const { frontmatter, markdown } = parseMarkdownRule(fileContent);

expect(frontmatter).toEqual({
name: "TypeScript Rule",
alwaysApply: true,
description: "Always use interfaces",
globs: "**/*.{ts,tsx}",
Expand Down Expand Up @@ -73,6 +74,7 @@ test("createRuleBlockImpl should create a rule with description pattern", async
const { frontmatter, markdown } = parseMarkdownRule(fileContent);

expect(frontmatter).toEqual({
name: "Description Test",
alwaysApply: true,
description: "This is a detailed explanation of the rule",
});
Expand All @@ -96,6 +98,7 @@ test("createRuleBlockImpl should include both globs and description in frontmatt
const { frontmatter, markdown } = parseMarkdownRule(fileContent);

expect(frontmatter).toEqual({
name: "Complete Rule",
alwaysApply: false,
description: "This rule enforces our team standards",
globs: "**/*.js",
Expand All @@ -119,6 +122,7 @@ test("createRuleBlockImpl should create a rule with alwaysApply set to false", a
const { frontmatter } = parseMarkdownRule(fileContent);

expect(frontmatter).toEqual({
name: "Conditional Rule",
alwaysApply: false,
description: "Optional rule",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe("createRuleMarkdown", () => {

const parsed = markdownToRule(result, mockPackageId);

expect(parsed.name).toBe("Test Rule");
expect(parsed.description).toBe("Test description");
expect(parsed.globs).toEqual(["*.ts", "*.js"]);
expect(parsed.alwaysApply).toBe(true);
Expand All @@ -112,12 +113,20 @@ describe("createRuleMarkdown", () => {

const parsed = markdownToRule(result, mockPackageId);

expect(parsed.name).toBe("Simple Rule");
expect(parsed.description).toBeUndefined();
expect(parsed.globs).toBeUndefined();
expect(parsed.alwaysApply).toBeUndefined();
expect(parsed.rule).toBe("Simple content");
});

it("should trim the name", () => {
const result = createRuleMarkdown(" Padded Name ", "Content");

const parsed = markdownToRule(result, mockPackageId);
expect(parsed.name).toBe("Padded Name");
});

it("should handle string globs", () => {
const result = createRuleMarkdown("String Glob Rule", "Content", {
globs: "*.py",
Expand Down
4 changes: 3 additions & 1 deletion packages/config-yaml/src/markdown/createMarkdownRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export function createRuleMarkdown(
invokable?: boolean;
} = {},
): string {
const frontmatter: RuleFrontmatter = {};
const frontmatter: RuleFrontmatter = {
name: name.trim(),
};

if (options.globs) {
frontmatter.globs =
Expand Down
Loading