Skip to content

Commit 6345537

Browse files
authored
Apply code style (#313)
2 parents 0a282fa + 48e0ccb commit 6345537

File tree

109 files changed

+469
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+469
-183
lines changed
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
<!--
2-
Provide a brief description of fixes provided in this pull request
3-
(Tip: Focus on what and why instead of how).
4-
Examples
5-
- Added tests for x algorithm/program.
6-
- Optimized implementation of y to improve time and/or space complexity.
7-
- Added a new implementation for z algorithm/ z data structure.
8-
9-
Fixes #<mention_issue_number_here>
10-
-->
1+
#### Description of Change
2+
<!--
3+
Thank you for your Pull Request. Please provide a description above and review
4+
the requirements below.
5+
6+
Contributors guide: https://github.com/TheAlgorithms/Go/CONTRIBUTING.md
7+
-->
8+
9+
#### Checklist
10+
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->
11+
12+
- [ ] Added description of change
13+
- [ ] Added file name matches [File name guidelines](https://github.com/TheAlgorithms/Go/blob/master/CONTRIBUTING.md#New-File-Name-guidelines)
14+
- [ ] Added tests and example, test must pass
15+
- [ ] Added documentation so that the program is self-explanatory and educational - [GoDoc guidelines](https://blog.golang.org/godoc)
16+
- [ ] Relevant documentation/comments is changed or added
17+
- [ ] PR title follows semantic [commit guidelines](https://github.com/TheAlgorithms/Go/blob/master/CONTRIBUTING.md#Commit-Guidelines)
18+
- [ ] Search previous suggestions before making a new one, as yours may be a duplicate.
19+
- [ ] I acknowledge that all my contributions will be made under the project's license.
20+
21+
Notes: <!-- Please add a one-line description for developers or pull request viewers -->

.github/workflows/golang_lint_and_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ jobs:
1616
# specified without patch version: we always use the latest patch version.
1717
# https://github.com/golangci/golangci-lint/releases
1818
version: v1.39
19-
- run: go test $(go list ./... | grep -v /sbom | grep -v /rsa)
19+
- run: go test $(go list ./... | grep -v /sbom | grep -v /rsa_cipher)

CONTRIBUTING.md

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# CONTRIBUTION GUIDELINES
2+
3+
## Before contributing
4+
5+
Welcome to [TheAlgorithms/Go](https://github.com/TheAlgorithms/Go)! Before submitting pull requests, please make sure that you have **read the whole guidelines**. If you have any doubts about this contribution guide, please open [an issue](https://github.com/TheAlgorithms/Go/issues/new/choose) or ask in our [Discord server](https://discord.gg/c7MnfGFGa6) / [Gitter](https://gitter.im/TheAlgorithms), and clearly state your concerns.
6+
7+
## Contributing
8+
9+
### Maintainer/reviewer
10+
11+
**Please check the [reviewer code](https://github.com/TheAlgorithms/Go/blob/master/DIRECTORY.md) file for maintainers and reviewers.**
12+
13+
### Contributor
14+
15+
Being a contributor at The Algorithms, we request you to follow the points mentioned below:
16+
17+
- You did your own work.
18+
- No plagiarism allowed. Any plagiarized work will not be merged.
19+
- Your work will be distributed under the [MIT License](https://github.com/TheAlgoritms/Go/blob/master/LICENSE) once your pull request has been merged.
20+
- Please follow the repository guidelines and standards mentioned below.
21+
22+
**New implementation** New implementations are welcome!
23+
24+
You can add new algorithms or data structures which are **not present in the repository** or that can **improve** the old implementations (**documentation**, **improving test cases**, removing bugs or in any other resonable sense)
25+
26+
**Issues** Please avoid opening issues asking to be "assigned” to a particular algorithm. This merely creates unnecessary noise for maintainers. Instead, please submit your implementation in a pull request, and it will be evaluated by project maintainers.
27+
28+
### Making Changes
29+
30+
#### Code
31+
32+
- Please use the directory structure of the repository.
33+
- Make sure the file extensions should be `*.go`.
34+
- Use meaning variable names.
35+
- Use standard library inside your code and avoid to import packages from other repositories
36+
- If an implementation of the algorithm already exists, please refer to the [file-name section below](#new-file-name-guidelines).
37+
- You can suggest reasonable changes to existing algorithms.
38+
- Strictly use snake_case (underscore_separated) in filenames.
39+
- If you have added or modified code, please make sure the code compiles before submitting.
40+
- Our automated testing runs [LGTM](https://lgtm.com/projects/g/TheAlgorithms/Go/) on all the pull requests, so please be sure that your code passes before submitting.
41+
- Please conform to [GoDoc](https://blog.golang.org/godoc) standard and document the code as much as possible. This not only facilitates the readers but also generates the correct info on the website.
42+
- **Be consistent in the use of these guidelines.**
43+
44+
#### Documentation
45+
46+
- Make sure you put useful comments in your code. Do not comment on obvious things.
47+
- Please avoid creating new directories if at all possible. Try to fit your work into the existing directory structure. If you want to create a new directory, then please check if a similar category has been recently suggested or created by other pull requests.
48+
- If you have modified/added documentation, please ensure that your language is concise and must not contain grammatical errors.
49+
- Do not update [`README.md`](https://github.com/TheAlgorithms/Go/blob/master/README.md) along with other changes. First, create an issue and then link to that issue in your pull request to suggest specific changes required to [`README.md`](https://github.com/TheAlgorithms/Go/blob/master/README.md).
50+
- The repository follows [GoDoc](https://blog.golang.org/godoc) standards and auto-generates the [repository website](https://thealgorithms.github.io/). Please ensure the code is documented in this structure. A sample implementation is given below.
51+
52+
#### Test
53+
54+
- Make sure to add examples and test cases in your `filename_test.go` file.
55+
- If you find an algorithm or document without tests, please feel free to create a pull request or issue describing suggested changes.
56+
- Please try to add one or more `Test` functions that will invoke the algorithm implementation on random test data with the expected output.
57+
58+
#### Typical structure of a program
59+
60+
```go
61+
62+
// filename
63+
// description: Add one line description here
64+
// details:
65+
// This is a multi-line
66+
// description containing links, references,
67+
// math equations, etc.
68+
// author(s) [Name](https://github.com/handle), [Name](https://github.com/handle)
69+
// see related_file.go, another_file.go, file_test.go
70+
71+
72+
// Package sort provides primitives for sorting slices and user-defined
73+
// collections.
74+
package sort
75+
76+
// Reasons why you used those packages
77+
// name package : Add one line description here
78+
// name2 package : Add one line description here
79+
// ...
80+
import (
81+
...
82+
)
83+
84+
85+
// Fprint formats using the default formats for its operands and writes to w.
86+
// Spaces are added between operands when neither is a string.
87+
// It returns the number of bytes written and any write error encountered.
88+
func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
89+
...
90+
}
91+
92+
93+
```
94+
95+
#### New File Name guidelines
96+
97+
- Use lowercase words with ``"_"`` as a separator
98+
- For instance
99+
100+
```markdown
101+
MyNewGoFile.GO is incorrect
102+
my_new_go_file.go is correct format
103+
```
104+
105+
- It will be used to dynamically create a directory of files and implementation.
106+
- File name validation will run on Docker to ensure validity.
107+
- If an implementation of the algorithm already exists and your version is different from that implemented, please use incremental numeric digit as a suffix. For example: if `binary_search.go` already exists in the `search` folder, and you are contributing a new implementation, the filename should be `binary_search2.go` and for a third implementation, `binary_search3.go`.
108+
109+
#### New Directory guidelines
110+
111+
- We recommend adding files to existing directories as much as possible.
112+
- Use lowercase words with ``"_"`` as separator ( no spaces or ```"-"``` allowed )
113+
- For instance
114+
115+
```markdown
116+
SomeNew Fancy-Category is incorrect
117+
some_new_fancy_category is correct
118+
```
119+
120+
- Filepaths will be used to dynamically create a directory of our algorithms.
121+
- Filepath validation will run on GitHub Actions to ensure compliance.
122+
123+
#### Commit Guidelines
124+
125+
- It is recommended to keep your changes grouped logically within individual commits. Maintainers find it easier to understand changes that are logically spilled across multiple commits. Try to modify just one or two files in the same directory. Pull requests that span multiple directories are often rejected.
126+
127+
```bash
128+
git add file_xyz.go
129+
git commit -m "your message"
130+
```
131+
132+
Examples of commit messages with semantic prefixes:
133+
134+
```markdown
135+
fix: xyz algorithm bug
136+
feat: add xyx algorithm
137+
test: add test for xyz algorithm
138+
docs: add comments and explanation to xyz algorithm
139+
```
140+
141+
Common prefixes:
142+
143+
- fix: A bug fix
144+
- feat: A new feature
145+
- docs: Documentation changes
146+
- test: Correct existing tests or add new ones
147+
148+
### Pull Requests
149+
150+
- Checkout our [pull request template](https://github.com/TheAlgorithms/Go/blob/master/.github/PULL_REQUEST_TEMPLATE/pull_request.go
151+
)
152+
153+
#### Building Locally
154+
155+
Before submitting a pull request,
156+
build the code locally or using the convenient [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/TheAlgorithms/Go) service.
157+
158+
```bash
159+
go build .
160+
```
161+
162+
#### Code Formatter
163+
164+
- Installation (only needs to be installed once.)
165+
- Mac (using home-brew): `brew install go`
166+
- Windows (MSYS2 64-bit): `choco install golang` [Chocolatey Package Manager](https://chocolatey.org/)
167+
- Linux (Debian): `sudo apt-get install golang`
168+
- Running (all platforms): `go run main.go` or `go build main.go`
169+
170+
#### GitHub Actions
171+
172+
- Enable GitHub Actions on your fork of the repository.
173+
After enabling, it will execute `golang_lint_and_test` after every push (not a commit).
174+
- The result can create another commit if the actions made any changes on your behalf.
175+
- Hence, it is better to wait and check the results of GitHub Actions after every push.
176+
- Run `git pull` in your local clone if these actions made many changes to avoid merge conflicts.
177+
178+
Most importantly,
179+
180+
- Happy coding!

0 commit comments

Comments
 (0)