Get the FREE Ultimate OpenClaw Setup Guide →

line-ending-normalizer

Scanned
npx machina-cli add skill a5c-ai/babysitter/line-ending-normalizer --openclaw
Files (1)
SKILL.md
1.3 KB

Line Ending Normalizer

Normalize line endings for cross-platform compatibility.

Capabilities

  • Detect line ending style
  • Convert between CRLF and LF
  • Configure git line ending settings
  • Handle mixed line endings
  • Set up .gitattributes

Generated Patterns

export type LineEnding = 'lf' | 'crlf' | 'mixed';

export function detectLineEnding(content: string): LineEnding {
  const crlf = (content.match(/\r\n/g) || []).length;
  const lf = (content.match(/(?<!\r)\n/g) || []).length;
  if (crlf > 0 && lf > 0) return 'mixed';
  if (crlf > 0) return 'crlf';
  return 'lf';
}

export function normalizeLineEndings(content: string, target: 'lf' | 'crlf' = 'lf'): string {
  const normalized = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
  return target === 'crlf' ? normalized.replace(/\n/g, '\r\n') : normalized;
}

// .gitattributes content
export const gitattributes = `
* text=auto eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf
*.sh text eol=lf
`;

Target Processes

  • cross-platform-cli-compatibility
  • configuration-management-system
  • shell-script-development

Source

git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/specializations/cli-mcp-development/skills/line-ending-normalizer/SKILL.mdView on GitHub

Overview

Line Ending Normalizer detects and standardizes line endings to LF, CRLF, or mixed, helping teams work consistently across Windows, macOS, and Linux. It also provides a ready-made .gitattributes snippet to enforce desired endings and ease cross-platform git workflows.

How This Skill Works

It exposes TypeScript utilities to detect and normalize line endings: detectLineEnding(content) returns 'lf', 'crlf', or 'mixed', and normalizeLineEndings(content, target) converts to the chosen style. It also includes a sample gitattributes block to configure Git's end-of-line handling.

When to Use It

  • Sync code across Windows, macOS, and Linux machines to avoid dangling CRLF/LF issues.
  • Prepare a repo for cross-platform CI by enforcing consistent line endings.
  • Migrate legacy projects with mixed endings to a single standard.
  • Configure Git to respect line endings via the provided .gitattributes.
  • Set up end-of-line rules during onboarding of new contributors.

Quick Start

  1. Step 1: Run detectLineEnding on a sample file to determine current endings.
  2. Step 2: Run normalizeLineEndings(fileContent, 'lf' or 'crlf') to convert.
  3. Step 3: Add or update the .gitattributes block and commit with a descriptive message.

Best Practices

  • Detect the current ending style before converting.
  • Choose a single target ending ('lf' or 'crlf') and stick with it.
  • Apply normalization after major edits and before committing.
  • Commit the updated .gitattributes with a clear message.
  • Test in a small sandbox repo before sweeping changes across a large project.

Example Use Cases

  • Enforce LF endings in a Linux-based project.
  • Convert Windows scripts to LF for CI pipelines.
  • Use a .gitattributes snippet to standardize a polyglot repo.
  • Align Windows devs with core.autocrlf and Git attributes.
  • Clean up mixed endings after massive codebase import.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers