Skip to content

Commit 7508ca9

Browse files
committed
feat: lint setup
1 parent b360586 commit 7508ca9

File tree

6 files changed

+1279
-18
lines changed

6 files changed

+1279
-18
lines changed

.editorconfig

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
root = true
22

3-
# Apply to all files
43
[*]
4+
charset = utf-8
55
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
68
insert_final_newline = true
9+
max_line_length = 120
710
trim_trailing_whitespace = true
8-
max_line_length=120
9-
indent_style = space
10-
indent_size = 4
11+
12+
[*.{kt,kts}]
13+
ij_kotlin_allow_trailing_comma = true
14+
ij_kotlin_allow_trailing_comma_on_call_site = true
15+
ktlint_code_style = android_studio
16+
ktlint_experimental = enabled
17+
ktlint_function_naming_ignore_when_annotated_with = Composable
18+
ktlint_standard = enabled
1119

1220
[*.md]
13-
max_line_length = off
1421
indent_size = 2
22+
max_line_length = off
1523
trim_trailing_whitespace = false
1624

1725
[*.js]
1826
indent_size = 2
1927

2028
[*.json]
21-
max_line_length = off
2229
indent_size = 2
23-
24-
[*.yml]
2530
max_line_length = off
31+
32+
[*.{yml,yaml}]
2633
indent_size = 2
34+
max_line_length = off

.github/workflows/lint.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
env:
14+
# Force colored output in CI
15+
TERM: xterm-256color
16+
FORCE_COLOR: 1
17+
CI: true
18+
19+
jobs:
20+
lint:
21+
name: Lint Checks
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 15
24+
25+
permissions:
26+
contents: read # for actions/checkout to fetch code
27+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Setup Java
34+
uses: actions/setup-java@v4
35+
with:
36+
java-version: '17'
37+
distribution: 'adopt'
38+
39+
- name: Setup Gradle
40+
uses: gradle/actions/setup-gradle@v4
41+
with:
42+
cache-read-only: true
43+
44+
- name: Run Detekt Analysis
45+
run: |
46+
./gradlew detekt --no-daemon --stacktrace
47+
continue-on-error: true
48+
49+
- name: Upload SARIF
50+
if: always()
51+
uses: github/codeql-action/upload-sarif@v3
52+
with:
53+
sarif_file: app/build/reports/detekt/detekt.sarif
54+
continue-on-error: true
55+
56+
- name: Upload lint report
57+
if: always()
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: lint_report_${{ github.run_number }}
61+
path: |
62+
app/build/reports/detekt/
63+
retention-days: 30

LINTING.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 🔍 Linting Setup
2+
3+
This project uses detekt with default configurations for linting Kotlin and Jetpack Compose code.
4+
5+
## 🛠️ Tools
6+
7+
- **Detekt** - Static code analysis + formatting (includes ktlint rules via detekt-formatting & compose-rules)
8+
- **Detekt Compose** - Compose-specific rules
9+
- **GitHub Actions** - via `.github/workflows/lint.yml`
10+
- **GitHub Advanced Security** - Code scanning with SARIF reports
11+
12+
Recommended Android Studio plugins:
13+
- **Detekt** - code analysis and formatting feedback
14+
15+
## Commands
16+
17+
```sh
18+
./gradlew detekt # analysis + formatting check
19+
./gradlew detekt --auto-correct # auto-fix formatting issues
20+
```
21+
22+
## 📊 Reports
23+
24+
Reports are generated in:
25+
- **Detekt**: `app/build/reports/detekt/` (HTML, SARIF, XML, Markdown)

app/build.gradle.kts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins {
1212
alias(libs.plugins.google.services)
1313
alias(libs.plugins.protobuf)
1414
alias(libs.plugins.room)
15+
alias(libs.plugins.detekt)
1516
}
1617

1718
// https://developer.android.com/studio/publish/app-signing#secure-key
@@ -83,8 +84,11 @@ android {
8384
keyPassword = "android"
8485
}
8586
create("release") {
86-
val keystoreFile = keystoreProperties.getProperty("storeFile").takeIf { it.isNotBlank() }
87-
?.let { rootProject.file(it) }
87+
val keystoreFile =
88+
keystoreProperties
89+
.getProperty("storeFile")
90+
.takeIf { it.isNotBlank() }
91+
?.let { rootProject.file(it) }
8892
storeFile = if (keystoreFile?.exists() == true) keystoreFile else null
8993
// storeFile = rootProject.file(keystoreProperties.getProperty("storeFile"))
9094
storePassword = keystoreProperties.getProperty("storePassword")
@@ -105,7 +109,7 @@ android {
105109
isShrinkResources = false
106110
proguardFiles(
107111
getDefaultProguardFile("proguard-android-optimize.txt"),
108-
"proguard-rules.pro"
112+
"proguard-rules.pro",
109113
)
110114
signingConfig = signingConfigs.getByName("release")
111115
ndk {
@@ -137,7 +141,7 @@ android {
137141
}
138142
testOptions {
139143
unitTests {
140-
isReturnDefaultValues = true // mockito
144+
isReturnDefaultValues = true // mockito
141145
isIncludeAndroidResources = true // robolectric
142146
}
143147
}
@@ -171,12 +175,32 @@ protobuf {
171175
}
172176

173177
composeCompiler {
174-
featureFlags = setOf(
175-
ComposeFeatureFlag.StrongSkipping.disabled(),
176-
ComposeFeatureFlag.OptimizeNonSkippingGroups,
177-
)
178+
featureFlags =
179+
setOf(
180+
ComposeFeatureFlag.StrongSkipping.disabled(),
181+
ComposeFeatureFlag.OptimizeNonSkippingGroups,
182+
)
178183
reportsDestination = layout.buildDirectory.dir("compose_compiler")
179184
}
185+
186+
// Linting Configuration
187+
val isCI = System.getenv("CI").toBoolean()
188+
189+
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
190+
ignoreFailures = !isCI
191+
reports {
192+
html.required.set(!isCI)
193+
md.required.set(!isCI)
194+
sarif.required.set(true)
195+
txt.required.set(false)
196+
xml.required.set(isCI)
197+
}
198+
}
199+
200+
201+
202+
203+
180204
dependencies {
181205
implementation(fileTree("libs") { include("*.aar") })
182206
implementation(libs.jna) { artifact { type = "aar" } }
@@ -273,10 +297,14 @@ dependencies {
273297
testImplementation(libs.test.mockito.kotlin)
274298
testImplementation(libs.test.robolectric)
275299
testImplementation(libs.test.turbine)
300+
// Linting
301+
detektPlugins(libs.detekt.formatting)
302+
detektPlugins(libs.detekt.compose.rules)
276303
}
277304
ksp {
278-
// cool but strict: https://developer.android.com/jetpack/androidx/releases/room#2.6.0
279-
// arg("room.generateKotlin", "true")
305+
arg("room.schemaLocation", "$projectDir/schemas")
306+
arg("room.incremental", "true")
307+
arg("room.expandProjection", "true")
280308
}
281309
// https://developer.android.com/jetpack/androidx/releases/room#gradle-plugin
282310
room {

0 commit comments

Comments
 (0)