diff --git a/README.md b/README.md index 7832a60..23aea38 100644 --- a/README.md +++ b/README.md @@ -300,15 +300,29 @@ This section lists all the available formatters and provides a screenshot for ea ### Friendly -![Friendly formatter](/assets/friendly-formatter.png) +![Friendly formatter](/assets/formatter-friendly.png) ### Stylish -![Stylish formatter](/assets/stylish-formatter.png) +![Stylish formatter](/assets/formatter-stylish.png) ### Default -![Default formatter](/assets/default-formatter.png) +The default formatter produces the same output as `golint`. + +![Default formatter](/assets/formatter-default.png) + +### Plain + +The plain formatter produces the same output as the default formatter and appends URL to the rule description. + +![Plain formatter](/assets/formatter-plain.png) + +### Unix + +The unix formatter produces the same output as the default formatter but surrounds the rules in `[]`. + +![Unix formatter](/assets/formatter-unix.png) ## Extensibility diff --git a/assets/default-formatter.png b/assets/default-formatter.png deleted file mode 100644 index 5292959..0000000 Binary files a/assets/default-formatter.png and /dev/null differ diff --git a/assets/formatter-default.png b/assets/formatter-default.png new file mode 100644 index 0000000..f35852b Binary files /dev/null and b/assets/formatter-default.png differ diff --git a/assets/formatter-friendly.png b/assets/formatter-friendly.png new file mode 100644 index 0000000..f93d992 Binary files /dev/null and b/assets/formatter-friendly.png differ diff --git a/assets/formatter-plain.png b/assets/formatter-plain.png new file mode 100644 index 0000000..67e654e Binary files /dev/null and b/assets/formatter-plain.png differ diff --git a/assets/formatter-stylish.png b/assets/formatter-stylish.png new file mode 100644 index 0000000..d044c5b Binary files /dev/null and b/assets/formatter-stylish.png differ diff --git a/assets/formatter-unix.png b/assets/formatter-unix.png new file mode 100644 index 0000000..a68b479 Binary files /dev/null and b/assets/formatter-unix.png differ diff --git a/assets/friendly-formatter.png b/assets/friendly-formatter.png deleted file mode 100644 index 0838ea2..0000000 Binary files a/assets/friendly-formatter.png and /dev/null differ diff --git a/assets/stylish-formatter.png b/assets/stylish-formatter.png deleted file mode 100644 index 7ceaa2e..0000000 Binary files a/assets/stylish-formatter.png and /dev/null differ diff --git a/config.go b/config.go index d6b1a6b..9f6188d 100644 --- a/config.go +++ b/config.go @@ -82,6 +82,7 @@ var allFormatters = []lint.Formatter{ &formatter.Default{}, &formatter.Unix{}, &formatter.Checkstyle{}, + &formatter.Plain{}, } func getFormatters() map[string]lint.Formatter { diff --git a/formatter/default.go b/formatter/default.go index 4544a1e..415c95c 100644 --- a/formatter/default.go +++ b/formatter/default.go @@ -7,7 +7,7 @@ import ( ) // Default is an implementation of the Formatter interface -// which formats the errors to JSON. +// which formats the errors to text. type Default struct { Metadata lint.FormatterMetadata } diff --git a/formatter/friendly.go b/formatter/friendly.go index 84b5d34..01f22c8 100644 --- a/formatter/friendly.go +++ b/formatter/friendly.go @@ -72,7 +72,7 @@ func (f *Friendly) printHeaderRow(failure lint.Failure, severity lint.Severity) if severity == lint.SeverityError { emoji = errorEmoji } - fmt.Print(f.table([][]string{{emoji, failure.RuleName, color.GreenString(failure.Failure)}})) + fmt.Print(f.table([][]string{{emoji, "https://revive.run/r#" + failure.RuleName, color.GreenString(failure.Failure)}})) } func (f *Friendly) printFilePosition(failure lint.Failure) { diff --git a/formatter/plain.go b/formatter/plain.go new file mode 100644 index 0000000..aef9a0c --- /dev/null +++ b/formatter/plain.go @@ -0,0 +1,26 @@ +package formatter + +import ( + "fmt" + + "github.com/mgechev/revive/lint" +) + +// Plain is an implementation of the Formatter interface +// which formats the errors to JSON. +type Plain struct { + Metadata lint.FormatterMetadata +} + +// Name returns the name of the formatter +func (f *Plain) Name() string { + return "plain" +} + +// Format formats the failures gotten from the lint. +func (f *Plain) Format(failures <-chan lint.Failure, _ lint.RulesConfig) (string, error) { + for failure := range failures { + fmt.Printf("%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName) + } + return "", nil +} diff --git a/formatter/stylish.go b/formatter/stylish.go index 8e86725..9d3286c 100644 --- a/formatter/stylish.go +++ b/formatter/stylish.go @@ -22,11 +22,11 @@ func (f *Stylish) Name() string { func formatFailure(failure lint.Failure, severity lint.Severity) []string { fString := color.CyanString(failure.Failure) - fName := color.RedString(failure.RuleName) + fName := color.RedString("https://revive.run/r#" + failure.RuleName) lineColumn := failure.Position pos := fmt.Sprintf("(%d, %d)", lineColumn.Start.Line, lineColumn.Start.Column) if severity == lint.SeverityWarning { - fName = color.YellowString(failure.RuleName) + fName = color.YellowString("https://revive.run/r#" + failure.RuleName) } return []string{failure.GetFilename(), pos, fName, fString} }