feat: add links to rules in formatters
This PR introduces: - A new formatter called "plain" which produces the same output as "default" but also appends link to the rule - The "friendly" and "stylish" formatters now have URLs to the rules instead of the rule names - Update of the README, adding the "unix" and "plain" formatters
20
README.md
@ -300,15 +300,29 @@ This section lists all the available formatters and provides a screenshot for ea
|
|||||||
|
|
||||||
### Friendly
|
### Friendly
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Stylish
|
### Stylish
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Default
|
### Default
|
||||||
|
|
||||||

|
The default formatter produces the same output as `golint`.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Plain
|
||||||
|
|
||||||
|
The plain formatter produces the same output as the default formatter and appends URL to the rule description.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Unix
|
||||||
|
|
||||||
|
The unix formatter produces the same output as the default formatter but surrounds the rules in `[]`.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Extensibility
|
## Extensibility
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 410 KiB |
BIN
assets/formatter-default.png
Normal file
After Width: | Height: | Size: 279 KiB |
BIN
assets/formatter-friendly.png
Normal file
After Width: | Height: | Size: 241 KiB |
BIN
assets/formatter-plain.png
Normal file
After Width: | Height: | Size: 289 KiB |
BIN
assets/formatter-stylish.png
Normal file
After Width: | Height: | Size: 184 KiB |
BIN
assets/formatter-unix.png
Normal file
After Width: | Height: | Size: 279 KiB |
Before Width: | Height: | Size: 292 KiB |
Before Width: | Height: | Size: 229 KiB |
@ -82,6 +82,7 @@ var allFormatters = []lint.Formatter{
|
|||||||
&formatter.Default{},
|
&formatter.Default{},
|
||||||
&formatter.Unix{},
|
&formatter.Unix{},
|
||||||
&formatter.Checkstyle{},
|
&formatter.Checkstyle{},
|
||||||
|
&formatter.Plain{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFormatters() map[string]lint.Formatter {
|
func getFormatters() map[string]lint.Formatter {
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Default is an implementation of the Formatter interface
|
// Default is an implementation of the Formatter interface
|
||||||
// which formats the errors to JSON.
|
// which formats the errors to text.
|
||||||
type Default struct {
|
type Default struct {
|
||||||
Metadata lint.FormatterMetadata
|
Metadata lint.FormatterMetadata
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func (f *Friendly) printHeaderRow(failure lint.Failure, severity lint.Severity)
|
|||||||
if severity == lint.SeverityError {
|
if severity == lint.SeverityError {
|
||||||
emoji = errorEmoji
|
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) {
|
func (f *Friendly) printFilePosition(failure lint.Failure) {
|
||||||
|
26
formatter/plain.go
Normal file
@ -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
|
||||||
|
}
|
@ -22,11 +22,11 @@ func (f *Stylish) Name() string {
|
|||||||
|
|
||||||
func formatFailure(failure lint.Failure, severity lint.Severity) []string {
|
func formatFailure(failure lint.Failure, severity lint.Severity) []string {
|
||||||
fString := color.CyanString(failure.Failure)
|
fString := color.CyanString(failure.Failure)
|
||||||
fName := color.RedString(failure.RuleName)
|
fName := color.RedString("https://revive.run/r#" + failure.RuleName)
|
||||||
lineColumn := failure.Position
|
lineColumn := failure.Position
|
||||||
pos := fmt.Sprintf("(%d, %d)", lineColumn.Start.Line, lineColumn.Start.Column)
|
pos := fmt.Sprintf("(%d, %d)", lineColumn.Start.Line, lineColumn.Start.Column)
|
||||||
if severity == lint.SeverityWarning {
|
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}
|
return []string{failure.GetFilename(), pos, fName, fString}
|
||||||
}
|
}
|
||||||
|