Commit 09aad040 authored by David Sveningsson's avatar David Sveningsson
Browse files

feat: new utility function `ruleExists` to test presence of bundled rules

parent e9099fdd
Pipeline #212994829 passed with stages
in 9 minutes and 31 seconds
......@@ -14,6 +14,7 @@ export { Report, Reporter, Message, Result } from "./reporter";
export { Transformer, TemplateExtractor } from "./transform";
export { Plugin } from "./plugin";
export { Parser } from "./parser";
export { ruleExists } from "./utils";
const pkg = require("../package.json");
......
export { ruleExists } from "./rule-exists";
jest.mock("../rules", () => {
return {
"existing-rule": (): null => null,
};
});
import { ruleExists } from "./rule-exists";
it("should return true if rule exists", () => {
expect.assertions(1);
expect(ruleExists("existing-rule")).toBeTruthy();
});
it("should return false if rule is missing", () => {
expect.assertions(1);
expect(ruleExists("missing-rule")).toBeFalsy();
});
import rules from "../rules";
const ruleIds = new Set<string>(Object.keys(rules));
/**
* Returns true if given ruleId is an existing builtin rule. It does not handle
* rules loaded via plugins.
*
* Can be used to create forward/backward compatibility by checking if a rule
* exists to enable/disable it.
*
* @param ruleId - Rule id to check
* @returns `true` if rule exists
*/
export function ruleExists(ruleId: string): boolean {
return ruleIds.has(ruleId);
}
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