Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Vikranth3140
Copy link

This pull request addresses closes #77 by adding pre-commit hooks to automatically handle code formatting and linting for various file types in the repository. These hooks help maintain consistent code style and formatting across Python files, Jupyter Notebooks, YAML, Markdown, and text files, ensuring better code quality and minimizing errors before committing.

Changes:

  • Added a .pre-commit-config.yaml file to configure the pre-commit hooks.
  • Configured the following hooks:
    • Black: Formats Python code and Jupyter notebooks.
    • nbQA: Applies Black and Flake8 to Jupyter Notebooks (.ipynb).
    • Check YAML: Validates YAML files.
    • Trailing Whitespace, End-of-file fixer, and Check-merge-conflict: Ensures clean formatting in text files.
    • Markdownlint: Enforces style consistency in Markdown files.

Key Updates:

  1. Python Files: Black is used for automatic code formatting.
  2. Jupyter Notebooks: Black and Flake8 linting are applied using nbQA.
  3. YAML Files: Validation using the check-yaml hook.
  4. Text Files: Whitespace and end-of-file formatting fixes are applied.
  5. Markdown Files: Linting for style consistency using mdformat (replacing markdownlint).

Notes:

  • Removed the original markdownlint due to Ruby dependency issues and replaced it with a Python-based Markdown formatter (mdformat) to avoid Ruby-related setup complications.
  • Updated Python encoding to handle special characters in some files (e.g., files with emojis).
  • Modified linting rules for notebooks, and disabled nbqa-flake8 where necessary to avoid common linting errors (e.g., long lines, unused imports).

How to Test:

  1. Install pre-commit by running:
    pip install pre-commit
  2. Run the following command to install the hooks:
    pre-commit install
  3. Apply the hooks to all files:
    pre-commit run --all-files

This ensures that all files are formatted and linted according to the new configuration, improving code quality across the repository.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Thank you for your contribution! Your pull request has been submitted successfully. A maintainer will review it as soon as possible. We appreciate your support in making this project better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Pre-commit Hooks for Code Formatting and Linting
1 participant