Linter configuration fixes and linting issues fixes.

Fixes #17.
This commit is contained in:
Stanislav Nikitin 2020-02-29 22:41:06 +05:00
parent 11897d0e1a
commit 47672c586d
No known key found for this signature in database
GPG Key ID: 106900B32F8192EE
6 changed files with 17 additions and 9 deletions

View File

@ -10,9 +10,12 @@ linters:
- gocritic
# Complains about main() lengths, which isn't an issue.
- funlen
# Magic numbers everywhere and we can't get rid of them.
- gomnd
linters-settings:
lll:
line-length: 420
gocognit:
min-complexity: 50
gocyclo:
min-complexity: 40

View File

@ -232,7 +232,7 @@ func pastePasswordedVerifyGet(ec echo.Context) error {
func pastePasswordedVerifyPost(ec echo.Context) error {
// We should check if database connection available.
dbConn := c.Database.GetDatabaseConnection()
// nolint
if c.Config.Database.Type != "flatfiles" && dbConn == nil {
return ec.Redirect(http.StatusFound, "/database_not_available")
}

View File

@ -48,9 +48,9 @@ func pastePOSTWebInterface(ec echo.Context) error {
return ec.HTML(http.StatusBadRequest, errtpl)
}
// nolint
if !strings.ContainsAny(params["paste-keep-for"][0], "Mmhd") && params["paste-keep-for"][0] != "forever" {
c.Logger.Debug().Str("field value", params["paste-keep-for"][0]).Msg("'Keep paste for' field have invalid value")
errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
return ec.HTML(http.StatusBadRequest, errtpl)

View File

@ -96,8 +96,7 @@ func (ff *FlatFiles) GetPagedPastes(page int) ([]structs.Paste, error) {
c.Logger.Debug().Msgf("%+v", publicPastes)
// Iteration two - get paginated pastes.
// nolint
var pastesData []structs.Paste
pastesData := make([]structs.Paste, 0)
for idx, paste := range publicPastes {
if len(pastesData) == c.Config.Pastes.Pagination {

View File

@ -30,8 +30,14 @@ import (
)
func InitialUp(tx *sql.Tx) error {
// nolint
_, err := tx.Exec("CREATE TABLE `pastes` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Paste ID', `title` text NOT NULL COMMENT 'Paste title', `data` longtext NOT NULL COMMENT 'Paste data', `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Paste creation timestamp', `keep_for` int(4) NOT NULL DEFAULT 1 COMMENT 'Keep for integer. 0 - forever.', `keep_for_unit_type` int(1) NOT NULL DEFAULT 1 COMMENT 'Keep for unit type. 1 - minutes, 2 - hours, 3 - days, 4 - months.', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Pastes';")
_, err := tx.Exec(`CREATE TABLE pastes (
id int(11) NOT NULL AUTO_INCREMENT COMMENT 'Paste ID',
title text NOT NULL COMMENT 'Paste title',
data longtext NOT NULL COMMENT 'Paste data',
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Paste creation timestamp',
keep_for int(4) NOT NULL DEFAULT 1 COMMENT 'Keep for integer. 0 - forever.',
keep_for_unit_type int(1) NOT NULL DEFAULT 1 COMMENT 'Keep for unit type. 1 - minutes, 2 - hours, 3 - days, 4 - months.',
PRIMARY KEY (id), UNIQUE KEY id (id)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Pastes';`)
if err != nil {
return err
}

View File

@ -10,7 +10,6 @@ import (
)
// CreateHTML creates pagination HTML based on passed parameters.
// nolint
func CreateHTML(currentPage int, pages int, linksBase string) string {
// Load templates.
paginationHTMLRaw, err := static.ReadFile("pagination.html")
@ -55,6 +54,7 @@ func CreateHTML(currentPage int, pages int, linksBase string) string {
if i == currentPage {
paginationItemRaw = string(paginationLinkCurrentRaw)
}
paginationItem := strings.Replace(paginationItemRaw, "{pageNum}", strconv.Itoa(i), -1)
paginationItem = strings.Replace(paginationItem, "{paginationLink}", linksBase+strconv.Itoa(i), 1)
paginationString += paginationItem
@ -77,7 +77,7 @@ func CreateHTML(currentPage int, pages int, linksBase string) string {
paginationString += paginationItem
}
i += 1
i++
}
pagination := strings.Replace(string(paginationHTMLRaw), "{paginationLinks}", paginationString, 1)