Skip to content

Commit fd2728d

Browse files
authored
Merge pull request #246 from synonymdev/feat/lint
Lint setup
2 parents b360586 + edc3955 commit fd2728d

File tree

7 files changed

+1255
-33
lines changed

7 files changed

+1255
-33
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/ci.yml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,33 @@ on:
66
pull_request:
77
branches: [ "master" ]
88

9-
workflow_dispatch:
9+
env:
10+
TERM: xterm-256color
11+
FORCE_COLOR: 1
1012

1113
jobs:
1214
build:
1315
runs-on: ubuntu-latest
1416

1517
steps:
16-
- name: Checkout the code
18+
- name: Checkout
1719
uses: actions/checkout@v4
1820

19-
- name: Set up JDK 17
21+
- name: Setup Java
2022
uses: actions/setup-java@v4
2123
with:
2224
java-version: '17'
2325
distribution: 'adopt'
2426

25-
- name: Cache gradle
26-
uses: actions/cache@v4
27-
with:
28-
path: |
29-
~/.gradle/caches
30-
~/.gradle/wrapper
31-
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
32-
restore-keys: |
33-
gradle-${{ runner.os }}-
27+
- name: Setup Gradle
28+
uses: gradle/actions/setup-gradle@v4
3429

3530
- name: Decode google-services.json
3631
run: echo "$GOOGLE_SERVICES_JSON_BASE64" | base64 -d > app/google-services.json
3732
env:
3833
GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}
3934

40-
- name: Make gradlew executable
41-
run: chmod +x gradlew
42-
43-
- name: Build for debug with gradle
35+
- name: Build debug app
4436
env:
4537
CHATWOOT_API: ${{ secrets.CHATWOOT_API }}
4638
run: ./gradlew assembleDevDebug
@@ -51,5 +43,6 @@ jobs:
5143
- name: Upload test report
5244
uses: actions/upload-artifact@v4
5345
with:
54-
name: unit_test_report
46+
name: unit_test_report_${{ github.run_number }}
5547
path: app/build/reports/tests/testDevDebugUnitTest/
48+
retention-days: 30

.github/workflows/lint.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
TERM: xterm-256color
15+
FORCE_COLOR: 1
16+
17+
jobs:
18+
lint:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 15
21+
22+
permissions:
23+
contents: read # for actions/checkout to fetch code
24+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
30+
- name: Setup Java
31+
uses: actions/setup-java@v4
32+
with:
33+
java-version: '17'
34+
distribution: 'adopt'
35+
36+
- name: Setup Gradle
37+
uses: gradle/actions/setup-gradle@v4
38+
39+
- name: Run Detekt Analysis
40+
run: |
41+
./gradlew detekt --no-daemon --stacktrace
42+
continue-on-error: true
43+
44+
- name: Upload SARIF
45+
if: always()
46+
uses: github/codeql-action/upload-sarif@v3
47+
with:
48+
sarif_file: app/build/reports/detekt/detekt.sarif
49+
continue-on-error: true
50+
51+
- name: Upload lint report
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: lint_report_${{ github.run_number }}
55+
path: app/build/reports/detekt/
56+
retention-days: 30

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ Bitkit Android Native app.
1414
- To communicate from emulator to host use:
1515
`10.0.2.2` instead of `localhost`
1616

17+
### Linting
18+
19+
This project uses detekt with default ktlint and compose-rules for linting Kotlin and Compose code.
20+
21+
Recommended Android Studio plugins:
22+
- EditorConfig
23+
- Detekt
24+
25+
#### Commands
26+
27+
```sh
28+
./gradlew detekt # run analysis + formatting check
29+
./gradlew detekt --auto-correct # auto-fix formatting issues
30+
```
31+
Lint reports are generated in: `app/build/reports/detekt/`.
32+
1733
## Localization
1834
See repo: https://github.com/synonymdev/bitkit-transifex-sync
1935

app/build.gradle.kts

Lines changed: 19 additions & 8 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
@@ -96,7 +97,7 @@ android {
9697
debug {
9798
signingConfig = signingConfigs.getByName("debug")
9899
ndk {
99-
//noinspection ChromeOsAbiSupport
100+
// noinspection ChromeOsAbiSupport
100101
abiFilters += listOf("armeabi-v7a", "arm64-v8a", "x86_64")
101102
}
102103
}
@@ -105,11 +106,11 @@ android {
105106
isShrinkResources = false
106107
proguardFiles(
107108
getDefaultProguardFile("proguard-android-optimize.txt"),
108-
"proguard-rules.pro"
109+
"proguard-rules.pro",
109110
)
110111
signingConfig = signingConfigs.getByName("release")
111112
ndk {
112-
//noinspection ChromeOsAbiSupport
113+
// noinspection ChromeOsAbiSupport
113114
abiFilters += listOf("armeabi-v7a", "arm64-v8a")
114115
}
115116
}
@@ -137,7 +138,7 @@ android {
137138
}
138139
testOptions {
139140
unitTests {
140-
isReturnDefaultValues = true // mockito
141+
isReturnDefaultValues = true // mockito
141142
isIncludeAndroidResources = true // robolectric
142143
}
143144
}
@@ -177,6 +178,18 @@ composeCompiler {
177178
)
178179
reportsDestination = layout.buildDirectory.dir("compose_compiler")
179180
}
181+
182+
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
183+
ignoreFailures = true
184+
reports {
185+
html.required.set(true)
186+
sarif.required.set(true)
187+
md.required.set(false)
188+
txt.required.set(false)
189+
xml.required.set(false)
190+
}
191+
}
192+
180193
dependencies {
181194
implementation(fileTree("libs") { include("*.aar") })
182195
implementation(libs.jna) { artifact { type = "aar" } }
@@ -273,10 +286,8 @@ dependencies {
273286
testImplementation(libs.test.mockito.kotlin)
274287
testImplementation(libs.test.robolectric)
275288
testImplementation(libs.test.turbine)
276-
}
277-
ksp {
278-
// cool but strict: https://developer.android.com/jetpack/androidx/releases/room#2.6.0
279-
// arg("room.generateKotlin", "true")
289+
detektPlugins(libs.detekt.formatting)
290+
detektPlugins(libs.detekt.compose.rules)
280291
}
281292
// https://developer.android.com/jetpack/androidx/releases/room#gradle-plugin
282293
room {

0 commit comments

Comments
 (0)