Coding Style
Linter & Formatter
| Platform | Linter | Formatter | Config File |
|---|---|---|---|
| Android | detekt / ktlint | ktfmt | .editorconfig, detekt.yml |
| iOS | SwiftLint | swift-format | .swiftlint.yml |
| Flutter | flutter_lints / very_good_analysis | dart format | analysis_options.yaml |
| React Native | ESLint | Prettier | eslint.config.js (flat config), .prettierrc |
Aturan Umum
- Maksimum line length: 120 karakter (Dart: 80).
- Maksimum function length: 30 baris (guideline, bukan hard limit).
- Maksimum file length: 300 baris. Jika lebih, pertimbangkan untuk memecah.
- Indentation: 2 spaces (Dart, TS), 4 spaces (Kotlin, Swift).
- Trailing comma: Wajib untuk Dart dan Kotlin (Compose).
- Import ordering: Grouped dan sorted (stdlib → 3rd party → project).
Pre-commit Hook
Setiap project wajib memiliki pre-commit hook untuk menjalankan linter:
# .husky/pre-commit (React Native)
npx lint-staged
# lint-staged config di package.json
{
"lint-staged": {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{json,md}": ["prettier --write"]
}
}
CI Enforcement
Linter juga wajib dijalankan di CI pipeline. MR/PR yang gagal lint harus di-block dari merge.
ESLint flat config wajib
Sejak ESLint 10, .eslintrc.js/.eslintrc.json sudah tidak dibaca sama sekali — hanya eslint.config.js (flat config) yang didukung. Project lama yang masih pakai .eslintrc.* harus migrasi sebelum upgrade ESLint.