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

Introduces pre-commit github-action #2543

Merged
merged 1 commit into from
Dec 22, 2024

Conversation

Ludy87
Copy link
Contributor

@Ludy87 Ludy87 commented Dec 22, 2024

https://github.com/Stirling-Tools/Stirling-PDF/blob/main/.pre-commit-config.yaml

Description

1. Ruff (Python Code Quality and Formatting)

  • Hooks:

    • ruff:
      • Performs static analysis for Python code.
      • Automatically fixes issues (e.g., formatting, linting) with --fix.
      • Sets the maximum line length to 127.
      • Targets Python scripts while excluding specific files like split_photos.py.
    • ruff-format:
      • Ensures consistent formatting for Python files.
  • Purpose:
    Improves Python code quality, removes potential bugs, and enforces consistent styling.


2. Codespell (Spelling Errors in Code and Documentation)

  • Hook:

    • Detects and fixes spelling errors in multiple file types (e.g., .html, .py, .md).
    • Skips unnecessary files such as .csv and .json.
    • Excludes directories like .vscode and .devcontainer.
  • Purpose:
    Avoids typos in code and documentation, reducing potential misunderstandings and improving professional appearance.


3. Gitleaks (Secrets Detection)

  • Hook:

    • Scans the repository for hardcoded sensitive information like API keys, tokens, or passwords.
  • Purpose:
    Protects the project by preventing the accidental leakage of sensitive data.


4. Shellcheck (Shell Script Analysis)

  • Hook:

    • Analyzes shell scripts (.bash, .sh, etc.) for errors, security issues, and suboptimal coding patterns.
  • Purpose:
    Enhances the quality and security of shell scripts.


5. Pre-Commit Hooks (General Code Hygiene)

  • Hooks:

    • end-of-file-fixer: Ensures that all files end with a newline.
    • trailing-whitespace: Removes unnecessary whitespace at the end of lines.
    • Exclusions: Skips files in directories like pdfjs, thirdParty, and minified files (e.g., *.min.js).
  • Purpose:
    Enforces clean and consistent file structures.


6. Local Hooks (Project-Specific Checks)

  • Custom Python Scripts:

    • check-duplicate-properties-keys:
      • Checks .properties files for duplicate keys to avoid conflicts.
    • check-html-tabs:
      • Ensures HTML, CSS, and JavaScript files do not contain tab characters, which can be replaced with spaces if needed.
  • Purpose:
    Implements custom rules tailored to the project's requirements.


Benefits

  • Automated Quality Checks: Prevents committing of poorly formatted or insecure code.
  • Consistency: Ensures team-wide adherence to coding standards.
  • Security: Detects and prevents exposure of sensitive data.
  • Customizability: Supports specific checks for project-specific needs.

Checklist

  • I have read the Contribution Guidelines
  • I have performed a self-review of my own code
  • I have attached images of the change if it is UI based
  • I have commented my code, particularly in hard-to-understand areas
  • If my code has heavily changed functionality I have updated relevant docs on Stirling-PDFs doc repo
  • My changes generate no new warnings
  • I have read the section Add New Translation Tags (for new translation tags only)

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Dec 22, 2024
@Frooodle Frooodle merged commit d6937b1 into Stirling-Tools:main Dec 22, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Github size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants