summaryrefslogtreecommitdiff
path: root/CONTRIBUTING
blob: 5283d76c355e027ae6f481b74a09dd73c2e1941d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
############
Contributing
############

.. contents:: Table of Contents

We use `Github`_ for managing code and issues and `GerritHub`_ for reviews.

.. _GerritHub: https://review.gerrithub.io/admin/projects/SamsungSLAV/weles
.. _Github: https://github.com/SamsungSLAV/weles


*****************
How to contribute
*****************

Reporting bugs
==============

Create issue on `GitHub`_.

Suggesting enhancements
=======================

Create issue on `GitHub`_.

Code contributions
==================

Check issues on `Github`_.

***********
Styleguides
***********

Git
===

Commit message
--------------

Check following articles regarding commit messages:

- `Tim Pope's blog post`_
- `Chris Beams blog post`_

Each commit message must be signed-off. This means that the contributor agrees
to `Developer Certificate of Origin`_.

If committer will not be responsive but his patch will be chosen to be merged,
some fixes might be added by someone else. Signoff will show original author
even when someone else will commit it.

.. _`Tim Pope's blog post`: https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
.. _`Chris Beams blog post`:  https://chris.beams.io/posts/git-commit
.. _`Developer Certificate of Origin`: https://developercertificate.org/


Commit size
-----------

Each feature should be on its designated branch. This allows to divide features
into small commits which are easier to review.

Branching schema
----------------

Main branches
^^^^^^^^^^^^^

Currently there is one main branch: ``master``.

Feature branches
^^^^^^^^^^^^^^^^

Feature branches should be named uniquely and identify the feature developed.

Merge strategy
^^^^^^^^^^^^^^

Feature branches are always merged without fast-forwarding to keep branch
information.

Release strategy
----------------

Releases are flagged on master branch using git tag. We use `Semantic
Versioning 2.0`_ .

.. _`Semantic Versioning 2.0`: https://semver.org/

Coding style
============

Automatic formatters
--------------------

We use both gofmt_ and goimports_. It is recommended to set your editor to run those two on save.
It is desired to place internal SLAV imports at the bottom.

.. _goimports: https://godoc.org/golang.org/x/tools/cmd/goimports

Line breaks
-----------

Breaking lines on 100 chars
^^^^^^^^^^^^^^^^^^^^^^^^^^^

The goal of this rule is to have code easy to read on vertical monitor or two files on a horizontal
monitor.

We consider tab to be 4 chars.

Breaking function signature when parameter list goes over 100 chars
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block::

  // Having a function signature like this, where the paginator weles.ArtifactPagination parameter
  // exceeds the 100 chars:                                                                   here: v
  func (aDB *ArtifactDB) Filter(filter weles.ArtifactFilter, sorter weles.ArtifactSorter, paginator weles.ArtifactPagination) ([]weles.ArtifactInfo, weles.ListInfo, error) {
      results := []weles.ArtifactInfo{}
      ...
  }

  // You should change it to:
  func (aDB *ArtifactDB) Filter(f weles.ArtifactFilter, s weles.ArtifactSorter,
       p weles.ArtifactPagination) ([]weles.ArtifactInfo, weles.ListInfo, error) {

       results := []weles.ArtifactInfo{}
       ...
  }
  // Please remember to add new line between functon signature and body to indicate end of function
  // signature. This is because gofmt indents them to the same level.

Breaking function signature when return goes over 100 chars
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block::

  // Having a function signature like this, where *Downloader return parameter exceeds
  // 100 chars:                                                                               here: v
  func newDownloader(notification chan weles.ArtifactStatusChange, workers, queueSize int) *Downloader {
      return newDownloader(notification, workerCount, queueCap)
  }
  // You should change it to
  func NewDownloader(notification chan weles.ArtifactStatusChange, workerCount, queueCap int,
  ) *Downloader {
      return newDownloader(notification, workerCount, queueCap)
  }
  // Please note lack of new line between function signature and body. They have different
  // indentation level thus new line is not necessary.

Breaking a struct literal when it goes over 100 chars
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block::

  // Having a line like below:
  f := weles.JobFilter{CreatedAfter: strfmt.DateTime(magicDate), CreatedBefore: strfmt.DateTime{}}
  // You should change it to:
  f := weles.JobFilter{
      CreatedAfter:  strfmt.DateTime(magicDate),
      CreatedBefore: strfmt.DateTime{},
  } // Note the comma in previous line and the closing brace in new line.

Tests
-----

We use Ginkgo_ which is BDD-style Go testing framework with Gomega_ which is a
matcher library.

.. _Ginkgo: https://onsi.github.io/ginkgo/
.. _Gomega: https://github.com/onsi/gomega

Static Analysis
---------------

We use `gometalinter`_ to check the code. To use locally, please download .v2
version and execute it in Weles repository root (or pass .gometalinter.json
explicitly) Below table contains overview of the checkers used in Weles.
Automatically generated code is not subject to static analysis.

