Separate and update coding conventions and contributing pages

This commit is contained in:
Riku Isokoski 2021-11-07 18:30:29 +02:00 committed by JF
parent 1d3098baa7
commit 52d1906589
3 changed files with 51 additions and 52 deletions

View File

@ -17,6 +17,7 @@ InfiniTime is an open-source firmware for the [Pinetime smartwatch](https://www.
## Documentation ## Documentation
### Develop ### Develop
- [Coding conventions](/doc/coding-convention.md)
- [Rough structure of the code](doc/code/Intro.md) - [Rough structure of the code](doc/code/Intro.md)
- [How to implement an application](doc/code/Apps.md) - [How to implement an application](doc/code/Apps.md)
- [Generate the fonts and symbols](src/displayapp/fonts/README.md) - [Generate the fonts and symbols](src/displayapp/fonts/README.md)
@ -48,9 +49,9 @@ InfiniTime is an open-source firmware for the [Pinetime smartwatch](https://www.
This project is far from being finished, and there are still a lot of things to do for this project to become a firmware usable by the general public. This project is far from being finished, and there are still a lot of things to do for this project to become a firmware usable by the general public.
Do not hesitate to fork the code, hack it and create pull-requests! Do not hesitate to fork the code, hack it and create pull-requests! Make sure to read the [coding conventions](/doc/coding-convention.md)
Read this page for more information on how you can help: [How to contribute?](doc/contribute.md) You don't need to be a programmer to contribute. Read this page for more information on how you can help: [How to contribute?](doc/contribute.md)
## Licenses ## Licenses

40
doc/coding-convention.md Normal file
View File

@ -0,0 +1,40 @@
# Coding convention
## Language
The language of this project is **C++**, and all new code must be written in C++. (Modern) C++ provides a lot of useful tools and functionalities that are beneficial for embedded software development like `constexpr`, `template` and anything that provides zero-cost abstraction.
C code is accepted if it comes from another library like FreeRTOS, NimBLE, LVGL or the NRF-SDK.
## Coding style
The most important rule to follow is to try to keep the code as easy to read and maintain as possible.
Using an autoformatter is highly recommended, but make sure it's configured properly.
There are preconfigured autoformatter rules for:
* CLion (IntelliJ) in [.idea/codeStyles/Project.xml](/.idea/codeStyles/Project.xml)
* `clang-format`
Also use `clang-tidy` to check the code for other issues.
If there are no preconfigured rules for your IDE, you can use one of the existing ones to configure your IDE.
- **Indentation** : 2 spaces, no tabulation
- **Opening brace** at the end of the line
- **Naming** : Choose self-describing variable name
- **class** : PascalCase
- **namespace** : PascalCase
- **variable** : camelCase, **no** prefix/suffix ('_', 'm_',...) for class members
- **Include guard** : `#pragma once` (no `#ifdef __MODULE__ / #define __MODULE__ / #endif`)
- **Includes** :
- files from the project : `#include "relative/path/to/the/file.h"`
- external files and std : `#include <file.h>`
- Only use [primary spellings for operators and tokens](https://en.cppreference.com/w/cpp/language/operator_alternative)
- Use auto sparingly. Don't use auto for [fundamental/built-in types](https://en.cppreference.com/w/cpp/language/types) and [fixed width integer types](https://en.cppreference.com/w/cpp/types/integer), except when initializing with a cast to avoid duplicating the type name.
- Examples:
- `auto* app = static_cast<DisplayApp*>(instance);`
- `auto number = static_cast<uint8_t>(variable);`
- `uint8_t returnValue = MyFunction();`
- Use nullptr instead of NULL

View File

@ -14,10 +14,6 @@ As the documentation is part of the source code, you can submit your improvement
You want to fix a bug, add a cool new functionality or improve the code? See *How to submit a pull request below*. You want to fix a bug, add a cool new functionality or improve the code? See *How to submit a pull request below*.
## Spread the word
The Pinetime is a cool open source project that deserves to be known. Talk about it around you, on social networks, on your blog,... and let people know that we are working on an open source firmware for a smartwatch!
# How to submit a pull request? # How to submit a pull request?
## TL;DR ## TL;DR
@ -25,7 +21,7 @@ The Pinetime is a cool open source project that deserves to be known. Talk about
- Create a branch from develop - Create a branch from develop
- Work on a single subject in this branch. Create multiple branches/pulls-requests if you want to work on multiple subjects (bugs, features,...) - Work on a single subject in this branch. Create multiple branches/pulls-requests if you want to work on multiple subjects (bugs, features,...)
- Test your modifications on the actual hardware - Test your modifications on the actual hardware
- Check the code formatting against our coding conventions and [clang-format](../.clang-format) and [clang-tidy](../.clang-tidy) - Check your code against the [coding conventions](/doc/coding-convention.md) and [clang-format](../.clang-format) and [clang-tidy](../.clang-tidy)
- Clean your code and remove files that are not needed - Clean your code and remove files that are not needed
- Write documentation related to your new feature if applicable - Write documentation related to your new feature if applicable
- Create a pull request and write a great description about it: what does your PR do, why, how,... Add pictures and video if possible - Create a pull request and write a great description about it: what does your PR do, why, how,... Add pictures and video if possible
@ -38,9 +34,9 @@ If you want to fix a bug, add functionality or improve the code, you'll first ne
When your feature branch is ready, **make sure it actually works** and **do not forget to write documentation** about it if it's relevant. When your feature branch is ready, **make sure it actually works** and **do not forget to write documentation** about it if it's relevant.
**Creating a pull request containing modifications that haven't been tested is strongly discouraged.** If, for any reason, you cannot test your modifications but want to publish them anyway, **please mention it in the description**. This way, other contributors might be willing to test it and provide feedback about your code. **Creating a pull request containing modifications that haven't been tested is strongly discouraged.** If for any reason you cannot test your modifications, but want to publish them anyway, **please mention it in the description**. This way, other contributors might be willing to test it and provide feedback about your code.
Also, before submitting your PR, check the coding style of your code against the **coding conventions** detailed below. This project also provides [clang-format](../.clang-format) and [clang-tidy](../.clang-tidy) configuration files. You can use them to ensure correct formatting of your code. Before submitting a PR, check your code against our [coding conventions](/doc/coding-convention.md). This project also provides [clang-format](../.clang-format) and [clang-tidy](../.clang-tidy) configuration files. You should use them to ensure correct formatting of your code.
Don't forget to check the files you are going to commit and remove those which aren't necessary (config files from your IDE, for example). Remove old comments, commented code,... Don't forget to check the files you are going to commit and remove those which aren't necessary (config files from your IDE, for example). Remove old comments, commented code,...
@ -52,52 +48,14 @@ Once the pull request is reviewed and accepted, it'll be merged into **develop**
## Why all these rules? ## Why all these rules?
Reviewing pull requests is a **very time consuming task** for the creator of this project ([JF002](https://github.com/JF002)) and for other contributors who take the time to review them. Everything you do to make reviewing easier will **get your PR merged faster**. Reviewing pull requests is a **very time consuming task**. Everything you do to make reviewing easier will **get your PR merged faster**.
When reviewing PRs, the author and contributors will first look at the **description**. If it's easy to understand what the PR does, why the modification is needed or interesting and how it's done, a good part of the work is already done : we understand the PR and its context. Reviewers will first look at the **description**. If it's easy to understand what the PR does, why the modification is needed or interesting and how it's done, a good part of the work is already done : we understand the PR and its context.
Then, reviewing **a few files that were modified for a single purpose** is a lot more easier than to review 30 files modified for many reasons (bug fix, UI improvements, typos in doc,...), even if all these changes make sense. Also, it's possible that we agree on some modification but not on some other, so we won't be able to merge the PR because of the changes that are not accepted. Reviewing **a few files that were modified for a single purpose** is a lot easier than reviewing 30 files modified for many reasons (bug fix, UI improvements, typos in doc,...), even if all the changes make sense. Also, it's possible that we agree on some modification but not on another, so we won't be able to merge the PR because of the changes that are not accepted.
We do our best to keep the code as consistent as possible. If the formatting of the code in your PR is not consistent with our code base, we'll ask you to review it, which will take more time. We do our best to keep the code as consistent as possible. If the formatting of your code is not consistent with our code base, we'll ask you to review it.
The last step of the review consists of **testing** the modification. If it doesn't work out of the box, we'll ask your to review your code and to ensure that it works as expected. Lastly the changes are tested. If it doesn't work out of the box, we'll ask your to review your code and to ensure that it works as expected.
It's totally normal for a PR to need some more work even after it was created, that's why we review them. But every round trip takes time, so it's good practice to try to reduce them as much as possible by following those simple rules. It's totally normal for a PR to need some more work even after it was created, that's why we review them. But every round trip takes time, so it's good practice to try to reduce them as much as possible by following those simple rules.
# Coding convention
## Language
The language of this project is **C++**, and all new code must be written in C++. (Modern) C++ provides a lot of useful tools and functionalities that are beneficial for embedded software development like `constexpr`, `template` and anything that provides zero-cost abstraction.
C code is accepted if it comes from another library like FreeRTOS, NimBLE, LVGL or the NRF-SDK.
## Coding style
The most important rule to follow is to try to keep the code as easy to read and maintain as possible.
Using an autoformatter is highly recommended, but make sure it's configured properly.
There are preconfigured autoformatter rules for:
* CLion (IntelliJ) in .idea/codeStyles/Project.xml
If there are no preconfigured rules for your IDE, you can use one of the existing ones to configure your IDE.
- **Indentation** : 2 spaces, no tabulation
- **Opening brace** at the end of the line
- **Naming** : Choose self-describing variable name
- **class** : PascalCase
- **namespace** : PascalCase
- **variable** : camelCase, **no** prefix/suffix ('_', 'm_',...) for class members
- **Include guard** : `#pragma once` (no `#ifdef __MODULE__ / #define __MODULE__ / #endif`)
- **Includes** :
- files from the project : `#include "relative/path/to/the/file.h"`
- external files and std : `#include <file.h>`
- Only use [primary spellings for operators and tokens](https://en.cppreference.com/w/cpp/language/operator_alternative)
- Use auto sparingly. Don't use auto for [fundamental/built-in types](https://en.cppreference.com/w/cpp/language/types) and [fixed width integer types](https://en.cppreference.com/w/cpp/types/integer), except when initializing with a cast to avoid duplicating the type name.
- Examples:
- `auto* app = static_cast<DisplayApp*>(instance);`
- `auto number = static_cast<uint8_t>(variable);`
- `uint8_t returnValue = MyFunction();`
- Use nullptr instead of NULL