| 1 |
# Contributing |
| 2 |
|
| 3 |
I would appreciate any contributions to this crate. However, some things are handy to know. |
| 4 |
|
| 5 |
## Code Style |
| 6 |
|
| 7 |
### Import Order |
| 8 |
|
| 9 |
All imports are semantically grouped and ordered. The order is: |
| 10 |
|
| 11 |
- standard library (`use std::...`) |
| 12 |
- external crates (`use rand::...`) |
| 13 |
- current crate (`use crate::...`) |
| 14 |
- parent module (`use super::..`) |
| 15 |
- current module (`use self::...`) |
| 16 |
- module declaration (`mod ...`) |
| 17 |
|
| 18 |
There must be an empty line between groups. An example: |
| 19 |
|
| 20 |
```rust |
| 21 |
use crossterm_utils::{csi, write_cout, Result}; |
| 22 |
|
| 23 |
use crate::sys::{get_cursor_position, show_cursor}; |
| 24 |
|
| 25 |
use super::Cursor; |
| 26 |
``` |
| 27 |
|
| 28 |
#### CLion Tips |
| 29 |
|
| 30 |
The CLion IDE does this for you (_Menu_ -> _Code_ -> _Optimize Imports_). Be aware that the CLion sorts |
| 31 |
imports in a group in a different way when compared to the `rustfmt`. It's effectively two steps operation |
| 32 |
to get proper grouping & sorting: |
| 33 |
|
| 34 |
* _Menu_ -> _Code_ -> _Optimize Imports_ - group & semantically order imports |
| 35 |
* `cargo fmt` - fix ordering within the group |
| 36 |
|
| 37 |
Second step can be automated via _CLion_ -> _Preferences_ -> |
| 38 |
_Languages & Frameworks_ -> _Rust_ -> _Rustfmt_ -> _Run rustfmt on save_. |
| 39 |
|
| 40 |
### Max Line Length |
| 41 |
|
| 42 |
| Type | Max line length | |
| 43 |
|:---------------------|----------------:| |
| 44 |
| Code | 100 | |
| 45 |
| Comments in the code | 120 | |
| 46 |
| Documentation | 120 | |
| 47 |
|
| 48 |
100 is the [`max_width`](https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#max_width) |
| 49 |
default value. |
| 50 |
|
| 51 |
120 is because of the GitHub. The editor & viewer width there is +- 123 characters. |
| 52 |
|
| 53 |
### Warnings |
| 54 |
|
| 55 |
The code must be warning free. It's quite hard to find an error if the build logs are polluted with warnings. |
| 56 |
If you decide to silent a warning with (`#[allow(...)]`), please add a comment why it's required. |
| 57 |
|
| 58 |
Always consult the [Travis CI](https://travis-ci.org/crossterm-rs/crossterm/pull_requests) build logs. |
| 59 |
|
| 60 |
### Forbidden Warnings |
| 61 |
|
| 62 |
Search for `#![deny(...)]` in the code: |
| 63 |
|
| 64 |
* `unused_must_use` |
| 65 |
* `unused_imports` |