# Quick Reference: Generated Files

## Files That Are Automatically Skipped

All Dart/Flutter rules automatically skip these generated file patterns:

### Code Generation
- ✅ `.g.dart` - json_serializable, built_value
- ✅ `.gen.dart` - flutter_gen
- ✅ `.gql.dart` / `.graphql.dart` - GraphQL
- ✅ `.freezed.dart` - freezed
- ✅ `.gr.dart` - gRPC
- ✅ `.pb.dart` - Protocol Buffers
- ✅ `.pbenum.dart` - Protobuf enums
- ✅ `.pbserver.dart` - Protobuf server
- ✅ `.pbjson.dart` - Protobuf JSON
- ✅ `.mocks.dart` - Mockito
- ✅ `.config.dart` / `.iconfig.dart` - Injectable
- ✅ `.mapper.dart` - dart_mappable
- ✅ `.drift.dart` - Drift database
- ✅ `.chopper.dart` - Chopper HTTP
- ✅ `.reflectable.dart` - Reflectable

### Special Cases
- ✅ `pigeon.dart` - Platform channels
- ✅ `l10n.dart` / `_l10n.dart` - Localization

### Directory Patterns
- ✅ `__generated__/` - Any file in this folder
- ✅ `/generated/` - Any file in this folder
- ✅ `.generated.` - Files with this in name

## How to Check if a File Will Be Skipped

Use this pattern (from analyzer_service.dart):

```dart
bool isGeneratedFile(String filePath) {
  final patterns = [
    RegExp(r'\.g\.dart$'),
    RegExp(r'\.gen\.dart$'),
    // ... all other patterns
  ];
  
  final fileName = path.basename(filePath);
  final fullPath = filePath.toLowerCase();
  
  return patterns.any((p) => 
    p.hasMatch(fullPath) || p.hasMatch(fileName)
  );
}
```

## FAQ

**Q: Do I need to add generated file checks in my rule?**  
A: No! It's handled centrally in analyzer_service.dart before rules run.

**Q: What if I need to check test files?**  
A: That's fine - add `if (filePath.contains('_test.dart'))` in your rule.

**Q: Can I add a new generated file pattern?**  
A: Yes! Add it to `_generatedFilePatterns` in analyzer_service.dart.

**Q: How do I test if a pattern works?**  
A: Run `dart run test_generated_files.dart` in dart_analyzer directory.

**Q: Will this affect existing rules?**  
A: Yes, but in a good way - they'll all skip generated files automatically!

## Common Mistakes to Avoid

❌ **DON'T** add this in your rule:
```dart
if (filePath.endsWith('.g.dart')) return [];
if (filePath.endsWith('.freezed.dart')) return [];
```

✅ **DO** trust the centralized check:
```dart
// No need to check - it's done before your rule runs!
```

❌ **DON'T** check for generated files manually:
```dart
final isGenerated = filePath.contains('generated');
if (isGenerated) return [];
```

✅ **DO** add rule-specific checks only:
```dart
// Rule-specific: Allow certain patterns in test files
if (filePath.contains('_test.dart')) {
  // Different behavior for tests
}
```
