Skip to content

Coding Principles and Standards

Marcel Boersma edited this page Feb 14, 2024 · 2 revisions

This document outlines the coding principles and standards adopted in our repository. These standards are enforced through automated checks and fixes, facilitated by the pre-commit framework. Our goal is to maintain high-quality, readable, and consistent code across the project.

Automated Code Quality Checks

We use pre-commit to automate code quality checks and fixes. This ensures that all contributions adhere to our coding standards before merging.

Enforced Hooks

Below are the hooks configured in our .pre-commit-config.yaml, each serving a specific purpose in maintaining our codebase's integrity:

Code Formatting and Style

  • YAPF (Yet Another Python Formatter): Formats Python code to conform to the PEP 8 style guide.
  • isort: Sorts Python imports alphabetically, and automatically separated into sections and by type.
  • Ruff: Provides rapid formatting adjustments, enforcing a consistent code style.

Linting

  • Flake8: Checks against the PEP 8 guidelines, catching coding errors, and enforcing a clean codebase.
  • yamllint: Lints YAML files, ensuring their syntax and structure follow best practices.

Utility Hooks

  • End-of-File Fixer: Ensures that files end with a newline, a common POSIX standard.
  • Mixed Line Ending: Normalizes line endings to LF, preventing cross-platform issues.
  • Remove Trailing Whitespaces: Cleans up unnecessary spaces at the end of lines.
  • Check toml/yaml: Validates the syntax of TOML and YAML files, respectively.

Import and Dependency Management

  • Sort imports: Organizes imports in a consistent manner across files, improving readability.

Markdown Formatting

  • mdformat: Formats Markdown files to ensure they are readable and conform to the specified style guidelines.

Exclusions

Certain files and directories may be excluded from checks when appropriate, e.g., third-party YAML configurations specific to our dependencies.

Commit Standards

  • No Commits to Master Branch: Direct commits to the master branch are blocked to encourage review and collaboration.

Conclusion

Adhering to these principles and standards facilitates a robust, maintainable, and high-quality codebase. Contributors are encouraged to set up pre-commit hooks locally to ensure their contributions are compliant before submission.