-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charlie Egan <[email protected]>
- Loading branch information
1 parent
9d2482f
commit c527195
Showing
9 changed files
with
97 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package fp | ||
package fileprovider | ||
|
||
import "github.com/styrainc/regal/pkg/rules" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package fp | ||
package fileprovider | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package fp | ||
package fileprovider | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package fixer | ||
|
||
import "slices" | ||
|
||
// Report contains updated file contents and summary information about the fixes that were applied | ||
// during a fix operation. | ||
type Report struct { | ||
totalFixes int | ||
fileFixedViolations map[string]map[string]struct{} | ||
} | ||
|
||
func NewReport() *Report { | ||
return &Report{ | ||
fileFixedViolations: make(map[string]map[string]struct{}), | ||
} | ||
} | ||
|
||
func (r *Report) SetFileFixedViolation(file string, violation string) { | ||
if _, ok := r.fileFixedViolations[file]; !ok { | ||
r.fileFixedViolations[file] = make(map[string]struct{}) | ||
} | ||
|
||
_, ok := r.fileFixedViolations[file][violation] | ||
if !ok { | ||
r.fileFixedViolations[file][violation] = struct{}{} | ||
r.totalFixes++ | ||
} | ||
} | ||
|
||
func (r *Report) FixedViolationsForFile(file string) []string { | ||
fixedViolations := make([]string, 0) | ||
for violation := range r.fileFixedViolations[file] { | ||
fixedViolations = append(fixedViolations, violation) | ||
} | ||
|
||
// sort the violations for deterministic output | ||
slices.Sort(fixedViolations) | ||
|
||
return fixedViolations | ||
} | ||
|
||
func (r *Report) FixedFiles() []string { | ||
fixedFiles := make([]string, 0) | ||
for file := range r.fileFixedViolations { | ||
fixedFiles = append(fixedFiles, file) | ||
} | ||
|
||
// sort the files for deterministic output | ||
slices.Sort(fixedFiles) | ||
|
||
return fixedFiles | ||
} | ||
|
||
func (r *Report) TotalFixes() int { | ||
// totalFixes is incremented for each unique violation that is fixed | ||
return r.totalFixes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters