Skip to content

Commit fdf8d59

Browse files
fix(lint): add fix hints to the variables-entry and CSS parse findings
Closes #5392
1 parent 4b68f73 commit fdf8d59

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎packages/lint/src/rules/composition.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ describe("composition rules", () => {
12591259
expect(findings.length).toBe(1);
12601260
expect(findings[0]?.message).toMatch(/\[1\]/);
12611261
expect(findings[0]?.message).toMatch(/type|label|default/);
1262+
expect(findings[0]?.fixHint).toMatch(/entry \[1\]/);
12621263
});
12631264

12641265
it("warns when a declaration uses an unknown type", async () => {
@@ -1269,6 +1270,17 @@ describe("composition rules", () => {
12691270
);
12701271
expect(finding).toBeDefined();
12711272
expect(finding?.message).toMatch(/type/);
1273+
expect(finding?.fixHint).toBeTruthy();
1274+
});
1275+
1276+
it("gives a fix hint when an entry is not an object", async () => {
1277+
const html = `<html data-composition-variables='["title"]'><body><div data-composition-id="x"></div></body></html>`;
1278+
const result = await lintHyperframeHtml(html);
1279+
const finding = result.findings.find(
1280+
(f) => f.code === "invalid_composition_variables_declaration",
1281+
);
1282+
expect(finding?.message).toMatch(/must be an object/);
1283+
expect(finding?.fixHint).toMatch(/"id":"title"/);
12721284
});
12731285

12741286
it("does not warn for a fully valid declarations array", async () => {

‎packages/lint/src/rules/composition.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ function variablesDeclarationFindings(
462462
code: "invalid_composition_variables_declaration",
463463
severity: "error",
464464
message: `data-composition-variables entry [${i}] must be an object with id, type, label, and default.`,
465+
fixHint:
466+
'Replace the entry with an object such as {"id":"title","type":"string","label":"Title","default":"Hello"}.',
465467
snippet: truncateSnippet(tag.raw),
466468
});
467469
continue;
@@ -477,6 +479,7 @@ function variablesDeclarationFindings(
477479
code: "invalid_composition_variables_declaration",
478480
severity: "error",
479481
message: `data-composition-variables entry [${i}] is missing or has invalid: ${missing.join(", ")}. Type must be one of string, number, color, boolean, enum, font, image.`,
482+
fixHint: `Give entry [${i}] a string id and label, a supported type, and a default, e.g. {"id":"title","type":"string","label":"Title","default":"Hello"}.`,
480483
snippet: truncateSnippet(tag.raw),
481484
});
482485
continue;

‎packages/lint/src/rules/core.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ describe("core rules", () => {
14461446
expect(finding).toBeDefined();
14471447
expect(finding?.severity).toBe("error");
14481448
expect(finding?.message).toContain("Missed semicolon");
1449+
expect(finding?.fixHint).toMatch(/reported line/);
14491450
});
14501451
});
14511452
});

‎packages/lint/src/rules/core.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@ export const coreRules: Array<(ctx: LintContext) => HyperframeLintFinding[]> = [
726726
code: "css_parse_error",
727727
severity: "error",
728728
message: `CSS parse error: ${error instanceof Error ? error.message : "unknown"}`,
729+
fixHint:
730+
"Check the CSS at the reported line for an unclosed brace, quote, or comment, or a missing semicolon between declarations.",
729731
});
730732
continue;
731733
}

0 commit comments

Comments
 (0)