Skip to content

Add basic code style helper guide and default linters #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions CONTRIBUTORS_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Contributors Guide

This guide aims to guide newcomers to getting started with the project standards.


## Code Style

For this project we use basically the default configuration for most used IDEs.
For the configurations below, make sure to properly configure your IDE:

- **imports**: goimports

This should be enough to get you started.

If you are unsure that your IDE is not correctly configured, you can run the lint checks:

```bash
make lint
```

If something goes wrong, the error will be printed, e.g.:
```bash
$ make lint
make addheaders
make fmt
./hack/go-lint.sh
util/floatstr/floatstr_test.go:19: File is not `goimports`-ed (goimports)
"k8s.io/apimachinery/pkg/util/yaml"
make: *** [lint] Error 1
```

Lint issues can be fixed with the `--fix` flag, this command can be used:
```bash
make lint params=--fix
```


### EditorConfig
For IntelliJ you can find an example `editorconfig` file [here](contrib/intellij.editorconfig). To use it please visit
the Jetbrains [documentation](https://www.jetbrains.com/help/idea/editorconfig.html).


## Known Issues

On MacOSX/darwin you might get this issue:
```
goimports: can't extract issues from gofmt diff output
```
To solve install the `diffutils` package:

```bash
brew install diffutils
```
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ lint:
@command -v golangci-lint > /dev/null || curl -sSfL https://github.com/raw/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin"
make addheaders
make fmt
./hack/go-lint.sh
./hack/go-lint.sh ${params}

.PHONY: test
coverage="false"
Expand Down
73 changes: 71 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Go SDK for Serverless Workflow

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.

Table of Contents
=================

- [Status](#status)
- [Releases](#releases)
- [How to Use](#how-to-use)
- [Parsing Serverless Workflow files](#parsing-serverless-workflow-files)
- [Slack Channel](#slack-channel)
- [Contributors Guide](#contributors-guide)
- [Code Style](#code-style)
- [EditorConfig](#editorconfig)
- [Known Issues](#known-issues)


## Status
Current status of features implemented in the SDK is listed in the table below:

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

## Status

## Releases
| Latest Releases | Conformance to spec version |
|:--------------------------------------------------------------------------:| :---: |
| [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) |
Expand Down Expand Up @@ -66,3 +80,58 @@ The `Workflow` structure then can be used in your application.
## Slack Channel

Join us at [CNCF Slack](https://communityinviter.com/apps/cloud-native/cncf), channel `#serverless-workflow-sdk` and say hello 🙋.

## Contributors Guide

This guide aims to guide newcomers to getting started with the project standards.


### Code Style

For this project we use basically the default configuration for most used IDEs.
For the configurations below, make sure to properly configure your IDE:

- **imports**: goimports

This should be enough to get you started.

If you are unsure that your IDE is not correctly configured, you can run the lint checks:

```bash
make lint
```

If something goes wrong, the error will be printed, e.g.:
```bash
$ make lint
make addheaders
make fmt
./hack/go-lint.sh
util/floatstr/floatstr_test.go:19: File is not `goimports`-ed (goimports)
"k8s.io/apimachinery/pkg/util/yaml"
make: *** [lint] Error 1
```

Lint issues can be fixed with the `--fix` flag, this command can be used:
```bash
make lint params=--fix
```


### EditorConfig
For IntelliJ you can find an example `editorconfig` file [here](contrib/intellij.editorconfig). To use it please visit
the Jetbrains [documentation](https://www.jetbrains.com/help/idea/editorconfig.html).


### Known Issues

On MacOSX/darwin you might get this issue:
```
goimports: can't extract issues from gofmt diff output
```
To solve install the `diffutils` package:

```bash
brew install diffutils
```

30 changes: 30 additions & 0 deletions contrib/intellij.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
root = true

[{*.go,*.go2}]
indent_style = tab
ij_continuation_indent_size = 4
ij_go_GROUP_CURRENT_PROJECT_IMPORTS = true
ij_go_add_leading_space_to_comments = true
ij_go_add_parentheses_for_single_import = false
ij_go_call_parameters_new_line_after_left_paren = true
ij_go_call_parameters_right_paren_on_new_line = true
ij_go_call_parameters_wrap = off
ij_go_fill_paragraph_width = 80
ij_go_group_stdlib_imports = true
ij_go_import_sorting = goimports
ij_go_keep_indents_on_empty_lines = false
ij_go_local_group_mode = project
ij_go_move_all_imports_in_one_declaration = true
ij_go_move_all_stdlib_imports_in_one_group = false
ij_go_remove_redundant_import_aliases = true
ij_go_run_go_fmt_on_reformat = true
ij_go_use_back_quotes_for_imports = false
ij_go_wrap_comp_lit = off
ij_go_wrap_comp_lit_newline_after_lbrace = true
ij_go_wrap_comp_lit_newline_before_rbrace = true
ij_go_wrap_func_params = off
ij_go_wrap_func_params_newline_after_lparen = true
ij_go_wrap_func_params_newline_before_rparen = true
ij_go_wrap_func_result = off
ij_go_wrap_func_result_newline_after_lparen = true
ij_go_wrap_func_result_newline_before_rparen = true
2 changes: 1 addition & 1 deletion hack/go-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

golangci-lint run ./... --timeout 2m0s
golangci-lint run -E goimports -E errorlint -E gosec "${1}" ./... --timeout 2m0s
2 changes: 1 addition & 1 deletion maintainer_guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Here are a few tips for repository maintainers.

## Branch Management

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

Expand Down
2 changes: 1 addition & 1 deletion model/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (obj *Object) UnmarshalJSON(data []byte) error {
default:
// json parses all not typed numbers as float64, let's enforce to int32
if valInt, parseErr := strconv.Atoi(fmt.Sprint(val)); parseErr != nil {
return fmt.Errorf("falied to parse %d to int32: %s", valInt, parseErr.Error())
return fmt.Errorf("falied to parse %d to int32: %w", valInt, parseErr)
} else {
var intVal Integer
if err := json.Unmarshal(data, &intVal); err != nil {
Expand Down
1 change: 1 addition & 0 deletions model/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"os"
"path/filepath"

"sigs.k8s.io/yaml"

"strings"
Expand Down
3 changes: 2 additions & 1 deletion util/floatstr/floatstr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package floatstr

import (
"encoding/json"
"k8s.io/apimachinery/pkg/util/yaml"
"reflect"
"testing"

"k8s.io/apimachinery/pkg/util/yaml"
)

func TestFromFloat(t *testing.T) {
Expand Down