1
0
mirror of https://github.com/mgechev/revive.git synced 2025-01-06 03:04:06 +02:00

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
This commit is contained in:
mgechev 2018-10-30 16:07:32 -07:00
parent 376425d517
commit 2020b30eef
No known key found for this signature in database
GPG Key ID: A98CD29F2650FAD2
14 changed files with 48 additions and 7 deletions

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 410 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

BIN
assets/formatter-plain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 KiB

BIN
assets/formatter-unix.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 229 KiB

View File

@ -82,6 +82,7 @@ var allFormatters = []lint.Formatter{
&formatter.Default{},
&formatter.Unix{},
&formatter.Checkstyle{},
&formatter.Plain{},
}
func getFormatters() map[string]lint.Formatter {

View File

@ -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
}

View File

@ -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) {

26
formatter/plain.go Normal file
View 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
}

View File

@ -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}
}