Skip to content

Commit

Permalink
initial project setup
Browse files Browse the repository at this point in the history
  • Loading branch information
wimspaargaren committed Apr 9, 2024
0 parents commit 1461d87
Show file tree
Hide file tree
Showing 16 changed files with 706 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
reports
221 changes: 221 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
run:
concurrency: 3
timeout: 15m
issues-exit-code: 1
tests: true

skip-dirs:
- data

# list of build tags, all linters use it. Default is empty list

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: code-climate

# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true

uniq-by-line: false

# all available settings of specific linters
linters-settings:
depguard:
rules:
main:
deny:
- pkg: "github.com/tj/assert"
desc: not allowed, did you mean testify assert?
gci:
local-prefixes: github.com/wimspaargaren/prolayout
errcheck:
check-type-assertions: false
check-foonk: true

revive:
ignore-generated-header: true
enable-all-rules: true
rules:
- name: add-constant
disabled: true
- name: var-naming
severity: warning
disabled: false
arguments:
- ["ID"] # AllowList
- [] # DenyList
- name: argument-limit
severity: warning
disabled: true
- name: banned-characters
disabled: true
- name: max-public-structs
disabled: true
- name: file-header
disabled: true
- name: cognitive-complexity
disabled: false
arguments: [15]
- name: unused-receiver
disabled: true
- name: function-length
disabled: false
arguments: [30, 0]
- name: line-length-limit
disabled: true
- name: cyclomatic
disabled: false
arguments: [7]
- name: function-result-limit
severity: warning
disabled: false
arguments: [3]
- name: import-alias-naming
severity: warning
disabled: false
arguments:
- "^[a-z][a-z0-9A-Z]{0,}$"
govet:
check-shadowing: false

golint:
min-confidence: 0.8

gofmt:
simplify: true
gocyclo:
min-complexity: 18
maligned:
suggest-new: true
dupl:
threshold: 175
goconst:
min-len: 3
min-occurrences: 3
funlen:
lines: 80
statements: 50
godox:
keywords:
- HACK
- OPTIMIZE
- TODO
- BUG
misspell:
locale: UK
ignore-words:
- color
- center
- centers
lll:
line-length: 200
tab-width: 2
unused:
check-exported: false

unparam:
check-exported: false

nakedret:
max-func-lines: 0
prealloc:
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default
gocritic:
disabled-checks:
- regexpMust

enabled-tags:
- performance

settings: # settings passed to gocritic
captLocal: # must be valid enabled check name
paramsOnly: true
rangeValCopy:
sizeThreshold: 32

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- dupl
- errcheck
- errorlint
- exhaustive
- exportloopref
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godox
- gofmt
- gofumpt
- goheader
- revive
- gomodguard
- goprintffuncname
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- nestif
- noctx
- nolintlint
- rowserrcheck
- sqlclosecheck
- staticcheck
- tparallel
- typecheck
- unconvert
- unparam
- whitespace
- dogsled
- godot
- goerr113
- goimports
- lll
- prealloc
- testpackage
- depguard

fast: false

severity:
default-severity: error
rules:
- linters:
- gomodguard
severity: warning

issues:
exclude-rules:
- path: _test\.go
linters:
- funlen

- linters:
- staticcheck
text: "SA9003:"

- linters:
- lll
text: "^//go:generate "

exclude-use-default: false

max-issues-per-linter: 0

max-same-issues: 0

new: false
6 changes: 6 additions & 0 deletions .prolayout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module: "github.com/wimspaargaren/prolayout"
root:
- name: "bar"



21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Wim Spaargaren

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.PHONY: lint test format

golangciLintVersion = "v1.55.2"
gofumptVersion = "v0.5.0"
gciVersion = "v0.11.0"
govulncheckVersion = "v1.0.1"

# Lint Go Code
$(GOBIN)/golangci-lint:
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@${golangciLintVersion}

lint: | $(GOBIN)/golangci-lint
@echo Linting...
@golangci-lint -v --concurrency=3 --config=.golangci.yml --issues-exit-code=1 run \
--out-format=colored-line-number

# Format Go Code
$(GOBIN)/gofumpt:
@go install mvdan.cc/gofumpt@${gofumptVersion}
@go mod tidy

gofumpt: | $(GOBIN)/gofumpt
@gofumpt -w $(shell ls -d $(PWD)/*/)

# Format imports
$(GOBIN)/gci:
@go install github.com/daixiang0/gci@${gciVersion}
@go mod tidy

gci: | $(GOBIN)/gci
@gci write --section Standard --section Default --section "Prefix(github.com/wimspaargaren/prolayout)" $(shell ls -d $(PWD)/*)

# Run unit tests and generate coverage report
test:
@mkdir -p reports
@go test -coverprofile=reports/codecoverage_all.cov ./... -cover -race -p=4
@go tool cover -func=reports/codecoverage_all.cov > reports/functioncoverage.out
@go tool cover -html=reports/codecoverage_all.cov -o reports/coverage.html
@echo "View report at $(PWD)/reports/coverage.html"
@tail -n 1 reports/functioncoverage.out

# Opens coverage report in browser
coverage-report:
@open ./reports/coverage.html

# Formats code
format:
@make gofumpt
@make gci
@go mod tidy

# Install and run govulncheck tool
$(GOBIN)/govulncheck:
@go install golang.org/x/vuln/cmd/govulncheck@${govulncheckVersion}

govulncheck: | $(GOBIN)/govulncheck
@govulncheck -test ./...
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ProLayout

Pro(ject) layout is a static analysis tool that allow you to lint the project structure of your go project.

# Why

Since Go does not enforce any real project structure, we wanted to have a static analysis tool, to help us to ensure projects are structured in a similar fashion.

# Example configuration file

```YAML
module: "github.com/wimspaargaren/prolayout"
root:
- name: "cmd"
dirs:
- name: ".*"
files:
- "main.go"
- name: "internal"
- name: "pkg"
- name: "tests"
files:
- name: ".*_test.go"
```
16 changes: 16 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module github.com/wimspaargaren/prolayout

go 1.22.0

require (
github.com/stretchr/testify v1.9.0
golang.org/x/tools v0.20.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
)
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY=
golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 1461d87

Please sign in to comment.