cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.4.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/checks/base.go

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