cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.11.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/checks/base.go

104lines · modecode

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