Skip to content

Commit d0dcc8c

Browse files
Include golangci-lint fixes when formatting code (#4461)
* Include golangci-lint fixes when formatting code * Add docs * Update warning for verify-no-changes
1 parent bc42335 commit d0dcc8c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Taskfile.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ tasks:
103103
desc: Ensure all code is formatted
104104
dir: v2
105105
cmds:
106+
- golangci-lint run --fix ./...
106107
- gofumpt -l -w .
107108

108109
build-docs-site:
@@ -1288,7 +1289,7 @@ tasks:
12881289
verify-no-changes:
12891290
desc: Checks that there are no uncommitted modifications to files
12901291
cmds:
1291-
- cmd: 'if [ -n "{{.CHANGED}}" ]; then echo "Error: files were modified during the build (did you forget to commit generated files?):"; echo "{{.CHANGED}}"; git diff; exit 1; fi'
1292+
- cmd: 'if [ -n "{{.CHANGED}}" ]; then echo "Error: files were modified during the build (ensure you have commited generated files, and run ''task format-code'' to tidy):"; echo "{{.CHANGED}}"; git diff; exit 1; fi'
12921293
silent: true
12931294
vars:
12941295
CHANGED:

docs/hugo/content/contributing/hints-and-tips/_index.md

+25
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,28 @@ One of the key features of ASO is that it takes care of sequencing - it works ou
3939
It's important that we exercise this in our tests. We've found in the past some resources where additional work was required to make this run smoothly - this is why we have extension points defined in the [`genruntime/extensions package`](https://pkg.go.dev/github.com/Azure/azure-service-operator/[email protected]/pkg/genruntime/extensions).
4040

4141
Instead of calling `tc.CreateResourceAndWait()` for each resource in turn, declare all the resources required for the test and then make a single call to `tc.CreateResourcesAndWait()` (note the plural in the name) to create them all at once.
42+
43+
## Code formatting and linting
44+
45+
We strongly believe that linting (aka static code analysis) can be very useful for identifying potential issues in the code. We use [golangci-lint](https://golangci-lint.run/) to run a suite of linters on the codebase as a part of our CI pipeline for every PR. We also use [gofumpt](https://github.com/mvdan/gofumpt), a stricter version of `gofmt`, to format the code.
46+
47+
To ensure your code passes CI, we suggest running the following two commands before submitting your pull request.
48+
49+
First, ensure your code is formatted according to our standards:
50+
51+
```bash
52+
task format-code
53+
```
54+
55+
If any files are modified, commit them.
56+
57+
58+
Then, run the linters:
59+
60+
```bash
61+
task controller:lint
62+
```
63+
64+
The above target is appropriate if you're contributing a new resource or controller feature. If you're contributing to our commandline tool, use `task asoctl:lint`; if you're working on our code generator, use `task generator:lint`.
65+
66+
If any issues are found, fix them before submitting your PR.

0 commit comments

Comments
 (0)