This style guide provides guidelines for writing and formatting code, commit messages, and branch names to ensure consistency and maintainability across the project.
- Write clear, concise, and self-explanatory code.
- Use meaningful variable and function names.
- Adhere to the language-specific best practices.
- Ensure your code is modular and reusable.
- Avoid code duplication and hard coded values
- Include docstrings for all functions, classes, and modules.
Commit messages should be clear and descriptive. Follow these conventions for commit messages:
- Use the present tense ("Add feature" not "Added feature").
- Use the imperative mood ("Fix bug" not "Fixed bug").
- Keep the subject line (first line) under 50 characters.
- Separate subject from body with a blank line.
- Provide a detailed description of the changes in the body.
- Include references to relevant issues or pull requests.
feat: Add user authentication module
Implemented user login and registration functionalities.
Updated the database schema to include user credentials.
fix: Resolve crash on app startup
Fixed an issue causing the app to crash on startup due to a null pointer exception.
Closes #42.
Branch names should be descriptive and follow a consistent pattern. Use the following conventions for naming branches:
- Use lowercase letters and hyphens (
-
) to separate words. - Include a prefix to indicate the type of branch:
feat/
for new featuresfix/
for bug fixeschore/
for maintenance tasksdocs/
for documentation updates
- Optionally, include an issue or ticket number for tracking (e.g., feat/issue-55-add-auth).
feat/add-user-authentication
fix/crash-on-startup
chore/update-dependencies
docs/improve-readme
Consistent code formatting enhances readability and maintainability. Follow these guidelines:
-
Use black for automatic code formatting.
- Default configuration with
max_line_length=79
and double quotes. - Target compatibility with Python 3.11.
- Default configuration with
-
Use flake8 for linting to ensure code quality.
- Run
flake8
to catch unused variables and other potential issues. - Check for adherence to PEP 8 and coding best practices.
- Run
-
Use pre-commit-hooks for helpful pre-commit checks.
- Flags any large files added to the repository.
- Detects unresolved merge conflict markers in files.
- Detects
print()
andpdb
statements in Python code to prevent accidental commits of debug code. - Identifies and removes trailing whitespace for cleaner, more consistent formatting.
-
Use yamllint to format YAML files.
- Limits lines to a maximum of 140 characters.
- Allows at most one space inside braces and brackets.
- Disallows spaces after colons and commas.
- Disables linting and indentation checks for comments.
- Disables requiring the document start marker (
---
) at the beginning of YAML files. - Allows a maximum of two consecutive empty lines.
- Enables checks for duplicate keys in mappings (dictionaries) to prevent unintentional overwrites.
- Disables checks enforcing explicit
true
/false
values instead ofyes
/no
.
-
Use pyupgrade to upgrade Python syntax automatically.
- Enables updates for syntax supported from Python 3.7 onward.
-
Use codespell to identify and fix common spelling errors.
pre-commit run --all-files
By following this style guide, you contribute to a consistent and maintainable codebase, making it easier for everyone to collaborate and improve the project. Thank you for your contributions!