Skip to content

Conversation

Copy link

Copilot AI commented Nov 14, 2025

Adds automated trailing whitespace detection for pull requests to maintain code consistency.

Implementation

  • Workflow: .github/workflows/trailing-whitespace-check.yml
    • Triggers on PR open/sync/reopen events
    • Scans only changed files (not entire codebase)
    • Covers text files: .cs, .csproj, .sln, .ts, .html, .css, .scss
    • Excludes: build artifacts (bin/, obj/, artifacts/), dependencies (node_modules/, packages/), hidden dirs, IDE files
    • Reports line numbers with trailing whitespace
    • Fails check if issues found

Security

  • Minimal permissions: contents: read
  • Passes CodeQL analysis

Example Output

❌ Trailing whitespace found in: src/Example.cs
42:         return value;  
55:     }  

❌ Found trailing whitespace in 1 file(s).
Original prompt

Please create a GitHub Action which checks new code for trailing whitespace on PRs


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 14, 2025 07:33
Co-authored-by: softworkz <4985349+softworkz@users.noreply.github.com>
Co-authored-by: softworkz <4985349+softworkz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GitHub Action to check for trailing whitespace on PRs Add GitHub Action to check trailing whitespace on PRs Nov 14, 2025
Copilot AI requested a review from softworkz November 14, 2025 07:38
Copy link
Owner

@softworkz softworkz left a comment

Choose a reason for hiding this comment

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

@copilot

Please add a few changes in files which create trailing whitespace

Co-authored-by: softworkz <4985349+softworkz@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 14, 2025

@copilot

Please add a few changes in files which create trailing whitespace

Added two demo files with trailing whitespace in commit 6f4e1f0:

  • src/ElectronNET.CLI/TrailingWhitespaceDemo.cs (C# file with trailing spaces)
  • src/ElectronNET.WebApp/test-trailing-whitespace.html (HTML file with trailing spaces)

These files will trigger the workflow check on this PR, demonstrating how it detects trailing whitespace.

@softworkz
Copy link
Owner

@copilot - Great! Now remove the extra files so that we can merge

Co-authored-by: softworkz <4985349+softworkz@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 14, 2025

@copilot - Great! Now remove the extra files so that we can merge

Removed the demo files in commit 5d5bda0. The PR now only contains the workflow file and is ready for merge.

@softworkz softworkz marked this pull request as ready for review November 14, 2025 08:35
Copilot AI review requested due to automatic review settings November 14, 2025 08:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds automated trailing whitespace detection for pull requests to maintain code consistency. The workflow checks only changed files against trailing whitespace issues and reports specific line numbers where issues are found.

Key Changes:

  • Implements a GitHub Actions workflow that triggers on PR events (open, sync, reopen)
  • Checks text files (.cs, .csproj, .sln, .ts, .html, .css, .scss) for trailing whitespace
  • Excludes build artifacts and dependencies from checks
  • Provides detailed output with line numbers and fails the check if issues are found

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +64 to +65
if [ $(grep -c '[[:space:]]$' "$file") -gt 10 ]; then
echo " ... and $(($(grep -c '[[:space:]]$' "$file") - 10)) more lines"
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

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

The head -10 command limits the display to 10 lines but doesn't affect the count in line 64. This means if there are exactly 10 lines with trailing whitespace, line 64 will calculate (10 - 10) = 0 and display "... and 0 more lines", which is confusing.

Consider changing the condition to check if the count is greater than 10:

if [ $(grep -c '[[:space:]]$' "$file") -gt 10 ]; then
  EXTRA=$(($(grep -c '[[:space:]]$' "$file") - 10))
  echo "   ... and $EXTRA more lines"
fi

Or simplify by checking if EXTRA is greater than 0.

Suggested change
if [ $(grep -c '[[:space:]]$' "$file") -gt 10 ]; then
echo " ... and $(($(grep -c '[[:space:]]$' "$file") - 10)) more lines"
EXTRA=$(($(grep -c '[[:space:]]$' "$file") - 10))
if [ "$EXTRA" -gt 0 ]; then
echo " ... and $EXTRA more lines"

Copilot uses AI. Check for mistakes.
Comment on lines +62 to +65
echo "❌ Trailing whitespace found in: $file"
grep -n '[[:space:]]$' "$file" | head -10
if [ $(grep -c '[[:space:]]$' "$file") -gt 10 ]; then
echo " ... and $(($(grep -c '[[:space:]]$' "$file") - 10)) more lines"
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

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

The grep command on line 64 is executed multiple times within the same if block, which is inefficient. Consider storing the count in a variable first:

TRAILING_COUNT=$(grep -c '[[:space:]]$' "$file")
echo "❌ Trailing whitespace found in: $file"
grep -n '[[:space:]]$' "$file" | head -10
if [ "$TRAILING_COUNT" -gt 10 ]; then
  echo "   ... and $(($TRAILING_COUNT - 10)) more lines"
fi

This avoids running grep multiple times on the same file.

Suggested change
echo "❌ Trailing whitespace found in: $file"
grep -n '[[:space:]]$' "$file" | head -10
if [ $(grep -c '[[:space:]]$' "$file") -gt 10 ]; then
echo " ... and $(($(grep -c '[[:space:]]$' "$file") - 10)) more lines"
TRAILING_COUNT=$(grep -c '[[:space:]]$' "$file")
echo "❌ Trailing whitespace found in: $file"
grep -n '[[:space:]]$' "$file" | head -10
if [ "$TRAILING_COUNT" -gt 10 ]; then
echo " ... and $(($TRAILING_COUNT - 10)) more lines"

Copilot uses AI. Check for mistakes.
@softworkz softworkz closed this Nov 15, 2025
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.

2 participants