mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-22 01:34:18 +00:00
format with gofumpt (#18184)
* gofumpt -w -l . * gofumpt -w -l -extra . * Add linter * manual fix * change make fmt
This commit is contained in:
parent
1d98d205f5
commit
54e9ee37a7
423 changed files with 1585 additions and 1758 deletions
|
@ -12,9 +12,11 @@ import (
|
|||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
const unmappedColumn = -1
|
||||
const maxRowsToInspect int = 10
|
||||
const minRatioToMatch float32 = 0.8
|
||||
const (
|
||||
unmappedColumn = -1
|
||||
maxRowsToInspect int = 10
|
||||
minRatioToMatch float32 = 0.8
|
||||
)
|
||||
|
||||
// TableDiffCellType represents the type of a TableDiffCell.
|
||||
type TableDiffCellType uint8
|
||||
|
@ -172,7 +174,7 @@ func createCsvDiff(diffFile *DiffFile, baseReader, headReader *csv.Reader) ([]*T
|
|||
// createDiffTableRow takes the row # of the `a` line and `b` line of a diff (starting from 1), 0 if the line doesn't exist (undefined)
|
||||
// in the base or head respectively.
|
||||
// Returns a TableDiffRow which has the row index
|
||||
createDiffTableRow := func(aLineNum int, bLineNum int) (*TableDiffRow, error) {
|
||||
createDiffTableRow := func(aLineNum, bLineNum int) (*TableDiffRow, error) {
|
||||
// diffTableCells is a row of the diff table. It will have a cells for added, deleted, changed, and unchanged content, thus either
|
||||
// the same size as the head table or bigger
|
||||
diffTableCells := make([]*TableDiffCell, numDiffTableCols)
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
)
|
||||
|
||||
func TestCSVDiff(t *testing.T) {
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
diff string
|
||||
base string
|
||||
head string
|
||||
|
@ -35,7 +35,8 @@ func TestCSVDiff(t *testing.T) {
|
|||
a,a`,
|
||||
cells: [][]TableDiffCellType{
|
||||
{TableDiffCellAdd, TableDiffCellAdd},
|
||||
{TableDiffCellAdd, TableDiffCellAdd}},
|
||||
{TableDiffCellAdd, TableDiffCellAdd},
|
||||
},
|
||||
},
|
||||
// case 1 - adding 1 row at end
|
||||
{
|
||||
|
@ -53,7 +54,8 @@ a,a`,
|
|||
a,a
|
||||
b,b`,
|
||||
cells: [][]TableDiffCellType{
|
||||
{TableDiffCellUnchanged, TableDiffCellUnchanged}, {TableDiffCellUnchanged, TableDiffCellUnchanged},
|
||||
{TableDiffCellUnchanged, TableDiffCellUnchanged},
|
||||
{TableDiffCellUnchanged, TableDiffCellUnchanged},
|
||||
{TableDiffCellAdd, TableDiffCellAdd},
|
||||
},
|
||||
},
|
||||
|
@ -72,7 +74,8 @@ b,b`,
|
|||
head: `col1,col2
|
||||
b,b`,
|
||||
cells: [][]TableDiffCellType{
|
||||
{TableDiffCellUnchanged, TableDiffCellUnchanged}, {TableDiffCellDel, TableDiffCellDel},
|
||||
{TableDiffCellUnchanged, TableDiffCellUnchanged},
|
||||
{TableDiffCellDel, TableDiffCellDel},
|
||||
{TableDiffCellUnchanged, TableDiffCellUnchanged},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -190,9 +190,11 @@ var (
|
|||
codeTagSuffix = []byte(`</span>`)
|
||||
)
|
||||
|
||||
var unfinishedtagRegex = regexp.MustCompile(`<[^>]*$`)
|
||||
var trailingSpanRegex = regexp.MustCompile(`<span\s*[[:alpha:]="]*?[>]?$`)
|
||||
var entityRegex = regexp.MustCompile(`&[#]*?[0-9[:alpha:]]*$`)
|
||||
var (
|
||||
unfinishedtagRegex = regexp.MustCompile(`<[^>]*$`)
|
||||
trailingSpanRegex = regexp.MustCompile(`<span\s*[[:alpha:]="]*?[>]?$`)
|
||||
entityRegex = regexp.MustCompile(`&[#]*?[0-9[:alpha:]]*$`)
|
||||
)
|
||||
|
||||
// shouldWriteInline represents combinations where we manually write inline changes
|
||||
func shouldWriteInline(diff diffmatchpatch.Diff, lineType DiffLineType) bool {
|
||||
|
@ -206,7 +208,6 @@ func shouldWriteInline(diff diffmatchpatch.Diff, lineType DiffLineType) bool {
|
|||
}
|
||||
|
||||
func fixupBrokenSpans(diffs []diffmatchpatch.Diff) []diffmatchpatch.Diff {
|
||||
|
||||
// Create a new array to store our fixed up blocks
|
||||
fixedup := make([]diffmatchpatch.Diff, 0, len(diffs))
|
||||
|
||||
|
@ -658,10 +659,10 @@ func (diffFile *DiffFile) GetTailSection(gitRepo *git.Repository, leftCommitID,
|
|||
LastRightIdx: lastLine.RightIdx,
|
||||
LeftIdx: leftLineCount,
|
||||
RightIdx: rightLineCount,
|
||||
}}
|
||||
},
|
||||
}
|
||||
tailSection := &DiffSection{FileName: diffFile.Name, Lines: []*DiffLine{tailDiffLine}}
|
||||
return tailSection
|
||||
|
||||
}
|
||||
|
||||
func getCommitFileLineCount(commit *git.Commit, filePath string) int {
|
||||
|
@ -942,8 +943,8 @@ parsingLoop:
|
|||
// TODO: There are numerous issues with this:
|
||||
// - we might want to consider detecting encoding while parsing but...
|
||||
// - we're likely to fail to get the correct encoding here anyway as we won't have enough information
|
||||
var diffLineTypeBuffers = make(map[DiffLineType]*bytes.Buffer, 3)
|
||||
var diffLineTypeDecoders = make(map[DiffLineType]*encoding.Decoder, 3)
|
||||
diffLineTypeBuffers := make(map[DiffLineType]*bytes.Buffer, 3)
|
||||
diffLineTypeDecoders := make(map[DiffLineType]*encoding.Decoder, 3)
|
||||
diffLineTypeBuffers[DiffLinePlain] = new(bytes.Buffer)
|
||||
diffLineTypeBuffers[DiffLineAdd] = new(bytes.Buffer)
|
||||
diffLineTypeBuffers[DiffLineDel] = new(bytes.Buffer)
|
||||
|
@ -1539,7 +1540,8 @@ func GetWhitespaceFlag(whiteSpaceBehavior string) string {
|
|||
"ignore-all": "-w",
|
||||
"ignore-change": "-b",
|
||||
"ignore-eol": "--ignore-space-at-eol",
|
||||
"": ""}
|
||||
"": "",
|
||||
}
|
||||
|
||||
return whitespaceFlags[whiteSpaceBehavior]
|
||||
}
|
||||
|
|
|
@ -504,7 +504,7 @@ index 6961180..9ba1a00 100644
|
|||
// Test max lines
|
||||
diffBuilder := &strings.Builder{}
|
||||
|
||||
var diff = `diff --git a/newfile2 b/newfile2
|
||||
diff := `diff --git a/newfile2 b/newfile2
|
||||
new file mode 100644
|
||||
index 0000000..6bb8f39
|
||||
--- /dev/null
|
||||
|
@ -594,7 +594,7 @@ index 0000000..6bb8f39
|
|||
}
|
||||
println(result)
|
||||
|
||||
var diff2 = `diff --git "a/A \\ B" "b/A \\ B"
|
||||
diff2 := `diff --git "a/A \\ B" "b/A \\ B"
|
||||
--- "a/A \\ B"
|
||||
+++ "b/A \\ B"
|
||||
@@ -1,3 +1,6 @@
|
||||
|
@ -611,7 +611,7 @@ index 0000000..6bb8f39
|
|||
}
|
||||
println(result)
|
||||
|
||||
var diff2a = `diff --git "a/A \\ B" b/A/B
|
||||
diff2a := `diff --git "a/A \\ B" b/A/B
|
||||
--- "a/A \\ B"
|
||||
+++ b/A/B
|
||||
@@ -1,3 +1,6 @@
|
||||
|
@ -628,7 +628,7 @@ index 0000000..6bb8f39
|
|||
}
|
||||
println(result)
|
||||
|
||||
var diff3 = `diff --git a/README.md b/README.md
|
||||
diff3 := `diff --git a/README.md b/README.md
|
||||
--- a/README.md
|
||||
+++ b/README.md
|
||||
@@ -1,3 +1,6 @@
|
||||
|
@ -665,6 +665,7 @@ func setupDefaultDiff() *Diff {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiff_LoadComments(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue