-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2db4342
commit 7506201
Showing
7 changed files
with
125 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package config | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/caitlinelfring/woke/pkg/printer" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
const ( | ||
OutFormatText = "text" | ||
OutFormatSimple = "simple" | ||
) | ||
|
||
var OutFormats = []string{ | ||
OutFormatText, | ||
OutFormatSimple, | ||
} | ||
|
||
var OutFormatsString = strings.Join(OutFormats, ",") | ||
|
||
func CreatePrinter(f string) printer.Printer { | ||
var p printer.Printer | ||
switch f { | ||
case OutFormatText: | ||
p = printer.NewText() | ||
case OutFormatSimple: | ||
p = printer.NewSimple() | ||
} | ||
log.Debug().Str("printer", f).Msg("created new printer") | ||
return p | ||
} |
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,7 @@ | ||
package printer | ||
|
||
import "github.com/caitlinelfring/woke/pkg/result" | ||
|
||
type Printer interface { | ||
Print(*result.FileResults) error | ||
} |
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,35 @@ | ||
package printer | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/caitlinelfring/woke/pkg/result" | ||
) | ||
|
||
// Simple | ||
type Simple struct{} | ||
|
||
func NewSimple() *Simple { | ||
return &Simple{} | ||
} | ||
|
||
// Print prints in the format 'filename:line:column: message' | ||
func (p *Simple) Print(fs *result.FileResults) error { | ||
var err error | ||
if _, err = fmt.Println(fs.Filename); err != nil { | ||
return err | ||
} | ||
|
||
for _, r := range fs.Results { | ||
out := fmt.Sprintf("%s:%d: [%s] %s", | ||
r.Filename, | ||
r.StartPosition.Line, | ||
r.Rule.Severity, | ||
r.Reason()) | ||
|
||
if _, err = fmt.Print(out); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
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,31 @@ | ||
package printer | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/caitlinelfring/woke/pkg/result" | ||
) | ||
|
||
type Text struct{} | ||
|
||
func NewText() *Text { | ||
return &Text{} | ||
} | ||
|
||
func (t *Text) Print(fs *result.FileResults) error { | ||
var err error | ||
if _, err = fmt.Fprintln(os.Stdout, fs.Filename); err != nil { | ||
return err | ||
} | ||
for _, r := range fs.Results { | ||
pos := fmt.Sprintf("%s-%s", | ||
r.StartPosition.String(), | ||
r.EndPosition.String()) | ||
|
||
if _, err = fmt.Fprintf(os.Stdout, " %-14s %-10s %s\n", pos, r.Rule.Severity, r.Reason()); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
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