Commit 8b106014 authored by David Sveningsson's avatar David Sveningsson

fix(rules): contextual documentation for `deprecated-rule`

parent 3602be73
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`rule deprecated-rule should contain contextual documentation 1`] = `
Object {
"description": "The rule \\"my-rule\\" is deprecated and should not be used any longer, consult documentation for further information.",
"url": "https://html-validate.org/rules/deprecated-rule.html",
}
`;
exports[`rule deprecated-rule should contain documentation 1`] = `
Object {
"description": "This rule is deprecated and should not be used any longer, consult documentation for further information.",
......
......@@ -75,4 +75,11 @@ describe("rule deprecated-rule", () => {
htmlvalidate.getRuleDocumentation("deprecated-rule")
).toMatchSnapshot();
});
it("should contain contextual documentation", () => {
const htmlvalidate = new HtmlValidate();
expect(
htmlvalidate.getRuleDocumentation("deprecated-rule", null, "my-rule")
).toMatchSnapshot();
});
});
......@@ -2,11 +2,12 @@ import { Severity } from "../config";
import { ConfigReadyEvent } from "../event";
import { Rule, RuleDocumentation, ruleDocumentationUrl } from "../rule";
class DeprecatedRule extends Rule {
public documentation(): RuleDocumentation {
class DeprecatedRule extends Rule<string> {
public documentation(context: string): RuleDocumentation {
return {
description:
"This rule is deprecated and should not be used any longer, consult documentation for further information.",
description: `${
context ? `The rule "${context}"` : "This rule"
} is deprecated and should not be used any longer, consult documentation for further information.`,
url: ruleDocumentationUrl(__filename),
};
}
......@@ -15,7 +16,12 @@ class DeprecatedRule extends Rule {
this.on("config:ready", (event: ConfigReadyEvent) => {
for (const rule of this.getDeprecatedRules(event)) {
if (rule.getSeverity() > Severity.DISABLED) {
this.report(null, `Usage of deprecated rule "${rule.name}"`);
this.report(
null,
`Usage of deprecated rule "${rule.name}"`,
null,
rule.name
);
}
}
});
......
Markdown is supported
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