Skip to content

Commit 9b3c017

Browse files
committed
chore: wired min_severity
1 parent 78ad49d commit 9b3c017

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

docs/dryrun-toml.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ timestamp_type = "timestamptz" # warns about bare timestamp without time zone
256256

257257
### min_severity
258258

259-
Filter lint output by severity. Default: `warning`.
259+
Filter lint output by severity. Default: `info` (show everything).
260260

261261
| Value | Shows |
262262
|-------|-------|

internal/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type (
6464
RequireTimestamps *bool `toml:"require_timestamps"`
6565
TimestampType *string `toml:"timestamp_type"`
6666
PreferTextOverVarchar *bool `toml:"prefer_text_over_varchar"`
67+
MinSeverity *string `toml:"min_severity"`
6768
DisabledRules *DisabledRulesConfig `toml:"disabled_rules"`
6869
Custom *CustomPatternsConfig `toml:"custom"`
6970
}
@@ -268,6 +269,9 @@ func (c *ProjectConfig) LintConfig() lint.Config {
268269
if conv.PreferTextOverVarchar != nil {
269270
cfg.PreferTextOverVarchar = *conv.PreferTextOverVarchar
270271
}
272+
if conv.MinSeverity != nil {
273+
cfg.MinSeverity = lint.Severity(*conv.MinSeverity)
274+
}
271275
if conv.DisabledRules != nil {
272276
cfg.DisabledRules = conv.DisabledRules.Rules
273277
}

internal/mcp/handlers_lint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (s *Server) handleLintSchema(_ context.Context, req mcp.CallToolRequest) (*
5151
result := map[string]any{}
5252

5353
if wantConventions {
54-
findings := lint.RunRules(target, &s.lintConfig)
54+
findings := lint.GateMinSeverity(lint.RunRules(target, &s.lintConfig), s.lintConfig.MinSeverity)
5555
report := lint.NewReport(findings, len(target.Tables), "conventions")
5656
compact := lint.CompactReportFromReportN(report, 5)
5757
if fullMode {
@@ -77,7 +77,7 @@ func (s *Server) handleLintSchema(_ context.Context, req mcp.CallToolRequest) (*
7777
auditCfg := audit.DefaultConfig()
7878
// planner stays unfiltered; bloat rules iterate target.Tables and look up sizing by qual
7979
ta := &schema.AnnotatedSchema{Schema: target, Planner: a.Planner, Merged: a.Merged}
80-
findings := audit.RunRulesAnnotated(ta, &auditCfg)
80+
findings := lint.GateMinSeverity(audit.RunRulesAnnotated(ta, &auditCfg), s.lintConfig.MinSeverity)
8181
for _, f := range findings {
8282
if f.DDLFix != nil {
8383
hasDDLFixes = true

pkg/lint/lint.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,25 @@ func LintSchema(snap *snapshot.SchemaSnapshot, config *Config) Report {
1212
if len(config.DisabledRules) > 0 {
1313
configSource = fmt.Sprintf("custom (%d rules disabled)", len(config.DisabledRules))
1414
}
15-
return NewReport(RunRules(snap, config), len(snap.Tables), configSource)
15+
findings := GateMinSeverity(RunRules(snap, config), config.MinSeverity)
16+
return NewReport(findings, len(snap.Tables), configSource)
17+
}
18+
19+
func GateMinSeverity(findings []Finding, min Severity) []Finding {
20+
if min == "" {
21+
return findings
22+
}
23+
24+
floor := severityRank(min)
25+
out := make([]Finding, 0, len(findings))
26+
27+
for _, f := range findings {
28+
if severityRank(f.Severity) >= floor {
29+
out = append(out, f)
30+
}
31+
}
32+
33+
return out
1634
}
1735

1836
func RunRules(snap *snapshot.SchemaSnapshot, config *Config) []Finding {

0 commit comments

Comments
 (0)