From 6c4688e1b1ddb68de192af7f83b06de27baae85e Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 25 Aug 2022 23:55:52 +0200 Subject: [PATCH] Add whitespace removal inside template curly brackes (#20853) --- Makefile | 12 ++++++++++-- templates/admin/config.tmpl | 2 +- templates/admin/cron.tmpl | 4 ++-- templates/admin/notice.tmpl | 6 +++--- templates/admin/process-row.tmpl | 2 +- templates/admin/queue.tmpl | 8 ++++---- templates/admin/stacktrace-row.tmpl | 14 +++++++------- templates/base/footer.tmpl | 2 +- templates/base/head.tmpl | 4 ++-- templates/base/head_script.tmpl | 12 ++++++------ templates/explore/code.tmpl | 12 ++++++------ templates/explore/repo_list.tmpl | 12 ++++++------ templates/mail/release.tmpl | 2 +- templates/repo/activity.tmpl | 18 +++++++++--------- templates/repo/commit_page.tmpl | 4 ++-- templates/repo/commits_list.tmpl | 4 ++-- templates/repo/commits_list_small.tmpl | 8 ++++---- templates/repo/commits_table.tmpl | 2 +- templates/repo/forks.tmpl | 2 +- templates/repo/graph.tmpl | 4 ++-- templates/repo/header.tmpl | 14 +++++++------- templates/repo/home.tmpl | 18 +++++++++--------- templates/repo/search.tmpl | 12 ++++++------ templates/repo/sub_menu.tmpl | 16 ++++++++-------- templates/repo/user_cards.tmpl | 2 +- templates/repo/view_file.tmpl | 2 +- templates/repo/view_list.tmpl | 4 ++-- templates/shared/issuelist.tmpl | 6 +++--- templates/user/profile.tmpl | 2 +- templates/user/project.tmpl | 2 +- 30 files changed, 110 insertions(+), 102 deletions(-) diff --git a/Makefile b/Makefile index 44e245d22..f7e91c05a 100644 --- a/Makefile +++ b/Makefile @@ -242,8 +242,10 @@ clean: .PHONY: fmt fmt: - @echo "Running gitea-fmt (with gofumpt)..." @MISSPELL_PACKAGE=$(MISSPELL_PACKAGE) GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}' + $(eval TEMPLATES := $(wildcard templates/**/*.tmpl)) + @# strip whitespace after '{{' and before `}}` unless there is only whitespace before it + @$(SED_INPLACE) -e 's/{{[ ]\{1,\}/{{/g' -e '/^[ ]\{1,\}}}/! s/[ ]\{1,\}}}/}}/g' $(TEMPLATES) .PHONY: vet vet: @@ -288,13 +290,19 @@ errcheck: .PHONY: fmt-check fmt-check: - # get all go files and run gitea-fmt (with gofmt) on them + @# get all go files and run gitea-fmt (with gofmt) on them @diff=$$(MISSPELL_PACKAGE=$(MISSPELL_PACKAGE) GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -l '{file-list}'); \ if [ -n "$$diff" ]; then \ echo "Please run 'make fmt' and commit the result:"; \ echo "$${diff}"; \ exit 1; \ fi + @diff2=$$(git diff templates); \ + if [ -n "$$diff2" ]; then \ + echo "Please run 'make fmt' and commit the result:"; \ + echo "$${diff2}"; \ + exit 1; \ + fi .PHONY: checks checks: checks-frontend checks-backend diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index ccd1029cd..0d9432b39 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -50,7 +50,7 @@
{{.locale.Tr "admin.config.reverse_auth_user"}}
{{.ReverseProxyAuthUser}}
- {{if .EnvVars }} + {{if .EnvVars}}
{{range .EnvVars}}
{{.Name}}
diff --git a/templates/admin/cron.tmpl b/templates/admin/cron.tmpl index b5db356bd..d34999e6e 100644 --- a/templates/admin/cron.tmpl +++ b/templates/admin/cron.tmpl @@ -22,9 +22,9 @@ {{$.locale.Tr (printf "admin.dashboard.%s" .Name)}} {{.Spec}} {{DateFmtLong .Next}} - {{if gt .Prev.Year 1 }}{{DateFmtLong .Prev}}{{else}}N/A{{end}} + {{if gt .Prev.Year 1}}{{DateFmtLong .Prev}}{{else}}N/A{{end}} {{.ExecTimes}} - {{if eq .Status "" }}—{{else if eq .Status "finished"}}{{svg "octicon-check" 16}}{{else}}{{svg "octicon-x" 16}}{{end}} + {{if eq .Status ""}}—{{else if eq .Status "finished"}}{{svg "octicon-check" 16}}{{else}}{{svg "octicon-x" 16}}{{end}} {{end}} diff --git a/templates/admin/notice.tmpl b/templates/admin/notice.tmpl index 7d0fa0019..b831f50c8 100644 --- a/templates/admin/notice.tmpl +++ b/templates/admin/notice.tmpl @@ -34,7 +34,7 @@ {{end}} - {{ if .Notices }} + {{if .Notices}} @@ -65,11 +65,11 @@ - {{ end }} + {{end}} - {{ template "base/paginate" . }} + {{template "base/paginate" .}} diff --git a/templates/admin/process-row.tmpl b/templates/admin/process-row.tmpl index b97d0fc8d..4ab190af4 100644 --- a/templates/admin/process-row.tmpl +++ b/templates/admin/process-row.tmpl @@ -1,6 +1,6 @@
-
{{if eq .Process.Type "request"}}{{svg "octicon-globe" 16 }}{{else if eq .Process.Type "system"}}{{svg "octicon-cpu" 16 }}{{else}}{{svg "octicon-terminal" 16 }}{{end}}
+
{{if eq .Process.Type "request"}}{{svg "octicon-globe" 16}}{{else if eq .Process.Type "system"}}{{svg "octicon-cpu" 16}}{{else}}{{svg "octicon-terminal" 16}}{{end}}
{{.Process.Description}}
{{TimeSince .Process.Start .root.locale}}
diff --git a/templates/admin/queue.tmpl b/templates/admin/queue.tmpl index a7ea4c602..95fd3a5e0 100644 --- a/templates/admin/queue.tmpl +++ b/templates/admin/queue.tmpl @@ -30,12 +30,12 @@
- {{if lt $sum 0 }} + {{if lt $sum 0}}

{{.locale.Tr "admin.monitor.queue.nopool.title"}}

- {{if eq .Queue.Type "wrapped" }} + {{if eq .Queue.Type "wrapped"}}

{{.locale.Tr "admin.monitor.queue.wrapped.desc"}}

{{else if eq .Queue.Type "persistable-channel"}}

{{.locale.Tr "admin.monitor.queue.persistable-channel.desc"}}

@@ -58,7 +58,7 @@
- +
@@ -166,7 +166,7 @@ {{else}} - {{.locale.Tr "admin.monitor.queue.pool.workers.none" }} + {{.locale.Tr "admin.monitor.queue.pool.workers.none"}} {{end}} diff --git a/templates/admin/stacktrace-row.tmpl b/templates/admin/stacktrace-row.tmpl index d8b337fc0..a8ae486bc 100644 --- a/templates/admin/stacktrace-row.tmpl +++ b/templates/admin/stacktrace-row.tmpl @@ -2,13 +2,13 @@
{{if eq .Process.Type "request"}} - {{svg "octicon-globe" 16 }} + {{svg "octicon-globe" 16}} {{else if eq .Process.Type "system"}} - {{svg "octicon-cpu" 16 }} + {{svg "octicon-cpu" 16}} {{else if eq .Process.Type "normal"}} - {{svg "octicon-terminal" 16 }} + {{svg "octicon-terminal" 16}} {{else}} - {{svg "octicon-code" 16 }} + {{svg "octicon-code" 16}} {{end}}
@@ -16,7 +16,7 @@
{{if ne .Process.Type "none"}}{{TimeSince .Process.Start .root.locale}}{{end}}
- {{if or (eq .Process.Type "request") (eq .Process.Type "normal") }} + {{if or (eq .Process.Type "request") (eq .Process.Type "normal")}} {{svg "octicon-trash" 16 "text-red"}} {{end}}
@@ -29,7 +29,7 @@
- {{svg "octicon-code" 16 }}{{.Description}}{{if gt .Count 1}} * {{.Count}}{{end}} + {{svg "octicon-code" 16}}{{.Description}}{{if gt .Count 1}} * {{.Count}}{{end}}
{{range .Labels}} @@ -41,7 +41,7 @@
{{range .Entry}}
- {{svg "octicon-dot-fill" 16 }} + {{svg "octicon-dot-fill" 16}}
{{.Function}}
{{.File}}:{{.Line}}
diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl index 0e1b382d9..3fa0f8e7a 100644 --- a/templates/base/footer.tmpl +++ b/templates/base/footer.tmpl @@ -16,7 +16,7 @@ {{if .EnableCaptcha}} {{if eq .CaptchaType "recaptcha"}} - + {{end}} {{if eq .CaptchaType "hcaptcha"}} diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 233cf3e1d..39749613d 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -65,8 +65,8 @@ {{end}} -{{if .IsSigned }} - {{ if ne .SignedUser.Theme "gitea" }} +{{if .IsSigned}} + {{if ne .SignedUser.Theme "gitea"}} {{end}} {{else if ne DefaultTheme "gitea"}} diff --git a/templates/base/head_script.tmpl b/templates/base/head_script.tmpl index a74923b55..8369b63b3 100644 --- a/templates/base/head_script.tmpl +++ b/templates/base/head_script.tmpl @@ -21,18 +21,18 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly. enableTimeTracking: {{EnableTimetracking}}, {{if .RequireTribute}} tributeValues: Array.from(new Map([ - {{ range .Participants }} + {{range .Participants}} ['{{.Name}}', {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}', name: '{{.Name}}', fullname: '{{.FullName}}', avatar: '{{.AvatarLink}}'}], - {{ end }} - {{ range .Assignees }} + {{end}} + {{range .Assignees}} ['{{.Name}}', {key: '{{.Name}} {{.FullName}}', value: '{{.Name}}', name: '{{.Name}}', fullname: '{{.FullName}}', avatar: '{{.AvatarLink}}'}], - {{ end }} - {{ range .MentionableTeams }} + {{end}} + {{range .MentionableTeams}} ['{{$.MentionableTeamsOrg}}/{{.Name}}', {key: '{{$.MentionableTeamsOrg}}/{{.Name}}', value: '{{$.MentionableTeamsOrg}}/{{.Name}}', name: '{{$.MentionableTeamsOrg}}/{{.Name}}', avatar: '{{$.MentionableTeamsOrgAvatar}}'}], - {{ end }} + {{end}} ]).values()), {{end}} mermaidMaxSourceCharacters: {{MermaidMaxSourceCharacters}}, diff --git a/templates/explore/code.tmpl b/templates/explore/code.tmpl index 45783b226..b6429b191 100644 --- a/templates/explore/code.tmpl +++ b/templates/explore/code.tmpl @@ -4,27 +4,27 @@
- -
- {{if .CodeIndexerUnavailable }} + {{if .CodeIndexerUnavailable}}

{{$.locale.Tr "explore.code_search_unavailable"}}

{{else if .SearchResults}}

- {{.locale.Tr "explore.code_search_results" (.Keyword|Escape) | Str2html }} + {{.locale.Tr "explore.code_search_results" (.Keyword|Escape) | Str2html}}

{{range $term := .SearchResultLanguages}} diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index cd75f4852..2a5c444dc 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -8,7 +8,7 @@ {{$avatar}} {{end}} - {{if or $.PageIsExplore $.PageIsProfileStarList }}{{if .Owner}}{{.Owner.Name}} / {{end}}{{end}}{{.Name}} + {{if or $.PageIsExplore $.PageIsProfileStarList}}{{if .Owner}}{{.Owner.Name}} / {{end}}{{end}}{{.Name}}
{{if .IsArchived}} @@ -39,9 +39,9 @@
- {{if .PrimaryLanguage }} + {{if .PrimaryLanguage}} - {{ .PrimaryLanguage.Language }} + {{.PrimaryLanguage.Language}} {{end}} {{if not $.DisableStars}} @@ -51,12 +51,12 @@
- {{ $description := .DescriptionHTML $.Context}} + {{$description := .DescriptionHTML $.Context}} {{if $description}}

{{$description}}

{{end}} - {{if .Topics }} + {{if .Topics}}
{{range .Topics}} - {{if ne . "" }}
{{.}}
{{end}} + {{if ne . ""}}
{{.}}
{{end}} {{end}}
{{end}} diff --git a/templates/mail/release.tmpl b/templates/mail/release.tmpl index 931c0d1b5..b2acdce8b 100644 --- a/templates/mail/release.tmpl +++ b/templates/mail/release.tmpl @@ -11,7 +11,7 @@ -{{$release_url := printf "%s" (.Release.HTMLURL | Escape) (.Release.TagName | Escape) }} +{{$release_url := printf "%s" (.Release.HTMLURL | Escape) (.Release.TagName | Escape)}} {{$repo_url := printf "%s" (.Release.Repo.HTMLURL | Escape) (.Release.Repo.FullName | Escape)}}

diff --git a/templates/repo/activity.tmpl b/templates/repo/activity.tmpl index 37cdf3ef0..c2f6c2d98 100644 --- a/templates/repo/activity.tmpl +++ b/templates/repo/activity.tmpl @@ -41,7 +41,7 @@

{{end}} - {{.locale.TrN .Activity.ActivePRCount "repo.activity.active_prs_count_1" "repo.activity.active_prs_count_n" .Activity.ActivePRCount | Safe }} + {{.locale.TrN .Activity.ActivePRCount "repo.activity.active_prs_count_1" "repo.activity.active_prs_count_n" .Activity.ActivePRCount | Safe}}
{{end}} {{if .Permission.CanRead $.UnitTypeIssues}} @@ -56,7 +56,7 @@
{{end}} - {{.locale.TrN .Activity.ActiveIssueCount "repo.activity.active_issues_count_1" "repo.activity.active_issues_count_n" .Activity.ActiveIssueCount | Safe }} + {{.locale.TrN .Activity.ActiveIssueCount "repo.activity.active_issues_count_1" "repo.activity.active_issues_count_n" .Activity.ActiveIssueCount | Safe}}
{{end}}
@@ -87,25 +87,25 @@ {{if .Permission.CanRead $.UnitTypeCode}} {{if eq .Activity.Code.CommitCountInAllBranches 0}}
-

{{.locale.Tr "repo.activity.no_git_activity" }}

+

{{.locale.Tr "repo.activity.no_git_activity"}}

{{end}} {{if gt .Activity.Code.CommitCountInAllBranches 0}}
- {{.locale.Tr "repo.activity.git_stats_exclude_merges" }} + {{.locale.Tr "repo.activity.git_stats_exclude_merges"}} {{.locale.TrN .Activity.Code.AuthorCount "repo.activity.git_stats_author_1" "repo.activity.git_stats_author_n" .Activity.Code.AuthorCount}} {{.locale.TrN .Activity.Code.AuthorCount "repo.activity.git_stats_pushed_1" "repo.activity.git_stats_pushed_n"}} {{.locale.TrN .Activity.Code.CommitCount "repo.activity.git_stats_commit_1" "repo.activity.git_stats_commit_n" .Activity.Code.CommitCount}} - {{.locale.Tr "repo.activity.git_stats_push_to_branch" .Repository.DefaultBranch }} + {{.locale.Tr "repo.activity.git_stats_push_to_branch" .Repository.DefaultBranch}} {{.locale.TrN .Activity.Code.CommitCountInAllBranches "repo.activity.git_stats_commit_1" "repo.activity.git_stats_commit_n" .Activity.Code.CommitCountInAllBranches}} - {{.locale.Tr "repo.activity.git_stats_push_to_all_branches" }} - {{.locale.Tr "repo.activity.git_stats_on_default_branch" .Repository.DefaultBranch }} + {{.locale.Tr "repo.activity.git_stats_push_to_all_branches"}} + {{.locale.Tr "repo.activity.git_stats_on_default_branch" .Repository.DefaultBranch}} {{.locale.TrN .Activity.Code.ChangedFiles "repo.activity.git_stats_file_1" "repo.activity.git_stats_file_n" .Activity.Code.ChangedFiles}} {{.locale.TrN .Activity.Code.ChangedFiles "repo.activity.git_stats_files_changed_1" "repo.activity.git_stats_files_changed_n"}} - {{.locale.Tr "repo.activity.git_stats_additions" }} + {{.locale.Tr "repo.activity.git_stats_additions"}} {{.locale.TrN .Activity.Code.Additions "repo.activity.git_stats_addition_1" "repo.activity.git_stats_addition_n" .Activity.Code.Additions}} - {{.locale.Tr "repo.activity.git_stats_and_deletions" }} + {{.locale.Tr "repo.activity.git_stats_and_deletions"}} {{.locale.TrN .Activity.Code.Deletions "repo.activity.git_stats_deletion_1" "repo.activity.git_stats_deletion_n" .Activity.Code.Deletions}}.
diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index 9e3fadee0..8ece76883 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -87,7 +87,7 @@ {{.CsrfTokenHtml}}
@@ -112,7 +112,7 @@
diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index 1003f2ee7..720067ce6 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -62,8 +62,8 @@ {{if $.PageIsWiki}} {{.Summary | RenderEmoji}} - {{else }} - {{ $commitLink:= printf "%s/commit/%s" $commitRepoLink (PathEscape .ID.String) }} + {{else}} + {{$commitLink:= printf "%s/commit/%s" $commitRepoLink (PathEscape .ID.String)}} {{RenderCommitMessageLinkSubject $.Context .Message $commitRepoLink $commitLink $.Repository.ComposeMetas}} {{end}} diff --git a/templates/repo/commits_list_small.tmpl b/templates/repo/commits_list_small.tmpl index c1e136318..f2f121c42 100644 --- a/templates/repo/commits_list_small.tmpl +++ b/templates/repo/commits_list_small.tmpl @@ -1,8 +1,8 @@ -{{ $index := 0}} +{{$index := 0}}
{{range .comment.Commits}} - {{ $tag := printf "%s-%d" $.comment.HashTag $index }} - {{ $index = Add $index 1}} + {{$tag := printf "%s-%d" $.comment.HashTag $index}} + {{$index = Add $index 1}}
{{svg "octicon-git-commit"}} {{if .User}} @@ -46,7 +46,7 @@ {{end}} - {{ $commitLink:= printf "%s/commit/%s" $.comment.Issue.PullRequest.BaseRepo.Link (PathEscape .ID.String) }} + {{$commitLink:= printf "%s/commit/%s" $.comment.Issue.PullRequest.BaseRepo.Link (PathEscape .ID.String)}} {{RenderCommitMessageLinkSubject $.root.Context .Message ($.comment.Issue.PullRequest.BaseRepo.Link|Escape) $commitLink $.comment.Issue.PullRequest.BaseRepo.ComposeMetas}} {{if IsMultilineCommitMessage .Message}} diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl index a15f08da6..ab54041b9 100644 --- a/templates/repo/commits_table.tmpl +++ b/templates/repo/commits_table.tmpl @@ -3,7 +3,7 @@ {{if or .PageIsCommits (gt .CommitCount 0)}} {{.CommitCount}} {{.locale.Tr "repo.commits.commits"}} {{if .RefName}}({{.RefName}}){{end}} {{else if .IsNothingToCompare}} - {{.locale.Tr "repo.commits.nothing_to_compare" }} {{if .RefName}}({{.RefName}}){{end}} + {{.locale.Tr "repo.commits.nothing_to_compare"}} {{if .RefName}}({{.RefName}}){{end}} {{else}} {{.locale.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}} {{if .RefName}}({{.RefName}}){{end}} {{end}} diff --git a/templates/repo/forks.tmpl b/templates/repo/forks.tmpl index a303c9d9f..56e60d422 100644 --- a/templates/repo/forks.tmpl +++ b/templates/repo/forks.tmpl @@ -19,6 +19,6 @@
- {{ template "base/paginate" . }} + {{template "base/paginate" .}}
{{template "base/footer" .}} diff --git a/templates/repo/graph.tmpl b/templates/repo/graph.tmpl index 70985a5fa..7efd6ec02 100644 --- a/templates/repo/graph.tmpl +++ b/templates/repo/graph.tmpl @@ -52,8 +52,8 @@
- {{ template "repo/graph/svgcontainer" .}} - {{ template "repo/graph/commits" .}} + {{template "repo/graph/svgcontainer" .}} + {{template "repo/graph/commits" .}}
diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index a08196f26..831784a62 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -66,7 +66,7 @@ {{end}}
{{$.CsrfTokenHtml}} -
+
@@ -78,7 +78,7 @@ {{if not $.DisableStars}} {{$.CsrfTokenHtml}} -
+
@@ -182,21 +182,21 @@ {{end}} {{if .Permission.CanRead $.UnitTypePackages}} - + {{svg "octicon-package"}} {{.locale.Tr "packages.title"}} {{end}} - {{ if and (not .UnitProjectsGlobalDisabled) (.Permission.CanRead $.UnitTypeProjects)}} - + {{if and (not .UnitProjectsGlobalDisabled) (.Permission.CanRead $.UnitTypeProjects)}} + {{svg "octicon-project"}} {{.locale.Tr "repo.project_board"}} {{if .Repository.NumOpenProjects}} {{CountFmt .Repository.NumOpenProjects}} {{end}} - {{ end }} + {{end}} - {{if and (.Permission.CanRead $.UnitTypeReleases) (not .IsEmptyRepo) }} + {{if and (.Permission.CanRead $.UnitTypeReleases) (not .IsEmptyRepo)}} {{svg "octicon-tag"}} {{.locale.Tr "repo.releases"}} {{if .NumReleases}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 5c3eec8ab..7b74c1cc7 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -5,7 +5,7 @@ {{template "base/alert" .}}
@@ -13,12 +13,12 @@