Repository: opentofu/opentofu
File: internal/tfdiags/consolidate_warnings.go (Go)

Code before:
			// Only the given level can get special treatment, and we only
			// consolidate diagnostics that have source locations because
			// our primary goal here is to deal with the situation where
			// some configuration language feature is producing a diagnostic
			// each time it's used across a potentially-large config.
			newDiags = newDiags.Append(diag)
			continue
		}

		if DoNotConsolidateDiagnostic(diag) {
			// Then do not consolidate this diagnostic.
			newDiags = newDiags.Append(diag)
			continue
		}

		desc := diag.Description()
		summary := desc.Summary
		var consolidationKey string
		// If the diagnostic has a keyable extra info and it's not empty,
		// use it as the consolidation key, along with the summary.
		// Otherwise use the summary only.
		if key, keyOk := diag.ExtraInfo().(Keyable); keyOk {
			consolidationKey = key.ExtraInfoKey()
		}

		consolidationKey += summary

		if g, ok := diagnosticGroups[consolidationKey]; ok {
			// We're already grouping this one, so we'll just continue it.
			g.Append(diag)
			continue
		}

		diagnosticStats[consolidationKey]++
		if diagnosticStats[consolidationKey] == threshold {
			// Initially creating the group doesn't really change anything
			// visibly in the result, since a group with only one diagnostic
			// is just a passthrough anyway, but once we do this any additional
			// diagnostics with the same consolidationKey will get appended to this group.
			g := &consolidatedGroup{}
			newDiags = newDiags.Append(g)
			diagnosticGroups[consolidationKey] = g
			g.Append(diag)
			continue
		}

		// If this diagnostic is not consolidating yet then we'll just append
		// it directly.
		newDiags = newDiags.Append(diag)
	}


Review comment (suggestion):
```suggestion
	        consolidationKey := summary
		// If the diagnostic has a keyable extra info and it's not empty,
		// use it as the consolidation key, along with the summary.
		// Otherwise use the summary only.
		if key, keyOk := diag.ExtraInfo().(Keyable); keyOk {
			consolidationKey += key.ExtraInfoKey()
		}
```

More of a nitpick, but I find it easier to read.

Code after:
			// Only the given level can get special treatment, and we only
			// consolidate diagnostics that have source locations because
			// our primary goal here is to deal with the situation where
			// some configuration language feature is producing a diagnostic
			// each time it's used across a potentially-large config.
			newDiags = newDiags.Append(diag)
			continue
		}

		if DoNotConsolidateDiagnostic(diag) {
			// Then do not consolidate this diagnostic.
			newDiags = newDiags.Append(diag)
			continue
		}

		desc := diag.Description()
		consolidationKey := desc.Summary
		// If the diagnostic has a keyable extra info and it's not empty,
		// use it as the consolidation key, along with the summary.
		// Otherwise use the summary only.
		if key, keyOk := diag.ExtraInfo().(Keyable); keyOk {
			consolidationKey += key.ExtraInfoKey()
		}

		if g, ok := diagnosticGroups[consolidationKey]; ok {
			// We're already grouping this one, so we'll just continue it.
			g.Append(diag)
			continue
		}

		diagnosticStats[consolidationKey]++
		if diagnosticStats[consolidationKey] == threshold {
			// Initially creating the group doesn't really change anything
			// visibly in the result, since a group with only one diagnostic
			// is just a passthrough anyway, but once we do this any additional
			// diagnostics with the same consolidationKey will get appended to this group.
			g := &consolidatedGroup{}
			newDiags = newDiags.Append(g)
			diagnosticGroups[consolidationKey] = g
			g.Append(diag)
			continue
		}

		// If this diagnostic is not consolidating yet then we'll just append
		// it directly.
		newDiags = newDiags.Append(diag)
	}

	return newDiags
}