|
2 | 2 |
|
3 | 3 | ## Style and Linting |
4 | 4 | - Python formatting and linting is handled by **ruff**. |
5 | | -- Rust code must pass `cargo fmt`, `cargo clippy`, and `cargo tomlfmt`. |
| 5 | +- Follow [PEP 8](https://www.python.org/dev/peps/pep-0008/) and these key |
| 6 | + ruff rules: |
| 7 | + - Use double quotes for string literals |
| 8 | + - Use explicit relative imports such as `from .module import Class` |
| 9 | + - Limit lines to 88 characters |
| 10 | + - Provide type hints for parameters and return values |
| 11 | + - Avoid unused imports |
| 12 | + - Prefer f-strings over other string formatting |
| 13 | + - Avoid `else` blocks after `return` |
| 14 | + - Use `isinstance()` instead of direct type comparison |
| 15 | + - Keep docstrings concise in Google format |
| 16 | + - Assign exception messages to variables before raising |
| 17 | +- All modules, classes, and functions should include docstrings. |
| 18 | +- Tests must use descriptive function names, pytest style assertions, and be |
| 19 | + grouped in classes when appropriate. |
| 20 | +- Rust code must pass `cargo fmt`, `cargo clippy`, and `cargo tomlfmt` and |
| 21 | + should omit unnecessary parentheses around `if` conditions. |
6 | 22 | - Install the pre-commit hooks with `pre-commit install` and run them with |
7 | 23 | `pre-commit run --files <file1> <file2>` or `pre-commit run --all-files`. |
8 | 24 | - The same checks can be run manually using the scripts in `ci/scripts`: |
|
11 | 27 | - `./ci/scripts/rust_clippy.sh` |
12 | 28 | - `./ci/scripts/rust_toml_fmt.sh` |
13 | 29 |
|
| 30 | +## Code Organization |
| 31 | +- Keep functions focused and under about 50 lines. |
| 32 | +- Break complex tasks into well-named helper functions and reuse existing |
| 33 | + helpers when possible. |
| 34 | +- Prefer adding parameters to existing functions rather than creating new |
| 35 | + versions with similar behavior. |
| 36 | +- Avoid unnecessary abstractions and follow established patterns in the |
| 37 | + codebase. |
| 38 | + |
| 39 | +## Comments |
| 40 | +- Add meaningful comments for complex logic and avoid obvious comments. |
| 41 | +- Start inline comments with a capital letter. |
| 42 | + |
14 | 43 | ## Running Tests |
15 | 44 | 1. Ensure submodules are initialized: |
16 | 45 | ```bash |
|
0 commit comments