Skip to content

Commit 8d2b4d6

Browse files
authored
chore: ignore auto-generated files and update documentation (#417)
- Add *.g.dart and *.mocks.dart to .gitignore - Remove previously tracked generated files from repository - Update README.md with mandatory setup instructions - Enhance CONTRIBUTING.md with generated files workflow - Update CLAUDE.md with complete CI/CD documentation
1 parent bfe923b commit 8d2b4d6

File tree

8 files changed

+146
-3699
lines changed

8 files changed

+146
-3699
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
**/.flutter-plugins-dependencies
88
**/.flutter-versions
99

10+
# Generated files (auto-generated by build_runner and other code generators)
11+
# These files are regenerated automatically in CI and should not be committed
12+
*.g.dart
13+
*.mocks.dart
14+
1015
# IntelliJ related
1116
.idea/
1217
*.iml

CLAUDE.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ When orders are canceled, Mostro sends `Action.canceled` gift wrap:
188188
- Integration tests in `integration_test/`
189189
- Mocks generated using Mockito in `test/mocks.dart`
190190

191-
### Mock Files Guidelines
191+
### Mock Files Guidelines
192192
- **Generated file**: `test/mocks.mocks.dart` is auto-generated by Mockito
193193
- **File-level ignores**: Contains comprehensive ignore directives at file level
194194
- **Regeneration**: Use `dart run build_runner build -d` to update mocks after changes
195195
- **No manual editing**: Never manually modify generated mock files
196+
- **Not in git**: All `*.mocks.dart` files are in `.gitignore` and should NOT be committed
196197

197198
## Development Guidelines
198199

@@ -365,6 +366,10 @@ For complete technical documentation, see `RELAY_SYNC_IMPLEMENTATION.md`.
365366
- **Commit messages**: Descriptive messages following conventional commits
366367
- **No Claude references**: Don't include Claude/AI references in commit messages
367368
- **Code review**: All changes should pass `flutter analyze` before commit
369+
- **Generated files**: NEVER commit `*.g.dart` or `*.mocks.dart` files - they are in `.gitignore`
370+
- These files are automatically regenerated by CI/CD workflows
371+
- Only commit source files that you manually write/edit
372+
- If you see generated files in `git status`, do NOT stage them
368373

369374
## Project Context & Recent Work
370375

@@ -501,22 +506,47 @@ For complete technical documentation, see `RELAY_SYNC_IMPLEMENTATION.md`.
501506
- `RELAY_SYNC_IMPLEMENTATION.md` - Complete technical documentation
502507

503508
### Generated Files (Don't Edit Manually)
504-
- `lib/generated/` - Generated localization files
505-
- `*.g.dart` - Generated Riverpod and other code
506-
- `*.mocks.dart` - Generated Mockito mock files (especially `test/mocks.mocks.dart`)
509+
- `lib/generated/` - Generated localization files (in `.gitignore`)
510+
- `*.g.dart` - Generated Riverpod and other code (in `.gitignore`)
511+
- `*.mocks.dart` - Generated Mockito mock files (in `.gitignore`)
507512
- Platform-specific generated files
508513

509514
### Generated Files Best Practices
510515
- **NEVER manually edit** generated files (`.g.dart`, `.mocks.dart`, `lib/generated/`)
516+
- **NEVER commit** generated files - they are in `.gitignore` and auto-generated by CI
511517
- **NEVER add individual ignore comments** to generated files (e.g., `// ignore: must_be_immutable`)
512518
- **DO NOT modify** `test/mocks.mocks.dart` - it already has file-level ignores
513519
- **If analyzer issues exist**: Regenerate files instead of adding ignores
514520
- **Mock files specifically**: Have file-level `// ignore_for_file: must_be_immutable` - don't add more
515-
- **Regeneration commands**:
521+
- **Regeneration commands**:
516522
- Riverpod: `dart run build_runner build -d`
517523
- Mocks: `dart run build_runner build -d`
518524
- Localization: `flutter gen-l10n`
519525

526+
### Generated Files Workflow
527+
```
528+
Local Development:
529+
1. Clone repo → flutter pub get
530+
2. Generate files → dart run build_runner build -d
531+
3. Develop → Edit source files only
532+
4. Re-generate if needed → dart run build_runner build -d
533+
5. Commit → git add (source files only, NO *.g.dart or *.mocks.dart)
534+
535+
CI/CD Workflow:
536+
1. Pull request created
537+
2. CI runs → dart run build_runner build -d (auto-generates)
538+
3. CI runs → flutter analyze
539+
4. CI runs → flutter test
540+
5. All generated files exist for CI, but NOT in git history
541+
```
542+
543+
**Why This Approach?**
544+
- ✅ Clean git diffs - only see actual code changes in PRs
545+
- ✅ No merge conflicts from generated files
546+
- ✅ Prevents accidental manual edits to generated code
547+
- ✅ CI ensures files can always be regenerated correctly
548+
- ✅ Smaller repository size
549+
520550
## Notes for Future Development
521551

522552
- Always maintain zero Flutter analyze issues
@@ -529,10 +559,12 @@ For complete technical documentation, see `RELAY_SYNC_IMPLEMENTATION.md`.
529559

530560
### Generated Files - CRITICAL
531561
- **NEVER** manually edit `test/mocks.mocks.dart` or any `*.g.dart` files
562+
- **NEVER** commit `*.g.dart` or `*.mocks.dart` files - they are in `.gitignore`
532563
- **NEVER** add `// ignore: must_be_immutable` to individual classes in generated files
533564
- **MockSharedPreferencesAsync** already has file-level ignore - don't add more
534565
- **duplicate_ignore warnings** are caused by adding individual ignores to files with file-level ignores
535566
- **Solution**: Always regenerate files instead of adding ignore comments
567+
- **Git workflow**: Generated files exist locally for development, but are NOT tracked by git
536568

537569
---
538570

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,21 @@ This is a fully-featured mobile application that enables secure, private, and de
8282
flutter pub get
8383
```
8484

85-
3. Generate localization and other required files:
85+
3. **Generate required files (REQUIRED STEP):**
8686

8787
```bash
8888
dart run build_runner build -d
8989
```
9090

91-
> **Note:**
92-
> These commands generate files needed by `flutter_intl` and any other code generators. You must run them after installing dependencies and whenever you update localization files or code generation sources. If you skip this step, you may encounter missing file errors when running the app.
91+
> **⚠️ IMPORTANT:**
92+
> This step is **mandatory** and must be run after cloning the repository. It generates code files (`*.g.dart`, `*.mocks.dart`) required for the app to compile and run. These generated files are not committed to the repository and are automatically recreated in CI/CD pipelines.
93+
>
94+
> You will need to run this command again whenever you:
95+
> - Update localization files (`lib/l10n/*.arb`)
96+
> - Modify files that use code generation (Riverpod providers, JSON serialization, etc.)
97+
> - Pull changes that affect generated code
98+
>
99+
> If you see compilation errors about missing files or imports, run this command again.
93100
94101
## Running the App
95102

docs/CONTRIBUTING.md

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,25 @@ Mostro Mobile is a Flutter app designed with modularity and maintainability in m
8181
```sh
8282
flutter pub get
8383
```
84-
3. **Run the app:**
84+
3. **Generate required files (CRITICAL STEP):**
85+
```sh
86+
dart run build_runner build -d
87+
```
88+
This generates code files (`*.g.dart`, `*.mocks.dart`) required for the app to compile. You must run this after cloning and whenever you modify files that use code generation (Riverpod providers, JSON serialization, localization files, etc.).
89+
90+
4. **Run the app:**
8591
```sh
8692
flutter run
8793
```
88-
4. **Configure environment:**
94+
5. **Configure environment:**
8995
- Localization: Run `flutter gen-l10n` if you add new strings.
9096
- Platform-specific setup: See `README.md` for details.
9197

92-
5. **Testing:**
98+
6. **Testing:**
9399
- Unit tests: `flutter test`
94100
- Integration tests: `flutter test integration_test/`
95101

96-
6. **Linting & Formatting:**
102+
7. **Linting & Formatting:**
97103
- Check code style: `flutter analyze`
98104
- Format code: `flutter format .`
99105

@@ -111,6 +117,90 @@ Mostro Mobile is a Flutter app designed with modularity and maintainability in m
111117

112118
---
113119

120+
## Generated Files & Git Workflow
121+
122+
### What Are Generated Files?
123+
124+
This project uses code generation for several purposes:
125+
- **Riverpod providers** (`*.g.dart`)
126+
- **JSON serialization** (`*.g.dart`)
127+
- **Mock classes for testing** (`*.mocks.dart`)
128+
- **Localization** (`lib/generated/`)
129+
130+
These files are automatically created by running:
131+
```sh
132+
dart run build_runner build -d
133+
```
134+
135+
### Important: DO NOT Commit Generated Files
136+
137+
**Generated files (`*.g.dart`, `*.mocks.dart`) are in `.gitignore` and should NEVER be committed to the repository.**
138+
139+
#### Why?
140+
-**Clean PRs**: Only source code changes appear in pull requests
141+
-**No merge conflicts**: Generated files won't cause conflicts between branches
142+
-**CI regenerates them**: GitHub Actions automatically regenerate these files during builds
143+
-**Prevents errors**: No one can accidentally modify generated code manually
144+
145+
### Development Workflow
146+
147+
```
148+
1. Clone repo
149+
└─> flutter pub get
150+
└─> dart run build_runner build -d ← Generate files locally
151+
152+
2. Develop your feature
153+
└─> Make code changes
154+
└─> If you modify providers/models, re-run build_runner
155+
156+
3. Before committing
157+
└─> flutter analyze ← Must pass with zero issues
158+
└─> flutter test ← All tests must pass
159+
└─> git add ← Add ONLY source files, NOT *.g.dart or *.mocks.dart
160+
161+
4. Create PR
162+
└─> CI automatically regenerates all files
163+
└─> CI runs analyze and tests
164+
└─> Your PR only shows actual code changes
165+
```
166+
167+
### What If I See Generated Files in My Git Status?
168+
169+
If you see modified `*.g.dart` or `*.mocks.dart` files when running `git status`, **do NOT commit them**. They are already in `.gitignore` and should be ignored automatically. If they appear as modified, it means they were tracked before the `.gitignore` update.
170+
171+
Simply don't stage them:
172+
```sh
173+
git status # See what changed
174+
git add lib/... # Add only your actual source files
175+
git commit # Generated files won't be included
176+
```
177+
178+
### Common Scenarios
179+
180+
**Scenario 1: After pulling changes**
181+
```sh
182+
git pull
183+
dart run build_runner build -d # Regenerate locally
184+
flutter run # App works
185+
```
186+
187+
**Scenario 2: Modified a model or provider**
188+
```sh
189+
# Edit lib/features/settings/settings.dart
190+
dart run build_runner build -d # Regenerate affected files
191+
flutter run # Test changes
192+
git add lib/features/settings/settings.dart # Add ONLY source file
193+
git commit -m "feat: add new setting"
194+
```
195+
196+
**Scenario 3: Compilation errors about missing files**
197+
```sh
198+
# Error: "File not found: '*.g.dart'"
199+
dart run build_runner build -d # Regenerate
200+
```
201+
202+
---
203+
114204
## Contact & Further Resources
115205

116206
- **Main repo:** [https://github.com/MostroP2P/mobile](https://github.com/MostroP2P/mobile)

lib/features/order/providers/order_notifier_provider.g.dart

Lines changed: 0 additions & 26 deletions
This file was deleted.

lib/services/event_bus.g.dart

Lines changed: 0 additions & 26 deletions
This file was deleted.

lib/shared/providers/mostro_service_provider.g.dart

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)