Skip to content

Commit

Permalink
Merge pull request #52 from koddr/main
Browse files Browse the repository at this point in the history
Add golangci-lint; Update dependencies
  • Loading branch information
koddr committed Feb 20, 2024
2 parents ab583c8 + 17df438 commit a92f3c4
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 26 deletions.
1 change: 1 addition & 0 deletions cmd/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func Create(di *injectors.Injector) error {
helpers.MakeStyled(strconv.FormatBool(di.Config.Tools.IsUseAir), &helpers.StringStyle{Color: variables.ColorBlue}),
helpers.MakeStyled(strconv.FormatBool(di.Config.Tools.IsUseBun), &helpers.StringStyle{Color: variables.ColorBlue}),
helpers.MakeStyled(strconv.FormatBool(di.Config.Tools.IsUseTempl), &helpers.StringStyle{Color: variables.ColorBlue}),
helpers.MakeStyled(strconv.FormatBool(di.Config.Tools.IsUseGolangCILint), &helpers.StringStyle{Color: variables.ColorBlue}),
)

// Show created project info.
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.0

require (
github.com/charmbracelet/huh v0.3.0
github.com/charmbracelet/huh/spinner v0.0.0-20240206155212-af520c855346
github.com/charmbracelet/huh/spinner v0.0.0-20240209193029-45947515c4cf
github.com/charmbracelet/lipgloss v0.9.1
github.com/google/wire v0.6.0
github.com/stretchr/testify v1.8.4
Expand All @@ -27,10 +27,10 @@ require (
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.6 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
github.com/charmbracelet/huh v0.3.0 h1:CxPplWkgW2yUTDDG0Z4S5HH8SJOosWHd4LxCvi0XsKE=
github.com/charmbracelet/huh v0.3.0/go.mod h1:fujUdKX8tC45CCSaRQdw789O6uaCRwx8l2NDyKfC4jA=
github.com/charmbracelet/huh/spinner v0.0.0-20240206155212-af520c855346 h1:oC0PFd9y0qsdT6AegIeklj5Q16JKYurj7Nn/AQXzc+Q=
github.com/charmbracelet/huh/spinner v0.0.0-20240206155212-af520c855346/go.mod h1:2l0nupcBRhdSZQqIiaV2hKwctrYbBbOr9Dn6Smox3f4=
github.com/charmbracelet/huh/spinner v0.0.0-20240209193029-45947515c4cf h1:hzfl5rHblaVR/8zfAoCBuqsTcEp/Zvy1IVZBIebZelM=
github.com/charmbracelet/huh/spinner v0.0.0-20240209193029-45947515c4cf/go.mod h1:2l0nupcBRhdSZQqIiaV2hKwctrYbBbOr9Dn6Smox3f4=
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro=
Expand Down Expand Up @@ -43,8 +43,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg=
github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down Expand Up @@ -79,15 +79,17 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
Expand Down
10 changes: 10 additions & 0 deletions internal/actions/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ func createBackendFiles(di *injectors.Injector) error {
})
}

// Check if Golang CI Lint tool is used.
if di.Config.Tools.IsUseGolangCILint {
// Add golangci-lint template to the list.
templates = append(templates, helpers.EmbedTemplate{
EmbedFile: "templates/misc/golangci.yml.gotmpl",
OutputFile: ".golangci.yml",
Data: di.Config,
})
}

return helpers.GenerateFilesByTemplateFromEmbedFS(di.Attachments.Templates, templates)
}

Expand Down
8 changes: 7 additions & 1 deletion internal/attachments/templates/misc/Makefile.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ build: clean test

run: build
@echo "\n> Running project on http://localhost:{{ .Backend.Port }}...\n"
${TEMP_DIR}/${BINARY_NAME}
${TEMP_DIR}/${BINARY_NAME}

{{ if .Tools.IsUseGolangCILint }}
lint:
@echo "\n> Run linter...\n"
go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run
{{ end }}
130 changes: 130 additions & 0 deletions internal/attachments/templates/misc/golangci.yml.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Auto-generated .golangci.yml file.
# See https://gowebly.org for more information.

# Linters settings.
linters-settings:
tagalign:
order:
- json
- db
- validate
strict: true

funlen:
lines: 120
ignore-comments: true

goconst:
min-len: 3
min-occurrences: 3

gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style

gocyclo:
min-complexity: 15

gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'

gomnd:
checks:
- argument
- case
- condition
- return
ignored-functions:
- byte

gosec:
exclude-generated: true
excludes:
- G101

govet:
check-shadowing: true

errorlint:
asserts: false

lll:
line-length: 300

misspell:
locale: US

nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

revive:
rules:
- name: unexported-return
disabled: true
- name: unused-parameter

# Linters to enable.
linters:
disable-all: true

enable:
- bodyclose
- dogsled
- dupl
- errcheck
- errorlint
- exportloopref
- funlen
- gocheckcompilerdirectives
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- nilerr
- nilnil
- revive
- staticcheck
- stylecheck
- typecheck
- tagalign
- unconvert
- unparam
- unused
- whitespace

# Issues configuration.
issues:
exclude-rules:
- path: _test\.go
linters:
- gomnd

