Skip to content

Add pre-commit hooks configuration#3

Open
jmanhype wants to merge 1 commit intomainfrom
jmanhype/precommit-hooks
Open

Add pre-commit hooks configuration#3
jmanhype wants to merge 1 commit intomainfrom
jmanhype/precommit-hooks

Conversation

@jmanhype
Copy link
Copy Markdown
Owner

@jmanhype jmanhype commented Oct 12, 2025

User description

Summary

  • Adds .pre-commit-config.yaml with relevant hooks for this awesome-list repository
  • Aligns with existing CI workflows (awesome-lint) and contribution guidelines

Hooks included

  • Trailing whitespace removal - per contributing.md requirement
  • End of file fixing - ensures consistent EOF newlines
  • YAML/JSON validation - catches syntax errors early
  • Markdown linting - maintains markdown quality
  • awesome-lint - matches CI workflow for consistency
  • Large file detection - prevents accidental large file commits
  • Merge conflict detection - catches unresolved conflicts
  • Line ending normalization - enforces LF line endings

Installation

pip install pre-commit
pre-commit install

Notes

  • Link checker is commented out (can be slow for pre-commit)
  • All hooks align with existing CI checks in .github/workflows/

🤖 Generated with Claude Code


PR Type

Enhancement


Description

  • Adds .pre-commit-config.yaml with 8 automated code quality hooks

  • Integrates awesome-lint to match existing CI workflow

  • Enforces markdown, YAML, and JSON validation before commits

  • Includes file hygiene checks (whitespace, line endings, large files)


Diagram Walkthrough

flowchart LR
  A["Developer commits"] --> B["Pre-commit hooks"]
  B --> C["File checks"]
  B --> D["Markdown linting"]
  B --> E["awesome-lint"]
  C --> F["Quality gates passed"]
  D --> F
  E --> F
Loading

File Walkthrough

Relevant files
Configuration changes
.pre-commit-config.yaml
Configure pre-commit hooks for automated code quality checks

.pre-commit-config.yaml

  • Configures 8 pre-commit hooks from pre-commit-hooks repository
    (v5.0.0)
  • Adds markdownlint hook with custom rule exclusions
  • Integrates local awesome-lint hook to align with CI workflow
  • Includes commented-out link checker hook for optional use
+54/-0   

Adds .pre-commit-config.yaml with hooks for:
- Trailing whitespace removal (per contributing guidelines)
- End of file fixing
- YAML/JSON validation
- Markdown linting
- awesome-lint integration (matching CI workflow)
- Large file detection
- Merge conflict checks
- Mixed line ending fixes

Helps maintain code quality and consistency before commits.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@qodo-code-review
Copy link
Copy Markdown

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
System command execution

Description: The local hook runs 'npx awesome-lint' with language 'system', which executes a system
command and may pull remote packages at commit time, potentially enabling command
execution if contributor PATH or npx resolution is compromised.
.pre-commit-config.yaml [36-44]

Referred Code
- repo: local
  hooks:
    - id: awesome-lint
      name: awesome-lint
      entry: npx awesome-lint
      language: system
      pass_filenames: false
      files: '\.md$'
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
No custom compliance provided

Follow the guide to enable custom compliance check.

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Make pre-commit configuration robust and self-contained

The suggestion recommends fixing invalid repository versions and URLs in the
pre-commit configuration. It also advises replacing language: system with
pre-commit's managed environments (like language: node) to ensure the setup is
robust and self-contained for all contributors.

Examples:

.pre-commit-config.yaml [5-7]
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
.pre-commit-config.yaml [36-43]
  - repo: local
    hooks:
      - id: awesome-lint
        name: awesome-lint
        entry: npx awesome-lint
        language: system
        pass_filenames: false
        files: '\.md$'

Solution Walkthrough:

Before:

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0 # Invalid version
    hooks:
      ...
  - repo: https://github.com/markdownlint/markdownlint # Incorrect repo for pre-commit hook
    rev: v0.13.0
    hooks:
      - id: markdownlint
        ...
  - repo: local
    hooks:
      - id: awesome-lint
        entry: npx awesome-lint
        language: system # Not self-contained, requires manual setup
        pass_filenames: false

After:

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0 # Use a valid, recent version
    hooks:
      ...
  - repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.41.0 # Use correct repo and recent version
    hooks:
      - id: markdownlint
        ...
  - repo: local
    hooks:
      - id: awesome-lint
        entry: awesome-lint
        language: node # Self-contained environment
        additional_dependencies: ['awesome-lint']
        pass_filenames: false
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies multiple critical flaws, including invalid versions and non-portable dependencies, which would render the entire pre-commit configuration unusable for many contributors.

High
Possible issue
Fix misconfigured markdownlint pre-commit hook

Fix the markdownlint hook by replacing the Ruby-based repository with a
Node.js-based one (igorshubovych/markdownlint-cli) and updating the arguments to
the correct format.

.pre-commit-config.yaml [27-33]

 # Markdown checks
-- repo: https://github.com/markdownlint/markdownlint
-  rev: v0.13.0
+- repo: https://github.com/igorshubovych/markdownlint-cli
+  rev: v0.41.0
   hooks:
     - id: markdownlint
       name: Lint Markdown files
-      args: ['--rules', '~MD013,~MD033,~MD041']
+      args: ['--disable', 'MD013', 'MD033', 'MD041']
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical misconfiguration where the markdownlint hook repository (a Ruby gem) is incompatible with the provided arguments (for a Node.js tool), which would cause the hook to fail.

High
General
Improve reproducibility of local hook

Refactor the awesome-lint hook to use language: node and additional_dependencies
instead of language: system to ensure pre-commit manages the tool's environment
for better reproducibility.

.pre-commit-config.yaml [35-43]

 # awesome-lint check (aligns with CI)
 - repo: local
   hooks:
     - id: awesome-lint
       name: awesome-lint
-      entry: npx awesome-lint
-      language: system
+      entry: awesome-lint
+      language: node
+      additional_dependencies: ['awesome-lint@5.3.0']
       pass_filenames: false
       files: '\.md$'
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion improves the robustness and reproducibility of the awesome-lint hook by having pre-commit manage the Node.js environment, which is a best practice over relying on a system-wide installation.

Medium
  • More

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant