{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://earslang.com/schema/0.1/diagnostics.schema.json",
  "$comment": "CC BY 4.0, Copyright 2026 Richard Pringle II: https://creativecommons.org/licenses/by/4.0/",
  "title": "earslang diagnostics, output format 0.1",
  "description": "What `ears check --json` writes to standard output (S17.7), and what `ears export --json` writes to standard error beside the export. The fields follow the text form: a code, the place, labelled spans and a help line (spec §12).",
  "type": "object",
  "required": ["version", "diagnostics"],
  "additionalProperties": false,
  "properties": {
    "version": {
      "description": "The version of this output format, the same as that of the compiled rules (spec.schema.json).",
      "const": "0.1"
    },
    "diagnostics": {
      "type": "array",
      "items": { "$ref": "#/$defs/diagnostic" }
    }
  },
  "$defs": {
    "place": {
      "description": "A line and a column, both from 1. Columns count characters, not bytes.",
      "type": "object",
      "required": ["line", "column"],
      "additionalProperties": false,
      "properties": {
        "line": { "type": "integer", "minimum": 1 },
        "column": { "type": "integer", "minimum": 1 }
      }
    },
    "label": {
      "description": "A marked span on one line, such as \"^^^^^^ second keyword\".",
      "type": "object",
      "required": ["start", "end", "text", "primary"],
      "additionalProperties": false,
      "properties": {
        "start": { "$ref": "#/$defs/place" },
        "end": {
          "description": "The place just after the last marked character.",
          "$ref": "#/$defs/place"
        },
        "text": {
          "description": "The words written after the marks, or empty.",
          "type": "string"
        },
        "primary": {
          "description": "True for the span the caret marks; false for a span marked with dashes.",
          "type": "boolean"
        }
      }
    },
    "diagnostic": {
      "type": "object",
      "required": ["code", "severity", "message", "file", "place", "labels", "help"],
      "additionalProperties": false,
      "properties": {
        "code": {
          "description": "A code that is never reused (S17.4), for ears explain.",
          "type": "string",
          "pattern": "^[EW][0-9]{4}$"
        },
        "severity": {
          "description": "The diagnostic's severity. --deny warnings changes the exit status, not this (S17.9).",
          "enum": ["error", "warning"]
        },
        "message": { "type": "string", "minLength": 1 },
        "file": {
          "description": "The file. Always set in format 0.1; null is reserved.",
          "type": ["string", "null"]
        },
        "place": {
          "description": "Where the diagnostic points (S17.5), or null when file is null.",
          "oneOf": [
            { "type": "null" },
            { "$ref": "#/$defs/place" }
          ]
        },
        "labels": {
          "type": "array",
          "items": { "$ref": "#/$defs/label" }
        },
        "help": {
          "description": "The suggestion, or null. For the codes S17.6 lists, the help shows the expected form.",
          "type": ["string", "null"]
        }
      },
      "allOf": [
        {
          "if": { "properties": { "file": { "type": "null" } } },
          "then": { "properties": { "place": { "type": "null" }, "labels": { "maxItems": 0 } } },
          "else": { "properties": { "place": { "$ref": "#/$defs/place" } } }
        }
      ]
    }
  }
}
