Skip to content

Commit 544f492

Browse files
authored
[feat/fix]: Add contributing guidelines and update templates (#610)
* feat: Add contributing guidelines * fix: Use the correct links in PR/issue template * fix: Update README.md to point to correct links * fix: Update README.md * fix: Move contributing guidelines to root directory * fix: Update PR template
1 parent 4cb3eeb commit 544f492

File tree

4 files changed

+236
-7
lines changed

4 files changed

+236
-7
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ assignees: ''
2424
## Steps to Reproduce
2525
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
2626
<!--- reproduce this bug. Include code to reproduce, if relevant -->
27+
2728
1.
2829
2.
2930
3.

.github/pull_request_template.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#### Description of Change
2+
23
<!--
34
Thank you for your Pull Request. Please provide a description above and review
45
the requirements below.
56
6-
Contributors guide: https://github.com/TheAlgorithms/C-Plus-Plus/CONTRIBUTING.md
7+
Contributors guide: https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md
78
-->
89

910
#### References
@@ -13,10 +14,10 @@ Contributors guide: https://github.com/TheAlgorithms/C-Plus-Plus/CONTRIBUTING.md
1314
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->
1415

1516
- [ ] Added description of change
16-
- [ ] Added file name matches [File name guidelines](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTING.md#New-File-Name-guidelines)
17+
- [ ] Added file name matches [File name guidelines](https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md#File-Name-guidelines)
1718
- [ ] Added tests and example, test must pass
1819
- [ ] Relevant documentation/comments is changed or added
19-
- [ ] PR title follows semantic [commit guidelines](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTING.md#Commit-Guidelines)
20+
- [ ] PR title follows semantic [commit guidelines](https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md#Commit-Guidelines)
2021
- [ ] Search previous suggestions before making a new one, as yours may be a duplicate.
2122
- [ ] I acknowledge that all my contributions will be made under the project's license.
2223

CONTRIBUTING.md

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# CONTRIBUTION GUIDELINES
2+
3+
## Before contributing
4+
5+
Welcome to [TheAlgorithms/C](https://github.com/TheAlgorithms/C)! 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/C/issues/new/choose) and clearly state your concerns.
6+
7+
## Contributing
8+
9+
### Maintainer/developer
10+
11+
If you are a maintainer of this repository, please consider the following:
12+
13+
- It is a protocol to contribute via pull requests.
14+
- Reviewers will advise and guide you up to make the code refined and documented.
15+
- When reviewing pull requests, be sure to:
16+
- Be kind.
17+
- Be respectful.
18+
- Make useful suggestions/comments.
19+
- Be sure not to make invalid suggestions/comments.
20+
- Guide and advise up the pull request author.
21+
22+
### Contributor
23+
24+
We are very happy that you consider implementing algorithms and data structures for others! This repository is referred to and used by learners from around the globe. Being one of our contributors, you agree and confirm that:
25+
26+
- You did your own work.
27+
- No plagiarism allowed. Any plagiarized work will not be merged.
28+
- Your work will be distributed under the [GNU General Public License v3.0](https://github.com/TheAlgorithms/C/blob/master/LICENSE) once your pull request has been merged.
29+
- You submitted work fulfils or mostly fulfils our styles and standards.
30+
31+
**New implementation** New implementation are welcome!
32+
33+
**Improving comments** and **adding tests** to existing algorithms are much appreciated.
34+
35+
**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.
36+
37+
### Making Changes
38+
39+
#### Code
40+
41+
- Please use the directory structure of the repository.
42+
- File extension for code should be `*.h` `*.c`
43+
- Organize your code using **`struct`** keywords
44+
- If an implementation of the algorithm already exists, please refer to the [file-name section below](#file-name-guidelines).
45+
- You can suggest reasonable changes to existing algorithms.
46+
- Strictly use snake_case (underscore_separated) in filenames.
47+
- If you have added or modified code, please make sure the code compiles before submitting.
48+
- Our automated testing runs [__CMake__](https://cmake.org/) on all pull requests so please be sure that your code passes before submitting.
49+
- Please conform to [doxygen](https://www.doxygen.nl/manual/docblocks.html) standard and document the code as much as possible. This not only facilitates the readers but also generates the correct info on website.
50+
- **Be consistent in use of these guidelines.**
51+
52+
#### Documentation
53+
54+
- Make sure you put useful comments in your code. Do not comment things that are obvious.
55+
- 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.
56+
- If you have modified/added documentation, please ensure that your language is concise and contains no grammar errors.
57+
- Do not update 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
58+
- The repository follows [Doxygen](https://www.doxygen.nl/manual/docblocks.html) standards and auto-generates the [repository website](https://thealgorithms.github.io/C). Please ensure the code is documented in this structure. Sample implementation is given below.
59+
60+
#### Test
61+
62+
- Make sure to add examples and test cases in your main() function.
63+
- If you find any algorithm or document without tests, please feel free to create a pull request or issue describing suggested changes.
64+
- Please try to add one or more `test()` functions that will invoke the algorithm implementation on random test data with expected output. Use `assert()` function to confirm that the tests will pass. Requires adding the `assert.h` library.
65+
66+
#### Typical structure of a program
67+
68+
```c
69+
/**
70+
* @file
71+
* @brief Add one line description here
72+
* @details
73+
* This is a multi line
74+
* description containing links, references,
75+
* math equations, etc
76+
* @author [Name](https://github.com/handle)
77+
* @see related_file.c, another_file.c
78+
*/
79+
80+
#include <assert.h>
81+
#include
82+
83+
/**
84+
* @brief Struct documentation
85+
*/
86+
struct struct_name {
87+
int variable; ///< short info of this variable
88+
char message; ///< short info
89+
};
90+
91+
/**
92+
* Function documentation
93+
* @param param1 one-line info about param1
94+
* @param param2 one-line info about param2
95+
* @returns `true` if ...
96+
* @returns `false` if ...
97+
*/
98+
bool func(int param1, int param2) {
99+
// function statements here
100+
if (/*something bad*/) {
101+
return false;
102+
}
103+
104+
return true;
105+
}
106+
107+
/**
108+
* @brief Test function
109+
* @returns void
110+
*/
111+
static void test() {
112+
/* desciptions of the following test */
113+
assert(func(...) == ...); // this ensures that the algorithm works as expected
114+
115+
// can have multiple checks
116+
}
117+
118+
/**
119+
* @brief Main function
120+
* @returns 0 on exit
121+
*/
122+
int main() {
123+
test(); // execute the tests
124+
// code here
125+
return 0;
126+
}
127+
```
128+
129+
#### File name guidelines
130+
131+
- Use lowercase words with ``"_"`` as separator
132+
- For instance
133+
134+
```markdown
135+
MyNewCStruct.C is incorrect
136+
my_new_c_struct.c is correct format
137+
```
138+
139+
- It will be used to dynamically create a directory of files and implementation.
140+
- File name validation will run on docker to ensure the validity.
141+
- 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 `median_search.c` already exists in the `search` folder and you are contributing a new implementation, the filename should be `median_search2.c` and for a third implementation, `median_search3.c`.
142+
143+
#### Directory guidelines
144+
145+
- We recommend adding files to existing directories as much as possible.
146+
- Use lowercase words with ``"_"`` as separator ( no spaces or ```"-"``` allowed )
147+
- For instance
148+
149+
```markdown
150+
SomeNew Fancy-Category is incorrect
151+
some_new_fancy_category is correct
152+
```
153+
154+
- Filepaths will be used to dynamically create a directory of our algorithms.
155+
- Filepath validation will run on GitHub Actions to ensure compliance.
156+
157+
#### Commit Guidelines
158+
159+
- It is recommended to keep your changes grouped logically within individual commits. Maintainers find it easier to understand changes that are logically spilt across multiple commits. Try to modify just one or two files in the same directory. Pull requests that span multiple directories are often rejected.
160+
161+
```bash
162+
git add file_xyz.c
163+
git commit -m "your message"
164+
```
165+
166+
Examples of commit messages with semantic prefixes:
167+
168+
```markdown
169+
fix: xyz algorithm bug
170+
feat: add xyx algorithm, struct xyz
171+
test: add test for xyz algorithm
172+
docs: add comments and explanation to xyz algorithm
173+
```
174+
175+
Common prefixes:
176+
177+
- fix: A bug fix
178+
- feat: A new feature
179+
- docs: Documentation changes
180+
- test: Correct existing tests or add new ones
181+
182+
### Pull Requests
183+
184+
- Checkout our [pull request template](https://github.com/TheAlgorithms/C/blob/master/.github/pull_request_template.md)
185+
186+
#### Building Locally
187+
188+
Before submitting a pull request, 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/C) service.
189+
190+
```bash
191+
cmake -B build -S .
192+
```
193+
194+
#### Static Code Analyzer
195+
196+
We use [clang-tidy](https://clang.llvm.org/extra/clang-tidy/) as a static code analyzer with a configuration in [.clang-tidy](.clang-tidy).
197+
198+
```bash
199+
clang-tidy --fix --quiet -p build subfolder/file_to_check.c --
200+
```
201+
202+
#### Code Formatter
203+
204+
[__clang-format__](https://clang.llvm.org/docs/ClangFormat.html) is used for code forrmating.
205+
206+
- Installation (only needs to be installed once.)
207+
- Mac (using home-brew): `brew install clang-format`
208+
- Mac (using macports): `sudo port install clang-10 +analyzer`
209+
- Windows (MSYS2 64-bit): `pacman -S mingw-w64-x86_64-clang-tools-extra`
210+
- Linux (Debian): `sudo apt-get install clang-format-10 clang-tidy-10`
211+
- Running (all platforms): `clang-format -i -style="file" my_file.c`
212+
213+
#### GitHub Actions
214+
215+
- Enable GitHub Actions on your fork of the repository.
216+
After enabling it will execute `clang-tidy` and `clang-format` after every a push (not a commit).
217+
- Click on the tab "Actions", then click on the big green button to enable it.
218+
219+
![GitHub Actions](https://user-images.githubusercontent.com/51391473/94609466-6e925100-0264-11eb-9d6f-3706190eab2b.png)
220+
221+
- The result can create another commit if the actions made any changes on your behalf.
222+
- Hence, it is better to wait and check the results of GitHub Actions after every push.
223+
- Run `git pull` in your local clone if these actions made many changes in order to avoid merge conflicts.
224+
225+
Most importantly,
226+
227+
- Happy coding!

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
<!-- the suffix in the above line is required for doxygen to consider this as the index page of the generated documentation site -->
33

44
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/TheAlgorithms/C)
5-
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/TheAlgorithms/C.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/TheAlgorithms/C/context:cpp)
5+
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/TheAlgorithms/C.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/TheAlgorithms/C/context:cpp)
66
[![Gitter chat](https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square)](https://gitter.im/TheAlgorithms)
7-
[![contributions welcome](https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=flat-square)](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/CONTRIBUTING.md)
7+
[![contributions welcome](https://img.shields.io/static/v1.svg?label=Contributions&message=Welcome&color=0059b3&style=flat-square)](https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md)
88
![GitHub repo size](https://img.shields.io/github/repo-size/TheAlgorithms/C?color=red&style=flat-square)
99
[![Doxygen CI](https://github.com/TheAlgorithms/C/workflows/Doxygen%20CI/badge.svg)](https://TheAlgorithms.github.io/C)
1010
[![Awesome CI](https://github.com/TheAlgorithms/C/workflows/Awesome%20CI%20Workflow/badge.svg)](https://github.com/TheAlgorithms/C/actions?query=workflow%3A%22Awesome+CI+Workflow%22)
1111

1212
## Overview
1313

14-
The repository is a collection of open-source implementation of a variety of algorithms implemented in C and licensed under [GPLv3 License](https://github.com/TheAlgorithms/C/blob/master/LICENSE). The algorithms span a variety of topics from computer science, mathematics and statistics, data science, machine learning, engineering, etc.. The implementations and the associated documentation are meant to provide a learning resource for educators and students. Hence, one may find more than one implementation for the same objective but using a different algorithm strategies and optimizations.
14+
The repository is a collection of open-source implementation of a variety of algorithms implemented in C and licensed under [GPLv3 License](https://github.com/TheAlgorithms/C/blob/master/LICENSE). The algorithms span a variety of topics from computer science, mathematics and statistics, data science, machine learning, engineering, etc.. The implementations and the associated documentation are meant to provide a learning resource for educators and students. Hence, one may find more than one implementation for the same objective but using a different algorithm strategies and optimizations.
1515

1616
## Features
1717

1818
* The repository provides implementations of various algorithms in one of the most fundamental general purpose languages - [C](https://en.wikipedia.org/wiki/C_(programming_language)).
1919
* Well documented source code with detailed explanations provide a valuable resource for educators and students alike.
2020
* Each source code is atomic using standard C library [`libc`](https://en.wikipedia.org/wiki/C_standard_library) and _no external libraries_ are required for their compilation and execution. Thus the fundamentals of the algorithms can be studied in much depth.
21-
* Source codes are [compiled and tested](https://github.com/TheAlgorithms/C/actions?query=workflow%3A%22Awesome+CI+Workflow%22) for every commit on the latest versions of three major operating systems viz., Windows, MacOS and Ubuntu (Linux) using MSVC 16 2019, AppleClang 11.0 and GNU 7.5.0 respectively.
21+
* Source codes are [compiled and tested](https://github.com/TheAlgorithms/C/actions?query=workflow%3A%22Awesome+CI+Workflow%22) for every commit on the latest versions of three major operating systems viz., Windows, MacOS and Ubuntu (Linux) using MSVC 16 2019, AppleClang 11.0 and GNU 7.5.0 respectively.
2222
* Strict adherence to [C11](https://en.wikipedia.org/wiki/C11_(C_standard_revision)) standard ensures portability of code to embedded systems as well like ESP32, ARM Cortex, etc. with little to no changes.
2323
* Self-checks within programs ensure correct implementations with confidence.
2424
* Modular implementations and OpenSource licensing enable the functions to be utilized conveniently in other applications.

0 commit comments

Comments
 (0)