refactor deprecation diag creation

This commit is contained in:
Daniel Schmidt 2026-01-22 15:54:30 +01:00
parent 3fd7a5052f
commit 5ed7d5134e

View file

@ -65,22 +65,26 @@ func (d *Deprecations) deprecationMarksToDiagnostics(deprecationMarks []marks.De
}
for _, depMark := range deprecationMarks {
diag := &hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: "Deprecated value used",
Detail: depMark.Message,
Subject: rng,
}
if depMark.OriginDescription != "" {
diag.Extra = &tfdiags.DeprecationOriginDiagnosticExtra{
OriginDescription: depMark.OriginDescription,
}
}
diags = diags.Append(diag)
diags = diags.Append(deprecationMarkToDiagnostic(depMark, rng))
}
return diags
}
func deprecationMarkToDiagnostic(depMark marks.DeprecationMark, subject *hcl.Range) *hcl.Diagnostic {
diag := &hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: "Deprecated value used",
Detail: depMark.Message,
Subject: subject,
}
if depMark.OriginDescription != "" {
diag.Extra = &tfdiags.DeprecationOriginDiagnosticExtra{
OriginDescription: depMark.OriginDescription,
}
}
return diag
}
// ValidateAsConfig checks the given value for deprecation marks and returns diagnostics
// for each deprecation found, unless deprecation warnings are suppressed for the given module.
// It checks for deeply nested deprecation marks as well.