Skip to content

Commit e020749

Browse files
authored
Add golangci-lint linter make target (#752)
Add line, and lint-and-fix make targets
1 parent 56a68a4 commit e020749

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

.golangci.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# https://golangci-lint.run/usage/configuration/#config-file
2+
3+
run:
4+
allow-parallel-runners: true
5+
timeout: 30s
6+
7+
linters:
8+
enable:
9+
- gocritic
10+
- gocyclo
11+
- gofmt
12+
- gosec

CONTRIBUTING.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Thank you for your interest in Troubleshoot, we welcome your participation. Plea
44

55
## Issues
66

7-
- [Request a New Feature](https://github.com/replicatedhq/troubleshoot/issues/new?assignees=&labels=feature&template=feature_enhancement.md) Create an issue to add functionality that addresses a problem or adds an enhancement.
7+
- [Request a New Feature](https://github.com/replicatedhq/troubleshoot/issues/new?assignees=&labels=feature&template=feature_enhancement.md) Create an issue to add functionality that addresses a problem or adds an enhancement.
88
- [Report a Bug](https://github.com/replicatedhq/troubleshoot/issues/new?assignees=&labels=bug&template=bug_report.md) Report a problem or unexpected behaviour with Troubleshoot.
99

1010
## Design Principles
@@ -24,6 +24,8 @@ To get started we recommend:
2424
> Note: recent versions of Go support easy cross-compilation. For example, to cross-compile a Linux binary from MacOS:
2525
> `GOOS=linux GOARCH=amd64 make support-bundle preflight`
2626
27+
6. Install [golangci-lint] linter and run `make lint` to execute code linters.
28+
2729
### Testing
2830

2931
To run the tests locally run the following:
@@ -48,23 +50,22 @@ This is a rough outline of how to prepare a contribution:
4850
- Create a topic branch from where you want to base your work (branched from `main` is a safe choice).
4951
- Make commits of logical units.
5052
- When your changes are ready to merge, squash your history to 1 commit.
51-
- For example, if you want to squash your last 3 commits and write a new commit message:
53+
- For example, if you want to squash your last 3 commits and write a new commit message:
5254
```
53-
git reset --soft HEAD~3 &&
55+
git reset --soft HEAD~3 &&
5456
git commit
55-
```
57+
```
5658
5759
- If you want to keep the previous commit messages and concatenate them all into a new commit, you can do something like this instead:
5860
```
59-
git reset --soft HEAD~3 &&
61+
git reset --soft HEAD~3 &&
6062
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
6163
```
6264
- Push your changes to a topic branch in your fork of the repository.
6365
- Submit a pull request to the original repository. It will be reviewed in a timely manner.
6466
6567
### Pull Requests
6668
67-
A pull request should address a single issue, feature or bug. For example, lets say you've written code that fixes two issues. That's great! However, you should submit two small pull requests, one for each issue as opposed to combining them into a single larger pull request. In general the size of the pull request should be kept small in order to make it easy for a reviewer to understand, and to minimize risks from integrating many changes at the same time. For example, if you are working on a large feature you should break it into several smaller PRs by implementing the feature as changes to several packages and submitting a separate pull request for each one. Squash commit history when preparing your PR so it merges as 1 commit.
69+
A pull request should address a single issue, feature or bug. For example, lets say you've written code that fixes two issues. That's great! However, you should submit two small pull requests, one for each issue as opposed to combining them into a single larger pull request. In general the size of the pull request should be kept small in order to make it easy for a reviewer to understand, and to minimize risks from integrating many changes at the same time. For example, if you are working on a large feature you should break it into several smaller PRs by implementing the feature as changes to several packages and submitting a separate pull request for each one. Squash commit history when preparing your PR so it merges as 1 commit.
6870
6971
Code submitted in pull requests must be properly documented, formatted and tested in order to be approved and merged. The following guidelines describe the things a reviewer will look for when they evaluate your pull request. Here's a tip. If your reviewer doesn't understand what the code is doing, they won't approve the pull request. Strive to make code clear and well documented. If possible, request a reviewer that has some context on the PR.
70-

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ preflight:
6464
.PHONY: analyze
6565
analyze:
6666
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/analyze github.com/replicatedhq/troubleshoot/cmd/analyze
67-
67+
6868
.PHONY: collect
6969
collect:
70-
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/collect github.com/replicatedhq/troubleshoot/cmd/collect
70+
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/collect github.com/replicatedhq/troubleshoot/cmd/collect
7171

7272
.PHONY: fmt
7373
fmt:
@@ -159,7 +159,7 @@ generate-sbom: install-spdx-sbom-generator
159159
$(SPDX_GENERATOR) -o ./sbom/spdx
160160

161161
sbom/assets/troubleshoot-sbom.tgz: generate-sbom
162-
tar -czf sbom/assets/troubleshoot-sbom.tgz sbom/spdx/*.spdx
162+
tar -czf sbom/assets/troubleshoot-sbom.tgz sbom/spdx/*.spdx
163163

164164
sbom: sbom/assets/troubleshoot-sbom.tgz
165165
cosign sign-blob -key cosign.key sbom/assets/troubleshoot-sbom.tgz > sbom/assets/troubleshoot-sbom.tgz.sig
@@ -186,4 +186,12 @@ scan:
186186
--exit-code=1 \
187187
--severity="HIGH,CRITICAL" \
188188
--ignore-unfixed \
189-
./
189+
./
190+
191+
.PHONY: lint
192+
lint:
193+
golangci-lint run -c .golangci.yaml
194+
195+
.PHONY: lint-and-fix
196+
lint-and-fix:
197+
golangci-lint run --fix -c .golangci.yaml

0 commit comments

Comments
 (0)