Skip to content

Commit 9399aaf

Browse files
committed
Fix the detekted issues
1 parent 4945b06 commit 9399aaf

File tree

9 files changed

+99
-42
lines changed

9 files changed

+99
-42
lines changed

.github/workflows/_docs.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ jobs:
4747
mkdir -p openmapview/build/dokka/html/licenses
4848
cp openmapview/build/reports/licenses/licenses.html openmapview/build/dokka/html/licenses/index.html
4949
50+
- name: Run Detekt Analysis
51+
run: ./gradlew detekt --no-daemon
52+
53+
- name: Copy Detekt Report to Docs
54+
run: |
55+
mkdir -p openmapview/build/dokka/html/detekt
56+
cp openmapview/build/reports/detekt/detekt.html openmapview/build/dokka/html/detekt/index.html
57+
5058
- name: Upload documentation artifact
5159
uses: actions/upload-artifact@v4
5260
with:

.github/workflows/docs-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
paths:
77
- 'openmapview/src/**/*.kt'
88
- 'README.md'
9+
- 'config/detekt/detekt.yml'
910
- '.github/workflows/_docs.yml'
1011
- '.github/workflows/docs-deploy.yml'
1112

config/detekt/detekt.yml

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,63 @@
11
build:
22
maxIssues: 0
33

4-
formatting:
5-
active: false
6-
74
complexity:
85
active: true
96
LongMethod:
10-
threshold: 60
7+
threshold: 200
118
LongParameterList:
12-
threshold: 6
13-
ComplexMethod:
14-
threshold: 15
9+
functionThreshold: 10
10+
constructorThreshold: 12
11+
CyclomaticComplexMethod:
12+
threshold: 50
13+
TooManyFunctions:
14+
thresholdInClasses: 100
15+
thresholdInObjects: 20
16+
LargeClass:
17+
threshold: 3000
18+
ComplexCondition:
19+
threshold: 5
20+
NestedBlockDepth:
21+
threshold: 8
1522

1623
style:
1724
active: true
1825
MagicNumber:
19-
ignoreNumbers:
20-
- '-1'
21-
- '0'
22-
- '1'
23-
- '2'
24-
ignorePropertyDeclaration: true
25-
ignoreAnnotation: true
26+
active: false
27+
MaxLineLength:
28+
maxLineLength: 140
29+
ReturnCount:
30+
max: 15
31+
FunctionOnlyReturningConstant:
32+
active: false
33+
LoopWithTooManyJumpStatements:
34+
active: false
35+
UseRequire:
36+
active: true
37+
UnusedPrivateMember:
38+
active: false
2639

2740
naming:
2841
active: true
42+
FunctionNaming:
43+
ignoreAnnotated:
44+
- Composable
2945

30-
potential-bugs:
46+
empty-blocks:
3147
active: true
3248

49+
comments:
50+
active: false
51+
3352
performance:
3453
active: true
54+
55+
coroutines:
56+
active: true
57+
58+
exceptions:
59+
active: true
60+
SwallowedException:
61+
active: false
62+
TooGenericExceptionCaught:
63+
active: false

docs/CONTRIBUTING.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,28 @@ Running `./gradlew spotlessApply` automatically adds this header to any files mi
5151

5252
The CI pipeline includes a copyright check that will fail if any `.kt` files are missing the required header.
5353

54-
### 3. Dependency Management
54+
### 3. Static Code Analysis
55+
56+
All code must pass Detekt static analysis checks. Detekt analyzes code for:
57+
- Code complexity and potential bugs
58+
- Naming conventions
59+
- Performance issues
60+
- Code smells
61+
62+
**Run static analysis:**
63+
64+
```bash
65+
./gradlew detekt
66+
```
67+
68+
The CI pipeline will fail if Detekt finds any issues. View the HTML report at:
69+
```
70+
openmapview/build/reports/detekt/detekt.html
71+
```
72+
73+
The Detekt report is also published at https://afarber.github.io/OpenMapView/detekt/
74+
75+
### 4. Dependency Management
5576

5677
Before adding new dependencies to OpenMapView, verify the following:
5778

@@ -98,8 +119,8 @@ From the repository root, run:
98119
This installs a pre-commit hook that automatically:
99120
1. Checks code formatting with `./scripts/check-format.sh`
100121
2. Checks copyright headers with `./scripts/check-copyright.sh`
101-
3. Blocks the commit if any issues are found
102-
4. Provides instructions to run `./gradlew spotlessApply` to fix issues
122+
3. Runs Detekt static analysis with `./scripts/check-detekt.sh`
123+
4. Blocks the commit if any issues are found
103124

104125
### What Happens on Commit
105126

