Skip to content

Commit

Permalink
Enable strict mode by default
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Apr 5, 2022
1 parent 0ee1361 commit b52bd8e
Show file tree
Hide file tree
Showing 63 changed files with 643 additions and 70 deletions.
2 changes: 1 addition & 1 deletion cmd/pint/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func actionCI(c *cli.Context) error {
return nil
}

finder := discovery.NewGitBranchFinder(git.RunGit, includeRe, meta.cfg.CI.BaseBranch, meta.cfg.CI.MaxCommits)
finder := discovery.NewGitBranchFinder(git.RunGit, includeRe, meta.cfg.CI.BaseBranch, meta.cfg.CI.MaxCommits, meta.cfg.Parser.CompileRelaxed())
entries, err := finder.Find()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/pint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func actionLint(c *cli.Context) error {
return fmt.Errorf("at least one file or directory required")
}

finder := discovery.NewGlobFinder(paths...)
finder := discovery.NewGlobFinder(paths, meta.cfg.Parser.CompileRelaxed())
entries, err := finder.Find()
if err != nil {
return err
Expand Down
5 changes: 4 additions & 1 deletion cmd/pint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func mockRules(dir string, filesCount, rulesPerFile int) error {
}

func mockConfig(configPath string) error {
content := `
content := `
parser {
relaxed = ["(.*)"]
}
rule {
reject ".* +.*" {
label_keys = true
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0001_match_path.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ level=fatal msg="Fatal error" error="problems found"
- record: "colo:test2"
expr: sum(foo) without(job)
-- .pint.hcl --
parser {
relaxed = [".*"]
}
rule {
match {
path = "rules/0002.yml"
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0003_lint_workdir.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ level=fatal msg="Fatal error" error="problems found"
expr: up == 0

-- .pint.hcl --
parser {
relaxed = [".*"]
}
rule {
match {
kind = "recording"
Expand Down
17 changes: 13 additions & 4 deletions cmd/pint/tests/0004_fail_invalid_yaml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ pint.error --no-color lint rules
cmp stderr stderr.txt

-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=error msg="Failed to parse file content" error="yaml: line 4: did not find expected key" path=rules/bad.yaml
level=info msg="File parsed" path=rules/ok.yml rules=1
rules/bad.yaml:4: did not find expected key (yaml/parse)


rules/ok.yml:2: syntax error: unclosed left bracket (promql/syntax)
expr: sum(foo[5m)
rules/ok.yml:5: syntax error: unclosed left bracket (promql/syntax)
expr: sum(foo[5m)

level=info msg="Problems found" Fatal=2
level=fatal msg="Fatal error" error="problems found"
-- rules/ok.yml --
- record: sum:missing
expr: sum(foo[5m)
groups:
- name: foo
rules:
- record: sum:missing
expr: sum(foo[5m)

-- rules/bad.yaml --
xxx:
Expand All @@ -24,3 +28,8 @@ xxx:

- xx
- yyy

-- .pint.hcl --
parser {
relaxed = [".*"]
}
3 changes: 3 additions & 0 deletions cmd/pint/tests/0005_false_positive.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ level=info msg="File parsed" path=rules/0001.yml rules=2
expr: topk(6, sum(rate(edgeworker_subrequest_errorCount{cordon="free"}[10m])) without (instance))

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
rule {
aggregate ".+" {
keep = [ "job" ]
Expand Down
21 changes: 12 additions & 9 deletions cmd/pint/tests/0006_rr_labels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ cmp stderr stderr.txt
-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=info msg="File parsed" path=rules/0001.yml rules=2
rules/0001.yml:5: incomplete rule, no alert or record key (yaml/parse)
- expr: sum(foo)
rules/0001.yml:8: incomplete rule, no alert or record key (yaml/parse)
- expr: sum(foo)

level=info msg="Problems found" Fatal=1
level=fatal msg="Fatal error" error="problems found"
-- rules/0001.yml --
- record: "colo:test1"
expr: sum(foo) without(job)
labels:
job: foo
- expr: sum(foo)
labels:
job: foo
groups:
- name: foo
rules:
- record: "colo:test1"
expr: sum(foo) without(job)
labels:
job: foo
- expr: sum(foo)
labels:
job: foo
-- .pint.hcl --
rule {
aggregate ".+" {
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0007_alerts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ level=fatal msg="Fatal error" error="problems found"
ignore: '$value is not a variable'

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
rule {
annotation "url" {
severity = "bug"
Expand Down
6 changes: 6 additions & 0 deletions cmd/pint/tests/0010_syntax_check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pint.error --no-color lint rules
cmp stderr stderr.txt

-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=error msg="Failed to parse file content" error="yaml: line 6: did not find expected '-' indicator" path=rules/1.yaml
rules/1.yaml:6: did not find expected '-' indicator (yaml/parse)

Expand All @@ -21,3 +22,8 @@ alert: Bad
for: 2m
labels:
component: foo

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
3 changes: 3 additions & 0 deletions cmd/pint/tests/0011_ignore_rules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ level=fatal msg="Fatal error" error="problems found"
expr: sum(errors_total) without(job)

-- .pint.hcl --
parser {
relaxed = [".*"]
}
rule {
aggregate ".+" {
keep = [ "job" ]
Expand Down
6 changes: 6 additions & 0 deletions cmd/pint/tests/0014_issue49_2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ pint.ok --no-color lint rules
cmp stderr stderr.txt

-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=info msg="File parsed" path=rules/0001.yaml rules=1
-- rules/0001.yaml --
- record: down
expr: up == 0

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
3 changes: 3 additions & 0 deletions cmd/pint/tests/0017_issue69.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4273,6 +4273,9 @@ func main() {
expr: up == 0

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
rule {
match {
kind = "alerting"
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0018_match_alerting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ level=info msg="Problems found" Warning=2
expr: sum(bar) without(job)

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
rule {
match {
kind = "alerting"
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0019_match_recording.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ level=info msg="Problems found" Warning=1
expr: sum(bar) without(job) > 0

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
rule {
match {
kind = "recording"
Expand Down
23 changes: 13 additions & 10 deletions cmd/pint/tests/0020_ignore_kind.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@ cmp stderr stderr.txt
-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=info msg="File parsed" path=rules/0001.yml rules=2
level=debug msg="Found recording rule" lines=1-2 path=rules/0001.yml record=colo:recording
level=debug msg="Found recording rule" lines=4-5 path=rules/0001.yml record=colo:recording
level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:recording
level=debug msg="Found alerting rule" alert=colo:alerting lines=4-5 path=rules/0001.yml
level=debug msg="Found alerting rule" alert=colo:alerting lines=7-8 path=rules/0001.yml
level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:alerting
rules/0001.yml:2: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate)
expr: sum(foo) without(job)
rules/0001.yml:5: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate)
expr: sum(foo) without(job)

rules/0001.yml:5: alert query doesn't have any condition, it will always fire if the metric exists (alerts/comparison)
expr: sum(bar) without(job)
rules/0001.yml:8: alert query doesn't have any condition, it will always fire if the metric exists (alerts/comparison)
expr: sum(bar) without(job)

level=info msg="Problems found" Warning=2
-- rules/0001.yml --
- record: "colo:recording"
expr: sum(foo) without(job)
groups:
- name: foo
rules:
- record: "colo:recording"
expr: sum(foo) without(job)

- alert: "colo:alerting"
expr: sum(bar) without(job)
- alert: "colo:alerting"
expr: sum(bar) without(job)

-- .pint.hcl --
rule {
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0021_ignore_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ level=fatal msg="Fatal error" error="failed to load config file \".pint.hcl\": i
expr: sum(bar) without(job)

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
rule {
ignore {}
aggregate ".+" {
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0022_ignore_multi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ level=info msg="Problems found" Warning=2
expr: sum(sum(errors_total) without(keep)) by(dropped)

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
rule {
aggregate ".+" {
keep = [ "keep" ]
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0023_enabled_checks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ stderr 'level=debug msg="Configured checks for rule" enabled=\["promql/syntax","
expr: up == 0

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
prometheus "prom" {
uri = "https://"
timeout = "2m"
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0024_color_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ level=fatal msg="Fatal error" error="problems found"
expr: up == 0

-- .pint.hcl --
parser {
relaxed = ["rules/.*"]
}
rule {
match {
kind = "recording"
Expand Down
1 change: 1 addition & 0 deletions cmd/pint/tests/0025_config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ level=info msg="Loading configuration file" path=.pint.hcl
"maxCommits": 20,
"baseBranch": "master"
},
"parser": {},
"prometheus": [
{
"name": "prom",
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0027_ci_branch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ level=fatal msg="Fatal error" error="problems found"
ci {
baseBranch = "main"
}
parser {
relaxed = [".*"]
}
3 changes: 3 additions & 0 deletions cmd/pint/tests/0028_ci_git_error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ level=fatal msg="Fatal error" error="failed to get the list of commits to scan:
ci {
baseBranch = "notmain"
}
parser {
relaxed = [".*"]
}
3 changes: 3 additions & 0 deletions cmd/pint/tests/0029_ci_too_many_commits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ ci {
maxCommits = 2
baseBranch = "main"
}
parser {
relaxed = [".*"]
}
3 changes: 3 additions & 0 deletions cmd/pint/tests/0032_ci_github.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ exec sh -c 'cat ../server.pid | xargs kill'
ci {
baseBranch = "main"
}
parser {
relaxed = [".*"]
}
repository {
github {
baseuri = "http://127.0.0.1:6032"
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0033_ci_github_multi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ exec sh -c 'cat ../server.pid | xargs kill'
ci {
baseBranch = "main"
}
parser {
relaxed = [".*"]
}
repository {
github {
baseuri = "http://127.0.0.1:6033"
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0036_ci_basebranch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ level=info msg="Running from base branch, skipping checks" branch=main
ci {
baseBranch = "main"
}
parser {
relaxed = [".*"]
}
3 changes: 3 additions & 0 deletions cmd/pint/tests/0037_disable_checks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ level=info msg="Problems found" Warning=1
expr: foo

-- .pint.hcl --
parser {
relaxed = [".*"]
}
rule {
match {
kind = "recording"
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0038_disable_checks_regex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ level=info msg="Problems found" Warning=1
expr: foo

-- .pint.hcl --
parser {
relaxed = [".*"]
}
rule {
match {
kind = "recording"
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0039_prom_selected_path.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ level=info msg="Problems found" Warning=1
expr: count(foo) > 0

-- .pint.hcl --
parser {
relaxed = [".*"]
}
prometheus "disabled" {
uri = "http://127.0.0.1:123"
timeout = "5s"
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0040_rule_match_label.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ level=info msg="Problems found" Warning=2
foo: bar

-- .pint.hcl --
parser {
relaxed = [".*"]
}
rule {
match {
label "foo" {
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0042_watch_metrics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ cat pint.pid | xargs kill
# pint rule/owner alice

-- .pint.hcl --
parser {
relaxed = [".*"]
}
rule {
match {
kind = "recording"
Expand Down
Loading

0 comments on commit b52bd8e

Please sign in to comment.