+---------------------------+-------------------------------------------------------------------------------+
| Linter                    | Description                                                                   |
+===========================+===============================================================================+
| deadcode_                 | Find unused code                                                              |
+---------------------------+-------------------------------------------------------------------------------+
| errcheck_                 | Check that error return values are used.                                      |
+---------------------------+-------------------------------------------------------------------------------+
| goconst_                  | Finds repeated strings that could be replaced by a constant.                  |
+---------------------------+-------------------------------------------------------------------------------+
| gocyclo_                  | Computes the cyclomatic complexity of functions.                              |
|                           |                                                                               |
|                           | Max cyclomatic complexity: 15                                                 |
+---------------------------+-------------------------------------------------------------------------------+
| gofmt_                    | Checks if the code is properly formatted and could not be further simplified. |
+---------------------------+-------------------------------------------------------------------------------+
| golint_                   | Google's (mostly stylistic) linter.                                           |
+---------------------------+-------------------------------------------------------------------------------+
| `gosec (previously gas)`_ | Inspects source code for security problems by scanning the Go AST.            |
+---------------------------+-------------------------------------------------------------------------------+
| gosimple_                 | Report simplifications in code.                                               |
+---------------------------+-------------------------------------------------------------------------------+
| ineffassign_              | Detect when assignments to existing variables are not used.                   |
+---------------------------+-------------------------------------------------------------------------------+
| interfacer_               | Suggest narrower interfaces that can be used.                                 |
+---------------------------+-------------------------------------------------------------------------------+
| lll_                      | Report long lines.                                                            |
|                           |                                                                               |
|                           | Max line length: 100. Tab width: 4.                                           |
+---------------------------+-------------------------------------------------------------------------------+
| maligned_                 | Detect structs that would take less memory if their fields were sorted.       |
+---------------------------+-------------------------------------------------------------------------------+
| megacheck_                | Run staticcheck_, gosimple_ and unused_, sharing work.                        |
+---------------------------+-------------------------------------------------------------------------------+
| staticcheck_              | Statically detect bugs, both obvious and subtle ones.                         |
+---------------------------+-------------------------------------------------------------------------------+
| structcheck_              | Find unused struct fields.                                                    |
+---------------------------+-------------------------------------------------------------------------------+
| unconvert_                | Detect redundant type conversions.                                            |
+---------------------------+-------------------------------------------------------------------------------+
| unparam_                  | Find unused function parameters.                                              |
+---------------------------+-------------------------------------------------------------------------------+
| unused_                   | Find `unused variables`_.                                                     |
+---------------------------+-------------------------------------------------------------------------------+
| varcheck_                 | Find unused global variables and constants.                                   |
+---------------------------+-------------------------------------------------------------------------------+
| vet_                      | Reports potential errors that otherwise compile.                              |
+---------------------------+-------------------------------------------------------------------------------+
| vetshadow_                | Reports variables that may have been unintentionally shadowed.                |
+---------------------------+-------------------------------------------------------------------------------+

.. _gometalinter: https://github.com/alecthomas/gometalinter>
.. _deadcode: https://github.com/tsenart/deadcode
.. _errcheck: https://github.com/kisielk/errcheck
.. _goconst: https://github.com/jgautheron/goconst
.. _gocyclo: https://github.com/alecthomas/gocyclo
.. _gofmt: https://golang.org/cmd/gofmt
.. _golint: https://github.com/golang/lint
.. _`gosec (previously gas)`: https://github.com/securego/gosec
.. _gosimple: https://github.com/dominikh/go-tools/tree/master/cmd/gosimple
.. _ineffassign: https://github.com/gordonklaus/ineffassign
.. _interfacer: https://github.com/mvdan/interfacer
.. _lll: https://github.com/walle/lll
.. _maligned: https://github.com/mdempsky/maligned
.. _megacheck: https://github.com/dominikh/go-tools/tree/master/cmd/megacheck
.. _staticcheck: https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
.. _structcheck: https://github.com/opennota/check
.. _unconvert: https://github.com/mdempsky/unconvert
.. _unparam: https://github.com/mvdan/unparam
.. _unused: https://github.com/dominikh/go-tools/tree/master/cmd/unused
.. _`unused variables`: https://github.com/dominikh/go-tools/tree/master/cmd/unused#what-counts-as-usedunused
.. _varcheck: https://github.com/opennota/check
.. _vet: https://golang.org/cmd/vet
.. _vetshadow: https://golang.org/cmd/vet/#hdr-Shadowed_variables

Documentation styleguide
========================

All documentation parts are gathered into Sphinx documentation.

User Documentation
------------------

For Sphinx documentation we follow `Benoit Bryon's styleguide`_.

Non Sphinx rst documents (such as README, CONTRIBUTING) follow only rules
listed below

* Whitespaces
* Line length (where possible)
* Headings

.. _`Benoit Bryon's styleguide`: https://documentation-style-guide-sphinx.readthedocs.io/en/latest/style-guide.html

API Documentation
-----------------

API Documentation is prepared according to `OpenAPI 2.0`_.

.. _`OpenAPI 2.0`: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md

Code Documentation
------------------

Currently Godoc is not used. It will be included in Sphinx documentation in
later stages of the project.