Skip to content

Commit 71cb97b

Browse files
authored
Add basic code style helper guide and default linters (#136)
* Add basic code style helper guide and default linters - fixes #98 Signed-off-by: Spolti <[email protected]> * review additions Signed-off-by: Spolti <[email protected]> * suggestion additions Signed-off-by: Spolti <[email protected]> Signed-off-by: Spolti <[email protected]>
1 parent 2ce428e commit 71cb97b

File tree

9 files changed

+161
-7
lines changed

9 files changed

+161
-7
lines changed

CONTRIBUTORS_GUIDE.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Contributors Guide
2+
3+
This guide aims to guide newcomers to getting started with the project standards.
4+
5+
6+
## Code Style
7+
8+
For this project we use basically the default configuration for most used IDEs.
9+
For the configurations below, make sure to properly configure your IDE:
10+
11+
- **imports**: goimports
12+
13+
This should be enough to get you started.
14+
15+
If you are unsure that your IDE is not correctly configured, you can run the lint checks:
16+
17+
```bash
18+
make lint
19+
```
20+
21+
If something goes wrong, the error will be printed, e.g.:
22+
```bash
23+
$ make lint
24+
make addheaders
25+
make fmt
26+
./hack/go-lint.sh
27+
util/floatstr/floatstr_test.go:19: File is not `goimports`-ed (goimports)
28+
"k8s.io/apimachinery/pkg/util/yaml"
29+
make: *** [lint] Error 1
30+
```
31+
32+
Lint issues can be fixed with the `--fix` flag, this command can be used:
33+
```bash
34+
make lint params=--fix
35+
```
36+
37+
38+
### EditorConfig
39+
For IntelliJ you can find an example `editorconfig` file [here](contrib/intellij.editorconfig). To use it please visit
40+
the Jetbrains [documentation](https://www.jetbrains.com/help/idea/editorconfig.html).
41+
42+
43+
## Known Issues
44+
45+
On MacOSX/darwin you might get this issue:
46+
```
47+
goimports: can't extract issues from gofmt diff output
48+
```
49+
To solve install the `diffutils` package:
50+
51+
```bash
52+
brew install diffutils
53+
```

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ lint:
1010
@command -v golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin"
1111
make addheaders
1212
make fmt
13-
./hack/go-lint.sh
13+
./hack/go-lint.sh ${params}
1414

1515
.PHONY: test
1616
coverage="false"

README.md

+71-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
# Go SDK for Serverless Workflow
2-
32
Here you will find all the [specification types](https://github.com/serverlessworkflow/specification/blob/main/schema/workflow.json) defined by our Json Schemas, in Go.
43

4+
Table of Contents
5+
=================
6+
7+
- [Status](#status)
8+
- [Releases](#releases)
9+
- [How to Use](#how-to-use)
10+
- [Parsing Serverless Workflow files](#parsing-serverless-workflow-files)
11+
- [Slack Channel](#slack-channel)
12+
- [Contributors Guide](#contributors-guide)
13+
- [Code Style](#code-style)
14+
- [EditorConfig](#editorconfig)
15+
- [Known Issues](#known-issues)
16+
17+
18+
## Status
519
Current status of features implemented in the SDK is listed in the table below:
620

721
| Feature | Status |
@@ -12,8 +26,8 @@ Current status of features implemented in the SDK is listed in the table below:
1226
| Validate workflow definitions (Integrity) | :heavy_check_mark: |
1327
| Generate workflow diagram (SVG) | :no_entry_sign: |
1428

15-
## Status
1629

30+
## Releases
1731
| Latest Releases | Conformance to spec version |
1832
|:--------------------------------------------------------------------------:| :---: |
1933
| [v1.0.0](https://github.com/serverlessworkflow/sdk-go/releases/tag/v1.0.0) | [v0.5](https://github.com/serverlessworkflow/specification/tree/0.5.x) |
@@ -66,3 +80,58 @@ The `Workflow` structure then can be used in your application.
6680
## Slack Channel
6781

6882
Join us at [CNCF Slack](https://communityinviter.com/apps/cloud-native/cncf), channel `#serverless-workflow-sdk` and say hello 🙋.
83+
84+
## Contributors Guide
85+
86+
This guide aims to guide newcomers to getting started with the project standards.
87+
88+
89+
### Code Style
90+
91+
For this project we use basically the default configuration for most used IDEs.
92+
For the configurations below, make sure to properly configure your IDE:
93+
94+
- **imports**: goimports
95+
96+
This should be enough to get you started.
97+
98+
If you are unsure that your IDE is not correctly configured, you can run the lint checks:
99+
100+
```bash
101+
make lint
102+
```
103+
104+
If something goes wrong, the error will be printed, e.g.:
105+
```bash
106+
$ make lint
107+
make addheaders
108+
make fmt
109+
./hack/go-lint.sh
110+
util/floatstr/floatstr_test.go:19: File is not `goimports`-ed (goimports)
111+
"k8s.io/apimachinery/pkg/util/yaml"
112+
make: *** [lint] Error 1
113+
```
114+
115+
Lint issues can be fixed with the `--fix` flag, this command can be used:
116+
```bash
117+
make lint params=--fix
118+
```
119+
120+
121+
### EditorConfig
122+
For IntelliJ you can find an example `editorconfig` file [here](contrib/intellij.editorconfig). To use it please visit
123+
the Jetbrains [documentation](https://www.jetbrains.com/help/idea/editorconfig.html).
124+
125+
126+
### Known Issues
127+
128+
On MacOSX/darwin you might get this issue:
129+
```
130+
goimports: can't extract issues from gofmt diff output
131+
```
132+
To solve install the `diffutils` package:
133+
134+
```bash
135+
brew install diffutils
136+
```
137+

contrib/intellij.editorconfig

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
root = true
2+
3+
[{*.go,*.go2}]
4+
indent_style = tab
5+
ij_continuation_indent_size = 4
6+
ij_go_GROUP_CURRENT_PROJECT_IMPORTS = true
7+
ij_go_add_leading_space_to_comments = true
8+
ij_go_add_parentheses_for_single_import = false
9+
ij_go_call_parameters_new_line_after_left_paren = true
10+
ij_go_call_parameters_right_paren_on_new_line = true
11+
ij_go_call_parameters_wrap = off
12+
ij_go_fill_paragraph_width = 80
13+
ij_go_group_stdlib_imports = true
14+
ij_go_import_sorting = goimports
15+
ij_go_keep_indents_on_empty_lines = false
16+
ij_go_local_group_mode = project
17+
ij_go_move_all_imports_in_one_declaration = true
18+
ij_go_move_all_stdlib_imports_in_one_group = false
19+
ij_go_remove_redundant_import_aliases = true
20+
ij_go_run_go_fmt_on_reformat = true
21+
ij_go_use_back_quotes_for_imports = false
22+
ij_go_wrap_comp_lit = off
23+
ij_go_wrap_comp_lit_newline_after_lbrace = true
24+
ij_go_wrap_comp_lit_newline_before_rbrace = true
25+
ij_go_wrap_func_params = off
26+
ij_go_wrap_func_params_newline_after_lparen = true
27+
ij_go_wrap_func_params_newline_before_rparen = true
28+
ij_go_wrap_func_result = off
29+
ij_go_wrap_func_result_newline_after_lparen = true
30+
ij_go_wrap_func_result_newline_before_rparen = true

hack/go-lint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
golangci-lint run ./... --timeout 2m0s
16+
golangci-lint run -E goimports -E errorlint -E gosec "${1}" ./... --timeout 2m0s

maintainer_guidelines.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Here are a few tips for repository maintainers.
1616

1717
## Branch Management
1818

19-
The `main` branch is is the bleeding edge. New major versions of the module
19+
The `main` branch is the bleeding edge. New major versions of the module
2020
are cut from this branch and tagged. If you intend to submit a pull request
2121
you should use `main HEAD` as your starting point.
2222

model/object.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (obj *Object) UnmarshalJSON(data []byte) error {
116116
default:
117117
// json parses all not typed numbers as float64, let's enforce to int32
118118
if valInt, parseErr := strconv.Atoi(fmt.Sprint(val)); parseErr != nil {
119-
return fmt.Errorf("falied to parse %d to int32: %s", valInt, parseErr.Error())
119+
return fmt.Errorf("falied to parse %d to int32: %w", valInt, parseErr)
120120
} else {
121121
var intVal Integer
122122
if err := json.Unmarshal(data, &intVal); err != nil {

model/util.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"net/http"
2222
"os"
2323
"path/filepath"
24+
2425
"sigs.k8s.io/yaml"
2526

2627
"strings"

util/floatstr/floatstr_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ package floatstr
1616

1717
import (
1818
"encoding/json"
19-
"k8s.io/apimachinery/pkg/util/yaml"
2019
"reflect"
2120
"testing"
21+
22+
"k8s.io/apimachinery/pkg/util/yaml"
2223
)
2324

2425
func TestFromFloat(t *testing.T) {

0 commit comments

Comments
 (0)