diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..531f4d2ea5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# Kotlin Ktlint +root = true + +[*.{kt,kts}] + +ktlint_code_style = android_studio + +ktlint_standard_no-wildcard-imports = disabled +ktlint_standard_no-empty-first-line-in-class-body = disabled +ktlint_standard_no-line-break-before-assignment = disabled +ktlint_standard_multiline-expression-wrapping = disabled +ktlint_standard_string-template-indent = disabled +ktlint_standard_trailing-comma-on-call-site = disabled +ktlint_standard_trailing-comma-on-declaration-site = disabled +ktlint_standard_no-empty-first-line-in-method-block = disabled +ktlint_standard_expression-body-wrapping = disabled +ktlint_standard_function-signature = disabled +ktlint_standard_spacing-between-declarations-with-annotations = disabled + +max_line_length = 130 diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index dedc44fcbd..fad3270ccd 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -8,6 +8,31 @@ concurrency: cancel-in-progress: true jobs: + + ktlint: + runs-on: ubuntu-latest + + steps: + - name: Checkout the code + uses: actions/checkout@v2 + with: + token: ${{ github.token }} + submodules: recursive + + - name: Set up JDK 17 + uses: actions/setup-java@v1 + with: + java-version: 17 + + - name: Install ktlint + run: curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.6.0/ktlint && chmod a+x ktlint + + - name: Build Ktlint Custom Rules Jar + run: ./gradlew :Core:KtlintCustomRules:jar + + - name: Run ktlint + run: ./ktlint --ruleset=Core/KtlintCustomRules/build/libs/KtlintCustomRules.jar + instrumentation-tests: if: github.event.pull_request.draft == false runs-on: [ self-hosted, Android ] diff --git a/Core b/Core index 943f49dec9..b6626ed90c 160000 --- a/Core +++ b/Core @@ -1 +1 @@ -Subproject commit 943f49dec915bce593ae492bc8de15fc351acb83 +Subproject commit b6626ed90ce4722e346fad0d0c5fd24cb2b833fd diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 14d1568edb..6cca25639d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -16,6 +16,7 @@ plugins { alias(core.plugins.compose.compiler) alias(core.plugins.kotlin.parcelize) alias(core.plugins.sentry.plugin) + alias(libs.plugins.ktlint) } val appCompileSdk: Int by rootProject.extra @@ -193,6 +194,7 @@ dependencies { implementation(core.infomaniak.core.ui.view) implementation(core.infomaniak.core.ui.view.edgetoedge) implementation(core.infomaniak.core.webview) + ktlintRuleset(project(":Core:KtlintCustomRules")) implementation(project(":Core:Legacy")) @@ -246,6 +248,11 @@ dependencies { implementation(libs.paho.mqtt.android) + implementation("com.pinterest.ktlint:ktlint-core:0.49.1") + implementation("com.pinterest.ktlint:ktlint-rule-engine-core:1.6.0") + implementation("com.pinterest.ktlint:ktlint-cli:1.6.0") + implementation("com.pinterest.ktlint:ktlint-cli-ruleset-core:1.6.0") + testImplementation(libs.kotlin.faker) testImplementation(libs.mock.web.server) testImplementation(core.mockk.android) diff --git a/build.gradle.kts b/build.gradle.kts index 9472e7aa08..d09fddcffa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,11 @@ +import org.jlleitschuh.gradle.ktlint.reporter.ReporterType + // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + repositories { + google() + mavenCentral() + } extra.apply { set("appCompileSdk", 36) // Ensure any extra configChanges are added into Activities' manifests. @@ -25,6 +31,21 @@ plugins { alias(core.plugins.dagger.hilt) apply false alias(core.plugins.ksp) apply false alias(core.plugins.navigation.safeargs) apply false + alias(core.plugins.ktlint) +} + +ktlint { + version.set("1.7.1") + outputToConsole.set(true) + android.set(true) + ignoreFailures.set(false) + reporters { + reporter(ReporterType.PLAIN) + } +} + +subprojects { + apply(plugin = "org.jlleitschuh.gradle.ktlint") } tasks.register("clean") { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 676eb3c88c..38c088b94d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -64,3 +64,4 @@ kotlin-android = { id = "kotlin-android" } kotlin-kapt = { id = "kotlin-kapt" } navigation-safeargs = { id = "androidx.navigation.safeargs.kotlin" } realm-android = { id = "realm-android" } +ktlint = { id = "org.jlleitschuh.gradle.ktlint" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 4e2e86dfed..a627fb18f3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -28,5 +28,6 @@ plugins { rootProject.name = "kDrive" include( ":app", + ":Core:KtlintCustomRules", ":Core:Legacy", )