Code Formatting Strategies for Legacy Codebases

Develop methods to apply modern code formatting standards to existing legacy codebases.

0 likes
9 views

Rule Content

# Code Formatting Strategies for Legacy Codebases

## Description

Develop methods to apply modern code formatting standards to existing legacy codebases.

## Category

Code Formatting

## Category Context

Ensures consistent style in code by handling indentation, spacing, line breaks, and overall structure to keep code clean and readable.

## Rules

### 1. Indentation

- **Standardize Indentation**:
  - Use 4 spaces per indentation level.
  - Replace all tab characters with spaces.

### 2. Line Length

- **Limit Line Length**:
  - Restrict lines to a maximum of 80 characters.
  - Break lines exceeding this limit at logical boundaries.

### 3. Spacing

- **Consistent Spacing**:
  - Ensure a single space after commas, semicolons, and around operators.
  - Remove trailing whitespace at the end of lines.

### 4. Braces and Parentheses

- **Brace Placement**:
  - Place opening braces on the same line as the statement.
  - Ensure closing braces align with the start of the statement.

### 5. Comments

- **Comment Formatting**:
  - Use a single space after the comment delimiter.
  - Ensure comments are complete sentences with proper punctuation.

### 6. File Encoding

- **Set File Encoding**:
  - Ensure all files are encoded in UTF-8 without a byte order mark (BOM).

### 7. End-of-File

- **Ensure Newline at EOF**:
  - Add a single newline character at the end of each file.

## Implementation

To enforce these formatting standards in Cursor IDE, integrate the following configuration into your project's `.cursorrules` file:

# Code Formatting Strategies for Legacy Codebases

## Indentation
- Use 4 spaces per indentation level.
- Replace all tab characters with spaces.

## Line Length
- Restrict lines to a maximum of 80 characters.
- Break lines exceeding this limit at logical boundaries.

## Spacing
- Ensure a single space after commas, semicolons, and around operators.
- Remove trailing whitespace at the end of lines.

## Braces and Parentheses
- Place opening braces on the same line as the statement.
- Ensure closing braces align with the start of the statement.

## Comments
- Use a single space after the comment delimiter.
- Ensure comments are complete sentences with proper punctuation.

## File Encoding
- Ensure all files are encoded in UTF-8 without a byte order mark (BOM).

## End-of-File
- Add a single newline character at the end of each file.
By adhering to these rules, you can systematically apply modern code formatting standards to legacy codebases, enhancing readability and maintainability.