| 116 | } |
| 117 | |
| 118 | func doSuppress(report Report, suppressedOutputLineRegex []string) (Report, error) { |
| 119 | if len(report.Entries) == 0 || len(suppressedOutputLineRegex) == 0 { |
| 120 | return report, nil |
| 121 | } |
| 122 | |
| 123 | filteredReport := Report{ |
| 124 | findRenames: report.findRenames, |
| 125 | } |
| 126 | filteredReport.format = report.format |
| 127 | filteredReport.Entries = []ReportEntry{} |
| 128 | |
| 129 | var suppressOutputRegexes []*regexp.Regexp |
| 130 | |
| 131 | for _, suppressOutputRegex := range suppressedOutputLineRegex { |
| 132 | regex, err := regexp.Compile(suppressOutputRegex) |
| 133 | if err != nil { |
| 134 | return Report{}, err |
| 135 | } |
| 136 | |
| 137 | suppressOutputRegexes = append(suppressOutputRegexes, regex) |
| 138 | } |
| 139 | |
| 140 | for _, entry := range report.Entries { |
| 141 | var diffs []difflib.DiffRecord |
| 142 | |
| 143 | DIFFS: |
| 144 | for _, diff := range entry.Diffs { |
| 145 | for _, suppressOutputRegex := range suppressOutputRegexes { |
| 146 | if suppressOutputRegex.MatchString(diff.Payload) { |
| 147 | continue DIFFS |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | diffs = append(diffs, diff) |
| 152 | } |
| 153 | |
| 154 | containsDiff := false |
| 155 | |
| 156 | // Add entry to the report, if diffs are present. |
| 157 | for _, diff := range diffs { |
| 158 | if diff.Delta.String() != " " { |
| 159 | containsDiff = true |
| 160 | break |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | diffRecords := []difflib.DiffRecord{} |
| 165 | switch { |
| 166 | case containsDiff: |
| 167 | diffRecords = diffs |
| 168 | case entry.ChangeType == "MODIFY": |
| 169 | entry.ChangeType = "MODIFY_SUPPRESSED" |
| 170 | } |
| 171 | |
| 172 | filteredReport.addEntry(entry.Key, entry.SuppressedKinds, entry.Kind, entry.Context, diffRecords, entry.ChangeType, entry.Structured) |
| 173 | } |
| 174 | |
| 175 | return filteredReport, nil |