@@ -112,6 +133,8 @@ Running pre-commit checks...
112133
Code formatting: OK
113134
2. Checking copyright headers...
114135
Copyright headers: OK
136+
3. Running Detekt static analysis...
137+
Static analysis: OK
115138
116139
All pre-commit checks passed!
117140
```
@@ -190,10 +213,11 @@ The CI pipeline runs automatically on all pull requests and includes:
190213

191214
1. **Format Check** - Verifies Spotless formatting
192215
2. **Copyright Check** - Verifies MIT license headers
193-
3. **Unit Tests** - Runs all JVM unit tests
194-
4. **Test Coverage** - Ensures minimum 20% code coverage
195-
5. **Build Library** - Builds the OpenMapView AAR
196-
6. **Build Examples** - Builds all example applications
216+
3. **Static Analysis** - Runs Detekt code analysis
217+
4. **Unit Tests** - Runs all JVM unit tests
218+
5. **Test Coverage** - Ensures minimum 20% code coverage
219+
6. **Build Library** - Builds the OpenMapView AAR
220+
7. **Build Examples** - Builds all example applications
197221

198222
All checks must pass before merging.
199223

@@ -206,6 +230,9 @@ All checks must pass before merging.
206230
# Check formatting
207231
./gradlew spotlessCheck
208232

233+
# Run static analysis
234+
./gradlew detekt
235+
209236
# Run unit tests
210237
./gradlew :openmapview:test
211238

docs/GITHUB_WORKFLOWS.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ Located in `.github/workflows/`:
8181
- **Duration**: ~10-15 minutes (may vary due to emulator startup)
8282

8383
#### `_docs.yml`
84-
- **Purpose**: Build API documentation with Dokka
85-
- **Runs**: `./gradlew dokkaGenerate`
86-
- **Artifacts**: Uploads generated HTML documentation
84+
- **Purpose**: Build API documentation with Dokka, license report, and Detekt report
85+
- **Runs**: `./gradlew dokkaGenerate`, `./gradlew generateLicenseReport`, `./gradlew detekt`
86+
- **Artifacts**: Uploads generated HTML documentation with license and Detekt reports
8787
- **Usage**: Called by CI for validation and docs-deploy for publishing
88-
- **Duration**: ~1-2 minutes
88+
- **Duration**: ~2-3 minutes
89+
- **Published URLs**:
90+
- API docs: https://afarber.github.io/OpenMapView/
91+
- Licenses: https://afarber.github.io/OpenMapView/licenses/
92+
- Detekt: https://afarber.github.io/OpenMapView/detekt/
8993

9094
### Main Workflows
9195

examples/Example11MapTypes/src/main/kotlin/de/afarber/openmapview/example11maptypes/MainActivity.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import androidx.compose.runtime.remember
3030
import androidx.compose.runtime.setValue
3131
import androidx.compose.ui.Modifier
3232
import androidx.compose.ui.platform.LocalConfiguration
33-
import androidx.compose.ui.platform.LocalContext
3433
import androidx.compose.ui.text.font.FontWeight
3534
import androidx.compose.ui.unit.dp
3635
import androidx.compose.ui.unit.sp
@@ -57,7 +56,6 @@ class MainActivity : ComponentActivity() {
5756

5857
@Composable
5958
fun MapViewScreen() {
60-
val context = LocalContext.current
6159
val lifecycleOwner = androidx.lifecycle.compose.LocalLifecycleOwner.current
6260
val configuration = LocalConfiguration.current
6361
var currentMapType by remember { mutableStateOf(MapType.STANDARD) }
@@ -287,7 +285,8 @@ fun MapTypeControls(
287285

288286
// API Key Info
289287
Text(
290-
text = "API key required: Cycle Map, Transport, Transport Dark, Tracestrack Topo\n\nConfigure in AndroidManifest.xml\nSee docs/API_KEYS.md",
288+
text = "API key required: Cycle Map, Transport, Transport Dark, " +
289+
"Tracestrack Topo\n\nConfigure in AndroidManifest.xml\nSee docs/API_KEYS.md",
291290
style = MaterialTheme.typography.bodySmall,
292291
fontSize = 9.sp,
293292
lineHeight = 11.sp,

openmapview/src/main/kotlin/de/afarber/openmapview/MapController.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,6 @@ class MapController(
213213
strokeWidth = 2f
214214
}
215215

216-
private val tileTextPaint =
217-
Paint().apply {
218-
color = Color.BLACK
219-
textSize = 24f
220-
textAlign = Paint.Align.CENTER
221-
}
222-
223216
private val tilePlaceholderPaint =
224217
Paint().apply {
225218
style = Paint.Style.FILL

openmapview/src/main/kotlin/de/afarber/openmapview/OpenMapView.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class OpenMapView
305305
}
306306
}
307307

308-
val consumed = controller.onMarkerClickListener?.onMarkerClick(touchedMarker) ?: false
308+
controller.onMarkerClickListener?.onMarkerClick(touchedMarker)
309309
controller.commitPan()
310310
invalidate()
311311
return true
@@ -500,10 +500,7 @@ class OpenMapView
500500
* @see getMapType
501501
*/
502502
fun setMapType(type: Int) {
503-
// Validate map type
504-
if (type !in 0..14) {
505-
throw IllegalArgumentException("Unknown map type: $type. Must be a valid MapType constant (0-14).")
506-
}
503+
require(type in 0..14) { "Unknown map type: $type. Must be a valid MapType constant (0-14)." }
507504

508505
currentMapType = type
509506
controller.setMapType(type)

openmapview/src/test/kotlin/de/afarber/openmapview/MapControllerTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class MapControllerTest {
8686
@Test
8787
fun testZoom_BeyondMaxLimit() {
8888
controller.setZoom(18.0f)
89-
val oldZoom = controller.getZoom()
9089
controller.zoom(5.0f, 540f, 960f)
9190
assertEquals(MapController.DEFAULT_MAX_ZOOM, controller.getZoom(), DELTA)
9291
}

0 commit comments

Comments
 (0)