AI-Driven Code Formatting for Enhanced Readability

Utilize AI tools to automatically format code, improving readability and consistency across projects.

0 likes
12 views

Rule Content

---
name: AI-Driven Code Formatting for Enhanced Readability
version: "1.0"
category: Code Formatting
description: Utilize AI tools to automatically format code, improving readability and consistency across projects.
---

## General Formatting Guidelines

- **Indentation**: Use 2 spaces per indentation level.
- **Line Length**: Limit lines to a maximum of 80 characters.
- **Trailing Whitespace**: Remove any trailing whitespace at the end of lines.
- **Encoding**: Ensure all files are encoded in UTF-8.

## Language-Specific Formatting

### Python

- **Style Guide**: Adhere to PEP 8 standards.
- **Imports**: Organize imports into three sections: standard library, third-party, and local imports.
- **Docstrings**: Use triple double-quoted strings for module, class, and function docstrings.

### JavaScript

- **Style Guide**: Follow the Airbnb JavaScript Style Guide.
- **Semicolons**: Always use semicolons to terminate statements.
- **Quotes**: Use single quotes for strings, except to avoid escaping.

### HTML/CSS

- **HTML**: Use lowercase for element names and attribute names.
- **CSS**: Follow the BEM (Block Element Modifier) naming convention.

## AI Integration

- **Auto-Formatting**: Configure AI tools to automatically apply the above formatting rules upon saving files.
- **Code Reviews**: Utilize AI to suggest formatting improvements during code reviews.
- **Consistency Checks**: Implement AI-driven checks to ensure consistent formatting across the codebase.

## Documentation

- **Comments**: Write comments in English, providing clear explanations for complex code sections.
- **README**: Maintain an up-to-date README.md with project setup and contribution guidelines.

## Best Practices

- **Modular Design**: Break functionality into self-contained, reusable components.
- **Testing**: Write unit tests for all new components and utilities, aiming for at least 80% test coverage.
- **Security**: Implement security best practices and avoid hardcoding sensitive information.

## Implementation Notes

- **Tooling**: Integrate AI-powered code formatters compatible with Cursor IDE to enforce these rules.
- **Configuration**: Ensure that the AI tools are configured to respect the project's specific formatting guidelines.
- **Continuous Integration**: Set up CI pipelines to automatically check for formatting compliance.