github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/tflint/issue.go (about) 1 package tflint 2 3 import ( 4 "sort" 5 6 hcl "github.com/hashicorp/hcl/v2" 7 ) 8 9 // Issue represents a problem in configurations 10 type Issue struct { 11 Rule Rule 12 Message string 13 Range hcl.Range 14 Callers []hcl.Range 15 } 16 17 // Issues is an alias for the map of Issue 18 type Issues []*Issue 19 20 const ( 21 // ERROR is possible errors 22 ERROR = "Error" 23 // WARNING doesn't cause problem immediately, but not good 24 WARNING = "Warning" 25 // NOTICE is not important, it's mentioned 26 NOTICE = "Notice" 27 ) 28 29 // Sort returns the sorted receiver 30 func (issues Issues) Sort() Issues { 31 sort.Slice(issues, func(i, j int) bool { 32 iRange := issues[i].Range 33 jRange := issues[j].Range 34 if iRange.Filename != jRange.Filename { 35 return iRange.Filename < jRange.Filename 36 } 37 if iRange.Start.Line != jRange.Start.Line { 38 return iRange.Start.Line < jRange.Start.Line 39 } 40 if iRange.Start.Column != jRange.Start.Column { 41 return iRange.Start.Column < jRange.Start.Column 42 } 43 if iRange.End.Line != jRange.End.Line { 44 return iRange.End.Line > jRange.End.Line 45 } 46 if iRange.End.Column != jRange.End.Column { 47 return iRange.End.Column > jRange.End.Column 48 } 49 return issues[i].Rule.Name() < issues[j].Rule.Name() 50 }) 51 return issues 52 }