feat(cli): .glint.yml config and inline suppression comments
Adds project-level configuration and per-job suppression directives:
.glint.yml (searched from pipeline dir up to the git root):
- ignore: [GL007, GL032] — suppress rules globally for the project
- severity: {GL004: warning} — override rule severity (error/warning/ignore)
- stages: [quality] — extra stages beyond the pipeline's stages: block
- token: / url: / cache_dir: — defaults for flags; lower priority than
CLI flags and environment variables
Inline suppression (# glint: ignore):
- Place "# glint: ignore GL007" immediately before a job definition to
suppress that rule for the specific job only
- Multiple rules: "# glint: ignore GL007, GL032" (comma or space separated)
- Wildcard: "# glint: ignore all" suppresses every finding for the job
- Suppressions are scoped to the annotated job; pipeline-level findings
are unaffected
- Parsed from yaml.Node head/line comments in the first parse pass;
stored in Pipeline.Suppressions (root file only, not includes)
New packages: internal/config (Load, walk-up search, .git boundary stop)
New files: cmd/glint/filter.go (applyConfig, isSuppressed helpers)
Tests: config_test.go, parser_suppress_test.go, filter_test.go
Validate fixtures: testdata/config_ignored/, config_severity/, config_suppress/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
package model
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseSuppressComment(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
head string
|
||||
line string
|
||||
wantRules []string
|
||||
wantNil bool
|
||||
}{
|
||||
{
|
||||
name: "no comment",
|
||||
head: "",
|
||||
line: "",
|
||||
wantNil: true,
|
||||
},
|
||||
{
|
||||
name: "single rule head comment",
|
||||
head: "# glint: ignore GL007",
|
||||
wantRules: []string{"GL007"},
|
||||
},
|
||||
{
|
||||
name: "multiple rules comma-separated",
|
||||
head: "# glint: ignore GL007, GL032",
|
||||
wantRules: []string{"GL007", "GL032"},
|
||||
},
|
||||
{
|
||||
name: "multiple rules space-separated",
|
||||
head: "# glint: ignore GL007 GL032",
|
||||
wantRules: []string{"GL007", "GL032"},
|
||||
},
|
||||
{
|
||||
name: "ignore all",
|
||||
head: "# glint: ignore all",
|
||||
wantRules: []string{"*"},
|
||||
},
|
||||
{
|
||||
name: "ignore all bare",
|
||||
head: "# glint: ignore",
|
||||
wantRules: []string{"*"},
|
||||
},
|
||||
{
|
||||
name: "lowercase rule ID is uppercased",
|
||||
head: "# glint: ignore gl007",
|
||||
wantRules: []string{"GL007"},
|
||||
},
|
||||
{
|
||||
name: "line comment",
|
||||
head: "",
|
||||
line: "# glint: ignore GL004",
|
||||
wantRules: []string{"GL004"},
|
||||
},
|
||||
{
|
||||
name: "unrelated comment",
|
||||
head: "# This job deploys to production",
|
||||
wantNil: true,
|
||||
},
|
||||
{
|
||||
name: "partial match - not a glint directive",
|
||||
head: "# hint: ignore this",
|
||||
wantNil: true,
|
||||
},
|
||||
{
|
||||
name: "multi-line head comment with directive on second line",
|
||||
head: "# Some description\n# glint: ignore GL007",
|
||||
wantRules: []string{"GL007"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := parseSuppressComment(tc.head, tc.line)
|
||||
if tc.wantNil {
|
||||
if got != nil {
|
||||
t.Errorf("expected nil, got %v", got)
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(got) != len(tc.wantRules) {
|
||||
t.Fatalf("got %v, want %v", got, tc.wantRules)
|
||||
}
|
||||
for i, r := range tc.wantRules {
|
||||
if got[i] != r {
|
||||
t.Errorf("[%d] got %q, want %q", i, got[i], r)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseBytes_Suppressions(t *testing.T) {
|
||||
yaml := `
|
||||
stages:
|
||||
- build
|
||||
|
||||
# glint: ignore GL007
|
||||
deprecated-job:
|
||||
stage: build
|
||||
only:
|
||||
- main
|
||||
|
||||
normal-job:
|
||||
stage: build
|
||||
script: echo ok
|
||||
`
|
||||
p, err := ParseBytes([]byte(yaml))
|
||||
if err != nil {
|
||||
t.Fatalf("ParseBytes: %v", err)
|
||||
}
|
||||
if p.Suppressions == nil {
|
||||
t.Fatal("Suppressions is nil")
|
||||
}
|
||||
rules, ok := p.Suppressions["deprecated-job"]
|
||||
if !ok {
|
||||
t.Fatal("no suppression for deprecated-job")
|
||||
}
|
||||
if len(rules) != 1 || rules[0] != "GL007" {
|
||||
t.Errorf("rules = %v, want [GL007]", rules)
|
||||
}
|
||||
if _, ok := p.Suppressions["normal-job"]; ok {
|
||||
t.Error("normal-job should have no suppressions")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user