You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

decorators.go 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package garif
  2. // WithLineColumn sets a physical location with the given line and column
  3. func (l *Location) WithLineColumn(line, column int) *Location {
  4. if l.PhysicalLocation == nil {
  5. l.PhysicalLocation = NewPhysicalLocation()
  6. }
  7. l.PhysicalLocation.Region = NewRegion()
  8. l.PhysicalLocation.Region.StartLine = line
  9. l.PhysicalLocation.Region.StartColumn = column
  10. return l
  11. }
  12. // WithURI sets a physical location with the given URI
  13. func (l *Location) WithURI(uri string) *Location {
  14. if l.PhysicalLocation == nil {
  15. l.PhysicalLocation = NewPhysicalLocation()
  16. }
  17. l.PhysicalLocation.ArtifactLocation = NewArtifactLocation()
  18. l.PhysicalLocation.ArtifactLocation.Uri = uri
  19. return l
  20. }
  21. // WithKeyValue sets (overwrites) the value of the given key
  22. func (b PropertyBag) WithKeyValue(key string, value interface{}) PropertyBag {
  23. b[key] = value
  24. return b
  25. }
  26. // WithHelpUri sets the help URI for this ReportingDescriptor
  27. func (r *ReportingDescriptor) WithHelpUri(uri string) *ReportingDescriptor {
  28. r.HelpUri = uri
  29. return r
  30. }
  31. // WithProperties adds the key & value to the properties of this ReportingDescriptor
  32. func (r *ReportingDescriptor) WithProperties(key string, value interface{}) *ReportingDescriptor {
  33. if r.Properties == nil {
  34. r.Properties = NewPropertyBag()
  35. }
  36. r.Properties.WithKeyValue(key, value)
  37. return r
  38. }
  39. // WithArtifactsURIs adds the given URI as artifacts of this Run
  40. func (r *Run) WithArtifactsURIs(uris ...string) *Run {
  41. if r.Artifacts == nil {
  42. r.Artifacts = []*Artifact{}
  43. }
  44. for _, uri := range uris {
  45. a := NewArtifact()
  46. a.Location = NewArtifactLocation()
  47. a.Location.Uri = uri
  48. r.Artifacts = append(r.Artifacts, a)
  49. }
  50. return r
  51. }
  52. // WithResult adds a result to this Run
  53. func (r *Run) WithResult(ruleId string, message string, uri string, line int, column int) *Run {
  54. if r.Results == nil {
  55. r.Results = []*Result{}
  56. }
  57. msg := NewMessage()
  58. msg.Text = message
  59. result := NewResult(msg)
  60. location := NewLocation().WithURI(uri).WithLineColumn(line, column)
  61. result.Locations = append(result.Locations, location)
  62. result.RuleId = ruleId
  63. r.Results = append(r.Results, result)
  64. return r
  65. }
  66. // WithInformationUri sets the information URI
  67. func (t *ToolComponent) WithInformationUri(uri string) *ToolComponent {
  68. t.InformationUri = uri
  69. return t
  70. }
  71. // WithRules sets (overwrites) the rules
  72. func (t *ToolComponent) WithRules(rules ...*ReportingDescriptor) *ToolComponent {
  73. t.Rules = rules
  74. return t
  75. }