! exec pint --no-color lint rules
! stdout .
cmp stderr stderr.txt

-- stderr.txt --
level=INFO msg="Loading configuration file" path=.pint.hcl
level=INFO msg="Finding all rules to check" paths=["rules"]
level=INFO msg="Checking Prometheus rules" entries=6 workers=10 online=true
Warning: required label not set (rule/label)
  ---> rules/0001.yml:1-2 -> `Always` [+1 duplicates]
2 |   expr: up
            ^^ `severity` label is required.

Bug: required annotation not set (alerts/annotation)
  ---> rules/0001.yml:1-2 -> `Always` [+1 duplicates]
2 |   expr: up
            ^^ `url` annotation is required.

Warning: always firing alert (alerts/comparison)
  ---> rules/0001.yml:2 -> `Always`
2 |   expr: up
            ^^
            This query doesn't have any condition and so this alert will always fire if it matches
            anything.

Warning: invalid label value (rule/label)
  ---> rules/0001.yml:14 -> `ServiceIsDown`
14 |     severity: bad
                   ^^^ `severity` label value must match `^critical|warning|info$`.

Bug: invalid annotation value (alerts/annotation)
  ---> rules/0001.yml:16 -> `ServiceIsDown`
16 |     url: bad
              ^^^ `url` annotation value must match `^https://wiki.example.com/page/(.+).html$`.

Fatal: template syntax error (alerts/template)
  ---> rules/0002.yml:5 -> `Foo Is Down` [+1 duplicates]
5 |     summary: 'Instance {{ $label.instance }} down'
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                  Template failed to parse with this error: `undefined variable "$label"`.

Fatal: template syntax error (alerts/template)
  ---> rules/0002.yml:6 -> `Foo Is Down`
6 |     func: '{{ $valuexx | xxx }}'
               ^^^^^^^^^^^^^^^^^^^^
               Template failed to parse with this error: `undefined variable "$valuexx"`.

Fatal: template syntax error (alerts/template)
  ---> rules/0002.yml:10 -> `Foo Is Down`
10 |     func: '{{ $value | xxx }}'
                ^^^^^^^^^^^^^^^^^^
                Template failed to parse with this error: `function "xxx" not defined`.

Bug: value used in labels (alerts/template)
  ---> rules/0002.yml:11 -> `Foo Is Down`
11 |     bar: 'Some {{$value}} value'
               ^^^^^^^^^^^^^^^^^^^^^
               Using `$value` in labels will generate a new alert on every value change, move it to
               annotations.

Bug: value used in labels (alerts/template)
  ---> rules/0002.yml:12 -> `Foo Is Down`
12 |     val: '{{ .Value|humanizeDuration }}'
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               Using `.Value` in labels will generate a new alert on every value change, move it to
               annotations.

level=INFO msg="Some problems are duplicated between rules and all the duplicates were hidden, pass `--show-duplicates` to see them" total=13 duplicates=3 shown=10
level=INFO msg="Problems found" Fatal=4 Bug=5 Warning=4
level=ERROR msg="Execution completed with error(s)" err="found 9 problem(s) with severity Bug or higher"
-- rules/0001.yml --
- alert: Always
  expr: up
- alert: AlwaysIgnored
  expr: up # pint disable alerts/comparison
  labels:
    severity: warning
  annotations:
    url: "https://wiki.example.com/page/ServiceIsDown.html"
- alert: ServiceIsDown
  expr: up == 0
- alert: ServiceIsDown
  expr: up == 0
  labels:
    severity: bad
  annotations:
    url: bad
- alert: ServiceIsDown
  expr: up == 0
  labels:
    severity: warning
  annotations:
    url: "https://wiki.example.com/page/ServiceIsDown.html"

-- rules/0002.yml --
- alert: Foo Is Down
  expr: up{job="foo"} == 0
  annotations:
    url: "https://wiki.example.com/page/ServiceIsDown.html"
    summary: 'Instance {{ $label.instance }} down'
    func: '{{ $valuexx | xxx }}'
  labels:
    severity: warning
    summary: 'Instance {{ $label.instance }} down'
    func: '{{ $value | xxx }}'
    bar: 'Some {{$value}} value'
    val: '{{ .Value|humanizeDuration }}'
    ignore: '$value is not a variable'

-- .pint.hcl --
parser {
  relaxed = ["rules/.*"]
}
rule {
    annotation "url" {
        severity = "bug"
        value = "https://wiki.example.com/page/(.+).html"
        required = true
    }
    label "severity" {
        value = "critical|warning|info"
        required = true
    }
}
