cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.7.3

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/checks/base.go

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