Skip to content

Add Pre-commit Hooks for Code Formatting and Linting #77

@Vikranth3140

Description

@Vikranth3140

To ensure consistent code style and formatting across the entire repository, we need to implement pre-commit hooks that automatically handle formatting and linting for multiple file types. This will improve code quality, catch errors early, and maintain clean code standards.

File Types to be Covered:

  • Python files (.py)
  • Jupyter Notebooks (.ipynb)
  • YAML files (.yml)
  • Markdown files (.md)
  • Text files (.txt)

Tasks:

  1. Add a .pre-commit-config.yaml file in the root directory of the repository.
  2. Configure the following pre-commit hooks:
    • Black: For automatic code formatting for Python and Jupyter Notebooks.
    • Flake8: For linting Python files and Jupyter Notebooks.
    • nbQA: To apply Black and Flake8 formatting and linting to Jupyter Notebooks (.ipynb).
    • Check YAML: To validate the format of YAML files.
    • Markdownlint: To ensure style consistency in Markdown files.
    • Trailing Whitespace, End-of-file fixer, and Check-merge-conflict: For cleaning up text files and ensuring proper file formatting.
  3. Install and activate the pre-commit hooks with the pre-commit install command.
  4. Run pre-commit run --all-files to apply the hooks to the entire codebase.

By implementing these hooks, we can maintain consistent formatting across all relevant file types and automatically prevent common formatting issues before code is committed.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions