cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.10.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/checks/base.go

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