forked from forgejo/forgejo
Rename scripts to build and add revive command as a new build tool command (#10942)
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
4af7c47b38
commit
4f63f283c4
182 changed files with 15832 additions and 1226 deletions
76
vendor/github.com/mgechev/revive/formatter/checkstyle.go
generated
vendored
Normal file
76
vendor/github.com/mgechev/revive/formatter/checkstyle.go
generated
vendored
Normal file
|
@ -0,0 +1,76 @@
|
|||
package formatter
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"github.com/mgechev/revive/lint"
|
||||
plainTemplate "text/template"
|
||||
)
|
||||
|
||||
// Checkstyle is an implementation of the Formatter interface
|
||||
// which formats the errors to Checkstyle-like format.
|
||||
type Checkstyle struct {
|
||||
Metadata lint.FormatterMetadata
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Checkstyle) Name() string {
|
||||
return "checkstyle"
|
||||
}
|
||||
|
||||
type issue struct {
|
||||
Line int
|
||||
Col int
|
||||
What string
|
||||
Confidence float64
|
||||
Severity lint.Severity
|
||||
RuleName string
|
||||
}
|
||||
|
||||
// Format formats the failures gotten from the lint.
|
||||
func (f *Checkstyle) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
|
||||
var issues = map[string][]issue{}
|
||||
for failure := range failures {
|
||||
buf := new(bytes.Buffer)
|
||||
xml.Escape(buf, []byte(failure.Failure))
|
||||
what := buf.String()
|
||||
iss := issue{
|
||||
Line: failure.Position.Start.Line,
|
||||
Col: failure.Position.Start.Column,
|
||||
What: what,
|
||||
Confidence: failure.Confidence,
|
||||
Severity: severity(config, failure),
|
||||
RuleName: failure.RuleName,
|
||||
}
|
||||
fn := failure.GetFilename()
|
||||
if issues[fn] == nil {
|
||||
issues[fn] = make([]issue, 0)
|
||||
}
|
||||
issues[fn] = append(issues[fn], iss)
|
||||
}
|
||||
|
||||
t, err := plainTemplate.New("revive").Parse(checkstyleTemplate)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
err = t.Execute(buf, issues)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
const checkstyleTemplate = `<?xml version='1.0' encoding='UTF-8'?>
|
||||
<checkstyle version="5.0">
|
||||
{{- range $k, $v := . }}
|
||||
<file name="{{ $k }}">
|
||||
{{- range $i, $issue := $v }}
|
||||
<error line="{{ $issue.Line }}" column="{{ $issue.Col }}" message="{{ $issue.What }} (confidence {{ $issue.Confidence}})" severity="{{ $issue.Severity }}" source="revive/{{ $issue.RuleName }}"/>
|
||||
{{- end }}
|
||||
</file>
|
||||
{{- end }}
|
||||
</checkstyle>`
|
26
vendor/github.com/mgechev/revive/formatter/default.go
generated
vendored
Normal file
26
vendor/github.com/mgechev/revive/formatter/default.go
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
package formatter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mgechev/revive/lint"
|
||||
)
|
||||
|
||||
// Default is an implementation of the Formatter interface
|
||||
// which formats the errors to text.
|
||||
type Default struct {
|
||||
Metadata lint.FormatterMetadata
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Default) Name() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// Format formats the failures gotten from the lint.
|
||||
func (f *Default) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
|
||||
for failure := range failures {
|
||||
fmt.Printf("%v: %s\n", failure.Position.Start, failure.Failure)
|
||||
}
|
||||
return "", nil
|
||||
}
|
146
vendor/github.com/mgechev/revive/formatter/friendly.go
generated
vendored
Normal file
146
vendor/github.com/mgechev/revive/formatter/friendly.go
generated
vendored
Normal file
|
@ -0,0 +1,146 @@
|
|||
package formatter
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/mgechev/revive/lint"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
var (
|
||||
errorEmoji = color.RedString("✘")
|
||||
warningEmoji = color.YellowString("⚠")
|
||||
)
|
||||
|
||||
var newLines = map[rune]bool{
|
||||
0x000A: true,
|
||||
0x000B: true,
|
||||
0x000C: true,
|
||||
0x000D: true,
|
||||
0x0085: true,
|
||||
0x2028: true,
|
||||
0x2029: true,
|
||||
}
|
||||
|
||||
// Friendly is an implementation of the Formatter interface
|
||||
// which formats the errors to JSON.
|
||||
type Friendly struct {
|
||||
Metadata lint.FormatterMetadata
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Friendly) Name() string {
|
||||
return "friendly"
|
||||
}
|
||||
|
||||
// Format formats the failures gotten from the lint.
|
||||
func (f *Friendly) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
|
||||
errorMap := map[string]int{}
|
||||
warningMap := map[string]int{}
|
||||
totalErrors := 0
|
||||
totalWarnings := 0
|
||||
for failure := range failures {
|
||||
sev := severity(config, failure)
|
||||
f.printFriendlyFailure(failure, sev)
|
||||
if sev == lint.SeverityWarning {
|
||||
warningMap[failure.RuleName] = warningMap[failure.RuleName] + 1
|
||||
totalWarnings++
|
||||
}
|
||||
if sev == lint.SeverityError {
|
||||
errorMap[failure.RuleName] = errorMap[failure.RuleName] + 1
|
||||
totalErrors++
|
||||
}
|
||||
}
|
||||
f.printSummary(totalErrors, totalWarnings)
|
||||
f.printStatistics(color.RedString("Errors:"), errorMap)
|
||||
f.printStatistics(color.YellowString("Warnings:"), warningMap)
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (f *Friendly) printFriendlyFailure(failure lint.Failure, severity lint.Severity) {
|
||||
f.printHeaderRow(failure, severity)
|
||||
f.printFilePosition(failure)
|
||||
fmt.Println()
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
func (f *Friendly) printHeaderRow(failure lint.Failure, severity lint.Severity) {
|
||||
emoji := warningEmoji
|
||||
if severity == lint.SeverityError {
|
||||
emoji = errorEmoji
|
||||
}
|
||||
fmt.Print(f.table([][]string{{emoji, "https://revive.run/r#" + failure.RuleName, color.GreenString(failure.Failure)}}))
|
||||
}
|
||||
|
||||
func (f *Friendly) printFilePosition(failure lint.Failure) {
|
||||
fmt.Printf(" %s:%d:%d", failure.GetFilename(), failure.Position.Start.Line, failure.Position.Start.Column)
|
||||
}
|
||||
|
||||
type statEntry struct {
|
||||
name string
|
||||
failures int
|
||||
}
|
||||
|
||||
func (f *Friendly) printSummary(errors, warnings int) {
|
||||
emoji := warningEmoji
|
||||
if errors > 0 {
|
||||
emoji = errorEmoji
|
||||
}
|
||||
problemsLabel := "problems"
|
||||
if errors+warnings == 1 {
|
||||
problemsLabel = "problem"
|
||||
}
|
||||
warningsLabel := "warnings"
|
||||
if warnings == 1 {
|
||||
warningsLabel = "warning"
|
||||
}
|
||||
errorsLabel := "errors"
|
||||
if errors == 1 {
|
||||
errorsLabel = "error"
|
||||
}
|
||||
str := fmt.Sprintf("%d %s (%d %s, %d %s)", errors+warnings, problemsLabel, errors, errorsLabel, warnings, warningsLabel)
|
||||
if errors > 0 {
|
||||
fmt.Printf("%s %s\n", emoji, color.RedString(str))
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
if warnings > 0 {
|
||||
fmt.Printf("%s %s\n", emoji, color.YellowString(str))
|
||||
fmt.Println()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Friendly) printStatistics(header string, stats map[string]int) {
|
||||
if len(stats) == 0 {
|
||||
return
|
||||
}
|
||||
var data []statEntry
|
||||
for name, total := range stats {
|
||||
data = append(data, statEntry{name, total})
|
||||
}
|
||||
sort.Slice(data, func(i, j int) bool {
|
||||
return data[i].failures > data[j].failures
|
||||
})
|
||||
formatted := [][]string{}
|
||||
for _, entry := range data {
|
||||
formatted = append(formatted, []string{color.GreenString(fmt.Sprintf("%d", entry.failures)), entry.name})
|
||||
}
|
||||
fmt.Println(header)
|
||||
fmt.Println(f.table(formatted))
|
||||
}
|
||||
|
||||
func (f *Friendly) table(rows [][]string) string {
|
||||
buf := new(bytes.Buffer)
|
||||
table := tablewriter.NewWriter(buf)
|
||||
table.SetBorder(false)
|
||||
table.SetColumnSeparator("")
|
||||
table.SetRowSeparator("")
|
||||
table.SetAutoWrapText(false)
|
||||
table.AppendBulk(rows)
|
||||
table.Render()
|
||||
return buf.String()
|
||||
}
|
40
vendor/github.com/mgechev/revive/formatter/json.go
generated
vendored
Normal file
40
vendor/github.com/mgechev/revive/formatter/json.go
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
package formatter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mgechev/revive/lint"
|
||||
)
|
||||
|
||||
// JSON is an implementation of the Formatter interface
|
||||
// which formats the errors to JSON.
|
||||
type JSON struct {
|
||||
Metadata lint.FormatterMetadata
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *JSON) Name() string {
|
||||
return "json"
|
||||
}
|
||||
|
||||
// jsonObject defines a JSON object of an failure
|
||||
type jsonObject struct {
|
||||
Severity lint.Severity
|
||||
lint.Failure `json:",inline"`
|
||||
}
|
||||
|
||||
// Format formats the failures gotten from the lint.
|
||||
func (f *JSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
|
||||
var slice []jsonObject
|
||||
for failure := range failures {
|
||||
obj := jsonObject{}
|
||||
obj.Severity = severity(config, failure)
|
||||
obj.Failure = failure
|
||||
slice = append(slice, obj)
|
||||
}
|
||||
result, err := json.Marshal(slice)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(result), err
|
||||
}
|
34
vendor/github.com/mgechev/revive/formatter/ndjson.go
generated
vendored
Normal file
34
vendor/github.com/mgechev/revive/formatter/ndjson.go
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
package formatter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/mgechev/revive/lint"
|
||||
)
|
||||
|
||||
// NDJSON is an implementation of the Formatter interface
|
||||
// which formats the errors to NDJSON stream.
|
||||
type NDJSON struct {
|
||||
Metadata lint.FormatterMetadata
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *NDJSON) Name() string {
|
||||
return "ndjson"
|
||||
}
|
||||
|
||||
// Format formats the failures gotten from the lint.
|
||||
func (f *NDJSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
for failure := range failures {
|
||||
obj := jsonObject{}
|
||||
obj.Severity = severity(config, failure)
|
||||
obj.Failure = failure
|
||||
err := enc.Encode(obj)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return "", nil
|
||||
}
|
26
vendor/github.com/mgechev/revive/formatter/plain.go
generated
vendored
Normal file
26
vendor/github.com/mgechev/revive/formatter/plain.go
generated
vendored
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.Config) (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
|
||||
}
|
13
vendor/github.com/mgechev/revive/formatter/severity.go
generated
vendored
Normal file
13
vendor/github.com/mgechev/revive/formatter/severity.go
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
package formatter
|
||||
|
||||
import "github.com/mgechev/revive/lint"
|
||||
|
||||
func severity(config lint.Config, failure lint.Failure) lint.Severity {
|
||||
if config, ok := config.Rules[failure.RuleName]; ok && config.Severity == lint.SeverityError {
|
||||
return lint.SeverityError
|
||||
}
|
||||
if config, ok := config.Directives[failure.RuleName]; ok && config.Severity == lint.SeverityError {
|
||||
return lint.SeverityError
|
||||
}
|
||||
return lint.SeverityWarning
|
||||
}
|
89
vendor/github.com/mgechev/revive/formatter/stylish.go
generated
vendored
Normal file
89
vendor/github.com/mgechev/revive/formatter/stylish.go
generated
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
package formatter
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/mgechev/revive/lint"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
// Stylish is an implementation of the Formatter interface
|
||||
// which formats the errors to JSON.
|
||||
type Stylish struct {
|
||||
Metadata lint.FormatterMetadata
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Stylish) Name() string {
|
||||
return "stylish"
|
||||
}
|
||||
|
||||
func formatFailure(failure lint.Failure, severity lint.Severity) []string {
|
||||
fString := color.CyanString(failure.Failure)
|
||||
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("https://revive.run/r#" + failure.RuleName)
|
||||
}
|
||||
return []string{failure.GetFilename(), pos, fName, fString}
|
||||
}
|
||||
|
||||
// Format formats the failures gotten from the lint.
|
||||
func (f *Stylish) Format(failures <-chan lint.Failure, config lint.Config) (string, error) {
|
||||
var result [][]string
|
||||
var totalErrors = 0
|
||||
var total = 0
|
||||
|
||||
for f := range failures {
|
||||
total++
|
||||
currentType := severity(config, f)
|
||||
if currentType == lint.SeverityError {
|
||||
totalErrors++
|
||||
}
|
||||
result = append(result, formatFailure(f, lint.Severity(currentType)))
|
||||
}
|
||||
ps := "problems"
|
||||
if total == 1 {
|
||||
ps = "problem"
|
||||
}
|
||||
|
||||
fileReport := make(map[string][][]string)
|
||||
|
||||
for _, row := range result {
|
||||
if _, ok := fileReport[row[0]]; !ok {
|
||||
fileReport[row[0]] = [][]string{}
|
||||
}
|
||||
|
||||
fileReport[row[0]] = append(fileReport[row[0]], []string{row[1], row[2], row[3]})
|
||||
}
|
||||
|
||||
output := ""
|
||||
for filename, val := range fileReport {
|
||||
buf := new(bytes.Buffer)
|
||||
table := tablewriter.NewWriter(buf)
|
||||
table.SetBorder(false)
|
||||
table.SetColumnSeparator("")
|
||||
table.SetRowSeparator("")
|
||||
table.SetAutoWrapText(false)
|
||||
table.AppendBulk(val)
|
||||
table.Render()
|
||||
c := color.New(color.Underline)
|
||||
output += c.SprintfFunc()(filename + "\n")
|
||||
output += buf.String() + "\n"
|
||||
}
|
||||
|
||||
suffix := fmt.Sprintf(" %d %s (%d errors) (%d warnings)", total, ps, totalErrors, total-totalErrors)
|
||||
|
||||
if total > 0 && totalErrors > 0 {
|
||||
suffix = color.RedString("\n ✖" + suffix)
|
||||
} else if total > 0 && totalErrors == 0 {
|
||||
suffix = color.YellowString("\n ✖" + suffix)
|
||||
} else {
|
||||
suffix, output = "", ""
|
||||
}
|
||||
|
||||
return output + suffix, nil
|
||||
}
|
27
vendor/github.com/mgechev/revive/formatter/unix.go
generated
vendored
Normal file
27
vendor/github.com/mgechev/revive/formatter/unix.go
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
package formatter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mgechev/revive/lint"
|
||||
)
|
||||
|
||||
// Unix is an implementation of the Formatter interface
|
||||
// which formats the errors to a simple line based error format
|
||||
// main.go:24:9: [errorf] should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
|
||||
type Unix struct {
|
||||
Metadata lint.FormatterMetadata
|
||||
}
|
||||
|
||||
// Name returns the name of the formatter
|
||||
func (f *Unix) Name() string {
|
||||
return "unix"
|
||||
}
|
||||
|
||||
// Format formats the failures gotten from the lint.
|
||||
func (f *Unix) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
|
||||
for failure := range failures {
|
||||
fmt.Printf("%v: [%s] %s\n", failure.Position.Start, failure.RuleName, failure.Failure)
|
||||
}
|
||||
return "", nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue