# CSharpier Configuration

## Configuration File

CSharpier uses `.csharpierrc` (or `.csharpierrc.json`, `.csharpierrc.yaml`) in the repository root.

### JSON Format (.csharpierrc or .csharpierrc.json)

```json
{
  "printWidth": 100,
  "useTabs": false,
  "tabWidth": 4,
  "endOfLine": "auto"
}
```

### YAML Format (.csharpierrc.yaml)

```yaml
printWidth: 100
useTabs: false
tabWidth: 4
endOfLine: auto
```

## Configuration Options

### printWidth

Maximum line width before wrapping.

- **Type**: integer
- **Default**: 100
- **Range**: 1-1000

```json
{
  "printWidth": 120
}
```

### useTabs

Use tabs instead of spaces for indentation.

- **Type**: boolean
- **Default**: false

```json
{
  "useTabs": true
}
```

### tabWidth

Number of spaces per indentation level (when `useTabs` is false).

- **Type**: integer
- **Default**: 4
- **Range**: 1-1000

```json
{
  "tabWidth": 2
}
```

### endOfLine

Line ending style.

- **Type**: string
- **Default**: "auto"
- **Values**: "auto", "lf", "crlf"

```json
{
  "endOfLine": "lf"
}
```

| Value | Description |
|-------|-------------|
| auto | Use existing line endings (mixed files use first line's ending) |
| lf | Unix-style line endings (`\n`) |
| crlf | Windows-style line endings (`\r\n`) |

## Ignore File

Create `.csharpierignore` in the repository root to exclude files from formatting.

### Syntax

Uses gitignore-style patterns:

```gitignore
# Ignore generated files
**/Generated/**
**/*.generated.cs

# Ignore specific directories
**/obj/
**/bin/
**/Migrations/

# Ignore specific files
src/Legacy/OldCode.cs

# Ignore test fixtures
tests/Fixtures/**/*.cs
```

### Default Exclusions

CSharpier automatically excludes:

- Files in `obj/` and `bin/` directories
- Files matching `*.generated.cs` pattern
- Files with `<auto-generated>` comment header

## EditorConfig Integration

CSharpier respects `.editorconfig` for some settings:

```ini
[*.cs]
indent_style = space
indent_size = 4
end_of_line = lf
max_line_length = 100
```

Priority order:

1. `.csharpierrc` settings (highest)
2. `.editorconfig` settings
3. CSharpier defaults (lowest)

## Preprocessor Directives

CSharpier handles preprocessor directives but may format them differently than expected. Use `.csharpierignore` for files with complex preprocessor logic that must not change.

## Example Repository Setup

```text
repo/
├── .csharpierrc
├── .csharpierignore
├── .editorconfig
├── .config/
│   └── dotnet-tools.json
└── src/
    └── ...
```

### Minimal .csharpierrc

```json
{
  "printWidth": 100
}
```

### Minimal .csharpierignore

```gitignore
**/Migrations/
**/Generated/
```

## Troubleshooting

### Formatting Conflicts with dotnet format

If using both tools, ensure they do not conflict:

1. Disable whitespace/formatting rules in `.editorconfig` for `dotnet format`
2. Let CSharpier own all formatting decisions
3. Document ownership in `AGENTS.md`

### Cache Issues

Clear the CSharpier cache if formatting seems inconsistent:

```bash
# Disable cache for single run
dotnet csharpier --no-cache .

# Cache location (for manual clearing)
# Windows: %LOCALAPPDATA%/CSharpier
# macOS/Linux: ~/.cache/CSharpier
```
