Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
project: Updating contributing guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaymar committed Aug 27, 2022
1 parent c45222b commit 2f55e8b
Showing 1 changed file with 154 additions and 102 deletions.
256 changes: 154 additions & 102 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,161 +1,213 @@
# Commits
Commits should always only focus on a single change that is necessary for that commit to work. For example, a commit that changes how something logs messages should not also include a new blur effect. In those cases, the commit should be split up into two, so that they can be reverted independently from another.
# Contributing
This document goes over how you and/or your company is expected to contribute to the project.

## Commit Subject
The subject line of a commit should begin with the prefix followed by a `: `, and then followed by a summary of what the change does, which should be no longer than 52 alphanumerical characters including whitespace. The prefix is determined by the file being modified, simply remove the extension or find the group that a file belongs to. For example, a modifiation to blur.effect would have the category effects, due to it being re-usable.
## Commit Guidelines
Commits should focus on a single change, such as formatting, fixing a single bug, a single warning across the code, and similar things. This means that you should not include a fix to color format handling in a commit that implements a new encoder.

### Prefixes
- effects: Anything modifying generic effects like blur.effect, color-conversion.effect, mask.effect, etc.
- locale: Changes in `/data/locale`.
- examples: Changes in `/data/examples` that are not directly influenced by a change to one of the filters, sources or transitions.
- project: Changes to files like README, CONTRIBUTING, AUTHORS, etc.
- cmake: Changes to CMake build scripts.
- ci: Changes to Continuous Integration.
### Commit Message & Title
As the StreamFX project uses linear history without merge commits, we require a commit message format like this:

All other files should be prefixed with the main file changed, so a change to the translations for Source Mirror would be `source-mirror: commit`.
```
prefix: short description
optional long description
```

The `short description` should be no longer than 80 characters, excluding the `prefix: ` part. The `optional long description` should be present if the change is not immediately obvious - however it does not replace proper documentation.

#### The correct `prefix`
Depending on where the file is that you ended up modifying, or if you modified multiple files at once, the prefix changes. Take a look at the list to understand which directories cause which prefix:

- `/CMakeLists.txt`, `/cmake` -> `cmake`
- `/.github/workflows` -> `ci`
- `/data/locale/`, `/crowdin.yml` -> `locale`
- `/data/examples/` -> `examples`
- `/data` -> `data` (if not part of another prefix)
- `/media` -> `media`
- `/source`, `/include` -> `code`
- `/templates` -> `templates` (or merge with `cmake`)
- `/third-party` -> `third-party`
- `/tools` -> `tools`
- `/ui` -> `ui` (if not part of a `code` change)
- Most other files -> `project`

## Commit Messages
The commit message should always convey why this change was necessary, what is being changed and how it affects the code when being run. There are rare cases where this can be left out (formatting, refactoring, ...) but it should always be descriptive of what is actually being done.
Multiple prefixes should be separated by `, ` and sorted alphabetically so that a change to `ui` and `code` results in a prefix of `code, ui`. If only a single code file was changed or multiple related file with a common parent were changed, the `code` prefix should be replaced by the path to the file like in these examples:

# Coding Guidelines
- `/source/encoders/encoder-ffmpeg` -> `encoder/ffmpeg`
- `/source/filters/filter-shader` -> `filter/shader`
- and so on.

## Naming
The project uses the generally known snake_case for code and the uppercase variant for enumerations and macros:
These guidelines are soft requirements and may be extended in the future.

### Macros (ELEPHANT_CASE)
- Casing: Uppercase
## Coding Guidelines

### Naming & Casing
#### Macros
- Casing: ELEPHANT_CASE
- Separator: `_`
- Prefixes: `S_` for global values, `ST_` for local (this file) values, `D_` for simple functions, `P_` for complex functions
- Prefixes: Optional
- `S_` for global values
- `ST_` for local values
- `D_` for simple functions
- `P_` for complex functions
- Suffixes: No

Example:
##### Example
```
#define S_PI 3.14141
#define ST_PI2 S_PI / 2.0
#define D_(x) S_PI * x
#define P_(x, y) double_t x(double_t a, double_t b) { return a * b * y; }
#define EXAMPLE FALSE // ❌
#define S_PI 3.14141 // ✔ (in .h and .hpp files)
#define ST_PI2 S_PI / 2.0 // ✔
#define D_(x) S_PI * x // ✔
#define P_(x, y) double_t x(double_t a, double_t b) { return a * b * y; } // ✔
```

### Enumerations (snake_case)
- Casing: Lowercase
#### Namespaces
- Casing: snake_case
- Separator: `_`
- Prefixes: None
- Suffixes: None

