cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.1.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/checks/base.go

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