# Run configuration.
run:
timeout: 5m
tests: false
{{ if .Tools.IsUseGolangCILint }}
skip-files:
- '.*_templ\\.go$'
{{ end }}
9 changes: 5 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Frontend struct {

// Tools represents struct for a tools part of the project config.
type Tools struct {
IsUseAir, IsUseBun, IsUseTempl bool
IsUseAir, IsUseBun, IsUseTempl, IsUseGolangCILint bool
}

// New creates a new config.
Expand All @@ -36,9 +36,10 @@ func New() *Config {
CSSFramework: "default",
},
Tools: &Tools{
IsUseAir: true,
IsUseBun: true,
IsUseTempl: true,
IsUseAir: true,
IsUseBun: true,
IsUseTempl: true,
IsUseGolangCILint: true,
},
}
}
10 changes: 10 additions & 0 deletions internal/fields/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ func IsUseBunConfirm(di *injectors.Injector) *huh.Confirm {
Negative("No").
Value(&di.Config.Tools.IsUseBun)
}

// IsUseGolangCILintConfirm runs the confirm if Golang CI Lint is used.
func IsUseGolangCILintConfirm(di *injectors.Injector) *huh.Confirm {
return huh.NewConfirm().
Title(messages.FormGolangCILintUsageTitle).
Description(messages.FormGolangCILintUsageDescription).
Affirmative("Yes").
Negative("No").
Value(&di.Config.Tools.IsUseGolangCILint)
}
19 changes: 10 additions & 9 deletions internal/forms/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ func welcomeForm() error {
// projectSettingsForm runs the project settings form.
func projectSettingsForm(di *injectors.Injector) error {
return huh.NewForm(
huh.NewGroup(fields.IsUseAirConfirm(di)), // confirm if Air is used
huh.NewGroup(fields.IsUseBunConfirm(di)), // confirm if Bun is used
huh.NewGroup(fields.IsUseTempleConfirm(di)), // confirm if Templ is used
huh.NewGroup(fields.GoFrameworkSelect(di)), // select Go framework
huh.NewGroup(fields.ReactivityLibrarySelect(di)), // select reactivity library
huh.NewGroup(fields.CSSFrameworkSelect(di)), // select CSS framework
huh.NewGroup(fields.GoModuleNameInput(di)), // input Go module name in go.mod
huh.NewGroup(fields.PackageNameInput(di)), // input package name in package.json
huh.NewGroup(fields.PortInput(di)), // input port number
huh.NewGroup(fields.IsUseAirConfirm(di)), // confirm if Air is used
huh.NewGroup(fields.IsUseBunConfirm(di)), // confirm if Bun is used
huh.NewGroup(fields.IsUseTempleConfirm(di)), // confirm if Templ is used
huh.NewGroup(fields.IsUseGolangCILintConfirm(di)), // confirm if Golang CI Lint is used
huh.NewGroup(fields.GoFrameworkSelect(di)), // select Go framework
huh.NewGroup(fields.ReactivityLibrarySelect(di)), // select reactivity library
huh.NewGroup(fields.CSSFrameworkSelect(di)), // select CSS framework
huh.NewGroup(fields.GoModuleNameInput(di)), // input Go module name in go.mod
huh.NewGroup(fields.PackageNameInput(di)), // input package name in package.json
huh.NewGroup(fields.PortInput(di)), // input port number
).Run()
}
2 changes: 1 addition & 1 deletion internal/messages/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
// CommandCreateSummaryHeadingTools represents the heading of the tools summary.
CommandCreateSummaryHeadingTools string = "Tools ↘"
// CommandCreateSummaryDescription represents the description of the project summary.
CommandCreateSummaryDescription string = "%s\n\nGo web framework/router: %s\nServer port: %s\n\n%s\n\nReactivity library: %s\nCSS framework: %s\n\n%s\n\nIs use Air tool to live-reloading? %s\nIs use Bun as a frontend runtime? %s\nIs use Templ to generate HTML? %s"
CommandCreateSummaryDescription string = "%s\n\nGo web framework/router: %s\nServer port: %s\n\n%s\n\nReactivity library: %s\nCSS framework: %s\n\n%s\n\nIs use Air tool to live-reloading? %s\nIs use Bun as a frontend runtime? %s\nIs use Templ to generate HTML? %s\nIs use golangci-lint to lint your Go code? %s"

// CommandDoctorSummaryTitle represents the title of the system summary.
CommandDoctorSummaryTitle string = "✓ Your system information has been collected successfully!\n"
Expand Down
5 changes: 5 additions & 0 deletions internal/messages/forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ const (
FormTemplUsageTitle string = "Use the Templ package to build HTML templates with Go?\n"
// FormTempleUsageDescription represents the description for the Templ package switch.
FormTemplUsageDescription string = "This package will be used to generate HTML templates\nby Go for your application.\n\nFor more info → https://github.com/a-h/templ"

// FormGolangCILintUsageTitle represents the title for the Golang CI Lint switch.
FormGolangCILintUsageTitle string = "Use the Golang CI Lint to lint your Go code?\n"
// FormGolangCILintUsageDescription represents the description for the Golang CI Lint switch.
FormGolangCILintUsageDescription string = "This tool will be used to lint your Go code.\n\nFor more info → https://github.com/golangci/golangci-lint"
)
2 changes: 1 addition & 1 deletion internal/variables/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package variables

// GoweblyVersion represents the current Gowebly CLI version.
var GoweblyVersion string = "v2.2.0"
var GoweblyVersion string = "v2.3.0"

0 comments on commit a92f3c4

Please sign in to comment.