Commit c91c36d5 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(rules): rule documentation url for rules in subdirectories

parent 8756373f
Pipeline #287934201 passed with stages
in 10 minutes and 18 seconds
......@@ -475,9 +475,18 @@ describe("validateOptions()", () => {
});
});
it("ruleDocumentationUrl() should return URL to rule documentation", () => {
expect.assertions(1);
expect(ruleDocumentationUrl("src/rules/foo.ts")).toEqual(
"https://html-validate.org/rules/foo.html"
);
describe("ruleDocumentationUrl()", () => {
it("should return URL to rule documentation", () => {
expect.assertions(1);
const filename = path.join(__dirname, "rules/foo.ts");
const url = ruleDocumentationUrl(filename);
expect(url).toEqual("https://html-validate.org/rules/foo.html");
});
it("should handle rules in subdirectories", () => {
expect.assertions(1);
const filename = path.join(__dirname, "rules/foo/bar.ts");
const url = ruleDocumentationUrl(filename);
expect(url).toEqual("https://html-validate.org/rules/foo/bar.html");
});
});
......@@ -356,5 +356,6 @@ export abstract class Rule<ContextType = void, OptionsType = void> {
export function ruleDocumentationUrl(filename: string): string {
const p = path.parse(filename);
return `${homepage}/rules/${p.name}.html`;
const rel = path.relative(path.join(__dirname, "rules"), path.join(p.dir, p.name));
return `${homepage}/rules/${rel}.html`;
}
......@@ -3,7 +3,7 @@
exports[`wcag/h30 should contain documentation 1`] = `
Object {
"description": "WCAG 2.1 requires each \`<a>\` anchor link to have a text describing the purpose of the link using either plain text or an \`<img>\` with the \`alt\` attribute set.",
"url": "https://html-validate.org/rules/h30.html",
"url": "https://html-validate.org/rules/wcag/h30.html",
}
`;
......
......@@ -3,7 +3,7 @@
exports[`wcag/h32 should contain documentation 1`] = `
Object {
"description": "WCAG 2.1 requires each \`<form>\` element to have at least one submit button.",
"url": "https://html-validate.org/rules/h32.html",
"url": "https://html-validate.org/rules/wcag/h32.html",
}
`;
......
......@@ -3,6 +3,6 @@
exports[`wcag/h36 should contain documentation 1`] = `
Object {
"description": "WCAG 2.1 requires all images used as submit buttons to have a textual description using the alt attribute. The alt text cannot be empty (\`alt=\\"\\"\`).",
"url": "https://html-validate.org/rules/h36.html",
"url": "https://html-validate.org/rules/wcag/h36.html",
}
`;
......@@ -3,7 +3,7 @@
exports[`rule h37 should contain documentation 1`] = `
Object {
"description": "Both HTML5 and WCAG 2.0 requires images to have a alternative text for each image.",
"url": "https://html-validate.org/rules/h37.html",
"url": "https://html-validate.org/rules/wcag/h37.html",
}
`;
......
......@@ -3,7 +3,7 @@
exports[`wcag/h67 should contain documentation 1`] = `
Object {
"description": "A decorative image cannot have a title attribute. Either remove \`title\` or add a descriptive \`alt\` text.",
"url": "https://html-validate.org/rules/h67.html",
"url": "https://html-validate.org/rules/wcag/h67.html",
}
`;
......
......@@ -3,6 +3,6 @@
exports[`wcag/h71 should contain documentation 1`] = `
Object {
"description": "H71: Providing a description for groups of form controls using fieldset and legend elements",
"url": "https://html-validate.org/rules/h71.html",
"url": "https://html-validate.org/rules/wcag/h71.html",
}
`;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment