google/mcp-security

Add GitHub status check to prevent trailing spaces in code

Open

#104 opened on Jun 25, 2025

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Python (124 forks)auto 404
enhancementgood first issue

Repository metrics

Stars
 (504 stars)
PR merge metrics
 (PR metrics pending)

Description

Description

Add a GitHub status check to automatically detect and prevent code with trailing spaces from being merged into the repository.

Motivation

Trailing spaces in code can cause issues with:

  • Git diffs showing unnecessary changes
  • Some linters and code formatters
  • Consistency across the codebase

Proposed Solution

Implement a GitHub Actions workflow that:

  1. Runs on all pull requests
  2. Checks for trailing spaces in all files
  3. Fails the status check if trailing spaces are found
  4. Provides clear feedback about which files contain trailing spaces

Implementation Options

  1. GitHub Actions with a simple script

    • Use a bash script with grep or similar tools
    • Lightweight and easy to maintain
  2. Pre-existing GitHub Actions

    • Use actions like zbeekman/EditorConfig-Action@v1
    • Or peter-evans/find-comment@v2 with custom logic
  3. Super-linter

    • Use GitHub's super-linter which includes trailing space checks
    • More comprehensive but might be overkill

Example Workflow

name: Check Trailing Spaces
on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  trailing-spaces:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Check for trailing spaces
        run: |
          if grep -r '[[:space:]]$' --include="*.py" --include="*.md" --include="*.json" --include="*.yaml" --include="*.yml" .; then
            echo "::error::Trailing spaces found in files above"
            exit 1
          else
            echo "No trailing spaces found"
          fi

Additional Considerations

  • Should we automatically fix trailing spaces or just report them?
  • Which file types should be checked?
  • Should we exclude certain directories (e.g., node_modules, .git)?

Contributor guide