Skip to content

⬅️ Back to Table of Contents

📄 getRuleOptionsSchema

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 3

📚 Table of Contents

🛠️ File Location:

📂 packages/rule-tester/src/utils/getRuleOptionsSchema.ts

📦 Imports

Name Source
JSONSchema4 @typescript-eslint/utils/json-schema
AnyRuleModule @typescript-eslint/utils/ts-eslint
isReadonlyArray ./isReadonlyArray

Functions

getRuleOptionsSchema(rule: Partial<AnyRuleModule>): JSONSchema4 | null

Gets a complete options schema for a rule.

Parameters:

  • rule any: A new-style rule object

Returns: undefined JSON Schema for the rule's options.

Raw JSDoc
/**
 * Gets a complete options schema for a rule.
 * @param rule A new-style rule object
 * @returns JSON Schema for the rule's options.
 */

Calls:

  • isReadonlyArray (from ./isReadonlyArray)

Internal Comments:

// Given a tuple of schemas, insert warning level at the beginning
// Given a full schema, leave it alone

Code
export function getRuleOptionsSchema(
  rule: Partial<AnyRuleModule>,
): JSONSchema4 | null {
  const schema = rule.meta?.schema;

  // Given a tuple of schemas, insert warning level at the beginning
  if (isReadonlyArray(schema)) {
    if (schema.length) {
      return {
        items: schema as JSONSchema4[],
        maxItems: schema.length,
        minItems: 0,
        type: 'array',
      };
    }
    return {
      maxItems: 0,
      minItems: 0,
      type: 'array',
    };
  }

  // Given a full schema, leave it alone
  return schema ?? null;
}

Generated by Syntax Scribe