cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.1.4

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/checks/base.go

93lines · modecode

1package checks
2
3import (
4 "fmt"
5
6 "github.com/cloudflare/pint/internal/parser"
7)
8
9var (
10 CheckNames = []string{
11 AlertsCheckName,
12 ComparisonCheckName,
13 AnnotationCheckName,
14 ByCheckName,
15 CostCheckName,
16 LabelCheckName,
17 RateCheckName,
18 SeriesCheckName,
19 SyntaxCheckName,
20 WithoutCheckName,
21 RejectCheckName,
22 TemplateCheckName,
23 VectorMatchingCheckName,
24 }
25)
26
27// Severity of the problem reported
28type Severity int
29
30func (s Severity) String() string {
31 switch s {
32 case Fatal:
33 return "Fatal"
34 case Information:
35 return "Information"
36 case Warning:
37 return "Warning"
38 default:
39 return "Bug"
40 }
41}
42
43func ParseSeverity(s string) (Severity, error) {
44 switch s {
45 case "fatal":
46 return Fatal, nil
47 case "bug":
48 return Bug, nil
49 case "info":
50 return Information, nil
51 case "warning":
52 return Warning, nil
53 default:
54 return Fatal, fmt.Errorf("unknown severity: %s", s)
55 }
56}
57
58const (
59 // Information doesn't count as a problem, it's a comment
60 Information Severity = iota
61
62 // Warning is not consider an error
63 Warning
64
65 // Bug is an error that should be corrected
66 Bug
67
68 // Fatal is a problem with linting content
69 Fatal
70)
71
72type Problem struct {
73 Fragment string
74 Lines []int
75 Reporter string
76 Text string
77 Severity Severity
78}
79
80func (p Problem) LineRange() (int, int) {
81 return p.Lines[0], p.Lines[len(p.Lines)-1]
82}
83
84type RuleChecker interface {
85 String() string
86 Check(rule parser.Rule) []Problem
87}
88
89type exprProblem struct {
90 expr string
91 text string
92 severity Severity
93}
94