Skill

fix-trailing-newlines

Fix SA1518 StyleCop violations by removing trailing newlines from .cs, .xaml, .axaml, .csproj, .props, .targets, .editorconfig, .slnx, .sln, and .json files. Targets projects where .editorconfig has insert_final_newline = false. Use when SA1518 violations appear, trailing newline issues occur, or to enforce insert_final_newline = false across the repository.

From dotnet
Install
1
Run in your terminal
$
npx claudepluginhub atc-net/atc-agentic-toolkit --plugin dotnet
Tool Access

This skill uses the workspace's default tool permissions.

Supporting Assets
View in Repository
scripts/fix_trailing_newlines.py
Skill Content

Fix Trailing Newlines (SA1518)

What This Fixes

SA1518: File may not end with a newline character.

When .editorconfig has insert_final_newline = false, files must NOT end with trailing \r\n or \n characters. This skill scans all relevant files and strips any trailing newline bytes.

Target File Types

ExtensionDescription
.csC# source files
.xamlXAML markup files
.axamlAvalonia XAML files
.csprojC# project files
.propsMSBuild property files
.targetsMSBuild target files
.editorconfigEditor configuration files
.slnxSolution XML files
.slnSolution files
.jsonJSON configuration files

Excluded Directories

The following directories are always skipped:

  • bin - Build output
  • obj - Intermediate build output
  • .vs - Visual Studio metadata
  • .git - Git repository data
  • node_modules - Node.js dependencies

Execution Steps

Step 1: Verify .editorconfig Setting

Before running, confirm the project uses insert_final_newline = false:

grep -r "insert_final_newline" .editorconfig

If insert_final_newline = true or not set, warn the user that removing trailing newlines may conflict with their editor configuration.

Step 2: Run the Fix Script

Execute the bundled Python script to scan and fix all files:

python scripts/fix_trailing_newlines.py [directory]
  • If no directory is specified, defaults to the current working directory
  • The script reports each fixed file and provides a summary

Step 3: Review Results

The script outputs:

  • Each file that was fixed (relative path)
  • Total files scanned and fixed

Step 4: Verify Build

After fixing, run:

dotnet build

Ensure the build succeeds and SA1518 warnings are resolved.

Manual Alternative

If the Python script is unavailable, perform the fix manually:

  1. Find all files with target extensions in the repository
  2. For each file, check if it ends with \n or \r\n
  3. If it does, remove all trailing newline characters from the end
  4. Save the file with binary write to avoid editors re-adding newlines

Guidelines

  • Always check .editorconfig before running to confirm insert_final_newline = false
  • The script preserves all file content except trailing newline bytes
  • Empty files are skipped (no modification needed)
  • The fix is idempotent - running it multiple times produces the same result
Stats
Parent Repo Stars0
Parent Repo Forks1
Last CommitMar 19, 2026