Example:
##### Example
```
enum my_enum {};
enum class my_enum_class {};
enum class my_enum_class_int : int {};
namespace BLA {}; // ❌
namespace a_space {}; // ✔
```

#### Enumeration Entries (ELEPHANT_CASE)
- Casing: Uppercase
#### Type Definitions
- Casing: snake_case
- Separator: `_`
- Prefixes: No
- Suffixes: `_t`

Example:
```
enum my_enum {
ENTRY_1,
ENTRY_2
};
typedef int32_t my_type; // ❌
typedef int32_t my_type_t; // ✔
```

### Variables (snake_case)
- Casing: Lowercase
#### Enumerations
- Casing: snake_case
- Separator: `_`
- Prefixes: No
- Suffixes: No

Example:
##### Entries
- Casing: ELEPHANT_CASE
- Separator: `_`
- Prefixes: Conditional
- `enum`: `STREAMFX_<ENUM_NAME>_`
- `enum class`: None
- Suffixes: No

##### Example
```
int my_var = 0;
enum my_enum { // ✔
STREAMFX_MY_ENUM_ENTRY_1, // ✔
ENUM_ENTRY_2 // ❌
};
enum class my_enum : int { // ✔
STREAMFX_MY_ENTRY_1, // ❌
ENUM_ENTRY_2 // ✔
};
enum class my_enum_int : int { // ❌, has `_int` suffix.
};
```

### Functions (snake_case)
- Casing: Lowercase
#### Variables
- Casing: snake_case
- Separator: `_`
- Prefixes: No
- Suffixes: No (differentiate by parameters only)
- Prefixes:
- Locals: None
- Globals: `g_`
- Suffixes: None

Example:
##### Example
```
// This is forbidden.
void func();
int func_int();
float example; // ❌
float g_example; // ✔
// This is okay.
void func();
void func(int& result);
function example() {
float _example; // ❌
float example; // ✔
}
```

### Namespaces (snake_case)
- Casing: Lowercase
#### Classes & Structures
- Casing: snake_case
- Separator: `_`
- Prefixes: None
- Suffixes: None

Example:
```
namespace a_space {};
```
##### Members
- Casing: snake_case
- Separator: `_`
- Prefixes:
- `_` for private, protected
- None for public (prefer set-/get-ters)
- Suffixes: None

### Classes, Structs, Unions (snake_case)
- Casing: Lowercase
##### Methods
- Casing: snake_case
- Separator: `_`
- Prefixes: No
- Suffixes: No
- Prefixes: None
- Suffixes: None

Example:
```
class a_class {};
class interface_class {};
##### Example
```
class example {
float example; // ❌
float _example; // ✔
#### Interface Classes
Interface Classes are handled like normal classes. There are no prefixes or suffixes to attach.

#### Methods (snake_case)
- Casing: Lowercase
- Separator: `_`
- Prefixes: No
- Suffixes: No (differentiate by parameters only)
int example_int(); // ❌, has `_int` suffix.
void example(); // ✔
void example(int& result); // ✔
}
Example:
```
class a_class {
// This is forbidden.
void func();
int func_int();
// This is okay.
void func();
void func(int& result);
};
struct example {
float _example; // ❌
float example; // ✔
}
```

#### Member Variables (snake_case)
- Casing: Lowercase
#### Unions
- Casing: snake_case
- Separator: `_`
- Prefixes: `_` if private, otherwise none
- Suffixes: No
- Prefixes: None
- Suffixes: None

Example:
##### Union Members
- Casing: snake_case
- Separator: `_`
- Prefixes: None
- Suffixes: None

##### Example
```
class a_class {
int64_t _local_var;
void* _pointer;
int32_t _id;
};
union {
float _example; // ❌
float example; // ✔
}
```

### Type Definitions (snake_case)
- Casing: Lowercase
#### Functions
- Casing: snake_case
- Separator: `_`
- Prefixes: No
- Suffixes: `_t`
- Suffixes: No

Example:
##### Example
```
typedef int32_t my_type_t;
void func(); // ✔
void func(int& result); // ✔
int func_int(); // ❌
```

## Preprocessor Macros
Preprocessor `#define` Macros should be used sparingly, due to their nature of changing code before the compiler gets a chance to work with it. Unless necessary, they should never be in a header file.
#### Interface Classes
Interface Classes are handled like normal classes. There are no prefixes or suffixes to attach.

### Preprocessor Macros
Pre-processor Macros are a "last stand" option, when all other options fail or would produce worse results. If possible and cleaner to do so, prefer the use of `constexpr` code.

### Classes
#### Members
Members of classes should be private and only accessible via get/set methods.

0 comments on commit 2f55e8b

Please sign in to comment.