123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- "use strict";
- const noOptionsSchema = Object.freeze({
- type: "array",
- minItems: 0,
- maxItems: 0
- });
- function parseRuleId(ruleId) {
- let pluginName, ruleName;
-
- if (ruleId.includes("/")) {
-
- if (ruleId.startsWith("@")) {
- pluginName = ruleId.slice(0, ruleId.lastIndexOf("/"));
- } else {
- pluginName = ruleId.slice(0, ruleId.indexOf("/"));
- }
- ruleName = ruleId.slice(pluginName.length + 1);
- } else {
- pluginName = "@";
- ruleName = ruleId;
- }
- return {
- pluginName,
- ruleName
- };
- }
- function getRuleFromConfig(ruleId, config) {
- const { pluginName, ruleName } = parseRuleId(ruleId);
- return config.plugins?.[pluginName]?.rules?.[ruleName];
- }
- function getRuleOptionsSchema(rule) {
- if (!rule.meta) {
- return { ...noOptionsSchema };
- }
- const schema = rule.meta.schema;
- if (typeof schema === "undefined") {
- return { ...noOptionsSchema };
- }
-
- if (schema === false) {
- return null;
- }
- if (typeof schema !== "object" || schema === null) {
- throw new TypeError("Rule's `meta.schema` must be an array or object");
- }
-
- if (Array.isArray(schema)) {
- if (schema.length) {
- return {
- type: "array",
- items: schema,
- minItems: 0,
- maxItems: schema.length
- };
- }
-
- return { ...noOptionsSchema };
- }
-
- return schema;
- }
- module.exports = {
- parseRuleId,
- getRuleFromConfig,
- getRuleOptionsSchema
- };
|